Initialization - Java SDK
Now the app is ready to be initialized after defining OAuth configuration file and OAuth persistence handler class for your app.
Generating grant tokens
For a Single User
The developer console has an option to generate grant token for a user directly. This option may be handy when your app is going to use only one CRM user's credentials for all its operations or for your development testing.
- Login to the User's account.
- Visit https://accounts.zoho.com/developerconsole
- Click on the Options → Self Client option of the client for which you wish to authorize.
- Enter one or more (comma separated) valid Zoho CRM scopes that you wish to authorize in the Scope field and choose the time of expiry.
- Copy the grant token that is displayed on the screen.
Note
- The generated grant token is valid only for the stipulated time you chose while generating it. Hence, the access and refresh tokens should be generated within that time.
- The OAuth client registration and grant token generation must be done in the same Zoho account's (meaning - login) developer console.
For Multiple Users
For multiple users, it is the responsibility of your client app to generate the grant token from the users trying to login.
Generating access and refresh tokens
After obtaining the grant token, the following code snippet should be put in a java file and executed from your main class to get access and refresh tokens.
- ZCRMRestClient.initialize();
- ZohoOAuthClient cli = ZohoOAuthClient.getInstance();
- String grantToken = “paste_the_self_authorized_grant_token_here”;
- ZohoOAuthTokens tokens = cli.generateAccessToken(grantToken);
- String accessToken = tokens.getAccessToken();
- String refreshToken = tokens.getRefreshToken();
- System.out.println("access token = " + accessToken + " & refresh token = " + refreshToken);
Access and refresh tokens are generated and stored in the oauth_tokens.properties file if you are using ZohoOAuthFilePersistence and the same will be stored in your Mysql database table "oauthtokens" if you are using ZohoOAuthDBPersistence, on executing the above java code.
Note- The above code snippet is valid only once per grant token. Upon its successful execution, the generated access and refresh tokens would have been persisted through your persistence handler class.
- Once the OAuth tokens have been persisted, subsequent API calls would use the persisted access and refresh tokens. The SDK will take care of refreshing the access token using refresh token, as and when required.
Related Articles
Responses & Exceptions - Java SDK
APIResponse, BulkAPIResponse and FileAPIResponse are the wrapper objects for Zoho CRM APIs’ responses. All API calling methods would return one of these three objects. A method-seeking entity would return APIResponse object, whereas a method-seeking ...
Java SDK - Overview
Java SDK offers a way to create client java applications that can be integrated with Zoho CRM. This SDK makes the access and use of necessary CRM APIs with ease. In other words, it serves as a wrapper for the REST APIs, making it easier to use the ...
Configuration - Java SDK
Setting up the configuration is a system engineering process, for establishing and maintaining the consistency of the application's performance, functional and physical attributes with its requirements, design and operational information throughout ...
Persistence - Java SDK
Persistent classes in an application implement the entities of the business problem. In Java SDK, two default persistence classes with their implementations are provided. On the other hand, if a developer wants his specific implementation, he can ...
Initialization - C# SDK
Now the app is ready to be initialized after defining configuration file/dictionary for your app. Generating Grant tokens For a Single User(self-authorized) For self client apps, the self authorized grant token should be generated from the Zoho ...