Initialization - PHP SDK

Initialization - PHP SDK

The app would be ready to be initialized after defining the OAuth configuration file.

Generating self-authorized grant and refresh token

For self client apps, the self authorized grant token should be generated from the Zoho Developer Console (https://accounts.zoho.com/developerconsole)
  1. Visit https://accounts.zoho.com/developerconsole
  2. Click Options → Self Client of the client for which you wish to authorize.
  3. Enter one or more(comma separated) valid Zoho CRM scopes, that you wish to authorize, in the “Scope” field and choose a time of expiry. Provide “aaaserver.profile.READ” scope along with Zoho CRM scopes.
  4. Copy the grant token for backup.
  5. Generate refresh_token from grant token by making a POST request with the URL below 
    https://accounts.zoho.com/oauth/v2/token?code={grant_token}&redirect_uri={redirect_uri}&client_id={client_id}&client_secret={client_secret}&grant_type=authorization_code
  6. Copy the refresh token for backup.
Please note that the generated grant token is valid only for the stipulated time you choose while generating it. Hence, the access and refresh tokens should be generated within that time.

Generating access token

Access token can be generated by grant token or refresh token. Following any one of the two methods is sufficient.

Generating Access token from Grant token

The following code snippet should be executed from your main class to get access and refresh tokens. Please paste the copied grant token in the string literal mentioned below. This is a one-time process.
  1. ZCRMRestClient::initialize();
  2. $oAuthClient = ZohoOAuth::getClientInstance();
  3. $grantToken = “paste_the_self_authorized_grant_token_here”;
  4. $oAuthTokens = $oAuthClient->generateAccessToken($grantToken);
Please note that the above code snippet is valid only once per grant token. Upon successful execution of the above code snippet, the generated access and refresh tokens would have been persisted through our persistence handler class.

Generating Access token from Refresh token

The following code snippet should be executed from your main class to get access and refresh tokens. Please paste the generated refresh token in the string literal mentioned below. This is a one-time process.
  1. ZCRMRestClient::initialize();
  2. $oAuthClient = ZohoOAuth::getClientInstance();
  3. $refreshToken = "paste_the_refresh_token_here";
  4. $userIdentifier = "provide_user_identifier_like_email_here";
  5. $oAuthTokens = $oAuthClient->generateAccessTokenFromRefreshToken($refreshToken,$userIdentifier);
Upon successful execution of the above code snippet, the generated access token and given refresh token would have been persisted through our persistence handler class.
Once the OAuth tokens have been persisted, subsequent API calls would use the persisted access and refresh tokens. The PHP SDK will take care of refreshing the access token using refresh token, as and when required.

App Startup

The PHP SDK requires the following line of code invoked every time your client app is started.
  1. ZCRMRestClient::initialize();
Once the PHP SDK has been initialized by the above line, you could use any APIs of the SDK to get proper results.
    • Related Articles

    • Initialization - Python SDK

      Now the app is ready to be initialized after defining configuration file/dictionary for your app. Generating grant and refresh tokens For a Single User(self-authorized) For self client apps, the self authorized grant token should be generated from ...
    • PHP SDK - An Overview

      PHP SDK offers a way to create client PHP 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 - PHP SDK

      Before you get started with creating your php application, you need to first authenticate the app with Zoho. And to do that there are some configuration procedures that need to be in place. There are two methods in which you can authenticate your ...
    • 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 ...
    • 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 ...