How do I authenticate my server based app with Zoho SDK?

Viewed 230

I hope this makes sense. I am using the Zoho C# SDK examples to write records to the CRM Leads. While calling recordOperations.CreateRecords(); it fails after trying to GetToken from the Token Store. Here is the token I am saving

Token token = new OAuthToken(
      "xxxx.clientid.goes.here.xxxxx",
      "xxxx.clientsecret.goes.here.xxxx",
      "REFRESH/GRANT token",
      TokenType.GRANT,
      string.Empty);
 TokenStore tokenStore = new CustomTokenStore();
 tokenStore.SaveToken(user, token); 

And I am sending this token into the SDKInitilizer.Initialize. No errors at this point. Next I try and create a lead. When it gets inside of recordOperations.CreateRecords(); it tries GetToken and I've hard coded it to return exactly what was in the token object above. CreateRecords throws an error for "invalid_code". Here is what is in the log file

21-09-07 16:49:34 [INFO]: Initialization successful for Email Id : myemail@email.com in Environment : https://www.zohoapis.com.
21-09-07 16:49:47 [INFO]: Access Token has expired. Hence refreshing.
21-09-07 16:49:50 [ERROR]: Exception in authenticating current request : {"Code":"INVALID CLIENT ERROR","Message":"invalid_code","Cause":null,"Details":null,"StackTrace":"   at Com.Zoho.API.Authenticator.OAuthToken.ParseResponse(String response)\r\n   at Com.Zoho.API.Authenticator.OAuthToken.RefreshAccessToken(UserSignature user, TokenStore store)\r\n   at Com.Zoho.API.Authenticator.OAuthToken.Authenticate(APIHTTPConnector urlConnection)\r\n   at Com.Zoho.Crm.API.Util.CommonAPIHandler.APICall[T](Type className, String encodeType)","Data":{},"InnerException":null,"HelpLink":null,"Source":"ZCRMSDK","HResult":-2146233088}

It appears to be failing when it tries to refresh the token so I assume I am not sending in the right info in the token object?

*** Edit for @sucasa *** This is what I am sending into the Initialize method. enter image description here

What I have figured out since my first post is, I'm not getting the initial token from Initialize and its not calling the custom TokenStore.SaveToken() I created and it should, right? If I save it, all I have is what is above, not an actual token. So I think when I go to create the lead, I don't actually have the initial token to refresh. I hope that's clearer.

1 Answers

Access Tokens expire and must be refreshed using a refresh token. The error message indicates this. Can you log the value of token and report back here?

Related