Getting Error from Zoho CRM API C#
Hi, I am trying to connect my application to Zoho API using C# SDK but I am getting the following error. It seems like the connection is fine but it is unable to get the data. I have enabled the
module.all scope and
read scope, for access token, as well.
ZCRM_INTERNAL_ERROR
Object reference not set to an instance of an object.
Here is my code:
-
public static Dictionary<string, string> config = new Dictionary<string, string>()
{
{"client_id","1000.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"},
{"client_secret","xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"},
{"access_type","offline"},
{"persistence_handler_class","ZCRMSDK.OAuth.ClientApp.ZohoOAuthFilePersistence, ZCRMSDK"},
{"oauth_tokens_file_path","C:/_zohoapitokens/tokens.txt"},
//{"mysql_username",""},
//{"mysql_password",""},
//{"mysql_database",""},
//{"mysql_server",""},
//{"mysql_port",""},
{"apiVersion","v2"},
//{"logFilePath","" },
//{"timeout",""},
//{"minLogLevel",""},
//{"domainSuffix",""},
};
private bool InitializeZohoAPI()
{
bool success = false;
try
{
ZCRMRestClient.Initialize(config);
ZohoOAuthClient client = ZohoOAuthClient.GetInstance();
string refreshToken = "1000.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
ZohoOAuthTokens tokens = client.GenerateAccessTokenFromRefreshToken(refreshToken, userMailId);
string accessToken = tokens.AccessToken;
if ( ! string.IsNullOrEmpty(refreshToken) && tokens.ExpiryTime > 0)
{
success = true;
}
}
catch (Exception ex)
{
ex.Message.ToString();
success = false;
}
return success;
}
public void test()
{
try
{
if(InitializeZohoAPI())
{
ZCRMRestClient restClient = ZCRMRestClient.GetInstance();
APIResponse response = restClient.GetOrganizationDetails();
ZCRMOrganization organization = (ZCRMOrganization)response.Data;
}
}
catch (ZCRMException ex)
{
throw;
}
}