Initialization - PHP SDK

Initialization - PHP SDK

The app would be ready to be initialized after defining the configuration array. The user can now proceed to generate the required tokens to run the app.

The generation of the grant token can be done using two methods.
  1. Self-Client
We will be using the self-client option here to demonstrate the process.

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  → 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.



    1. Provide “aaaserver.profile.READ” scope along with Zoho CRM scopes.
    2. All the scopes that are required must be given in the syntax: ZohoCRM.{scope_name}.{operation_type}.

  4. Copy the  grant token  for backup.

  5. Generate  refresh_token  from grant token by making a POST request with the URL below

  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. $configuration =array("client_id"=>{client_id},"client_secret"=>{client_secret},"redirect_uri"=>{redirect_url},"currentUserEmail"=>{user_email_id});
  2. ZCRMRestClient::initialize($configuration);
  3. $oAuthClient = ZohoOAuth::getClientInstance();
  4. $grantToken = "paste_the_self_authorized_grant_token_here";
  5. $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. $configuration =array("client_id"=>{client_id},"client_secret"=>{client_secret},"redirect_uri"=>{redirect_url},"currentUserEmail"=>{user_email_id});
  2. ZCRMRestClient::initialize($configuration);
  3. $oAuthClient = ZohoOAuth::getClientInstance();
  4. $refreshToken = "paste_the_refresh_token_here";
  5. $userIdentifier = "provide_user_identifier_like_email_here";
  6. $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. $configuration =array("client_id"=>{client_id},"client_secret"=>{client_secret},"redirect_uri"=>{redirect_url},"currentUserEmail"=>{user_email_id});
  2. ZCRMRestClient::initialize($configuration);
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

    • Release Notes - PHP SDK

      ZOHO CRM/PHP SDK 2.0.1 Install command composer require zohocrm/php-sdk:2.0.1 Notes Enhancement Tag names can contain spaces in between them, while associating with records. Tag names can be retrieved as "ZCRMTag" objects in records function. ZOHO ...
    • Installation - PHP SDK

      Install Composer(if not installed) Run this command to install the composer curl -sS  https://getcomposer.org/installer  | php To install composer on mac/ linux machine: https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx To install ...
    • 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

      To access the CRM services through SDK, the client application must be first authenticated. This can be done by passing a key-value configuration pair to the initialization process. The $configuration array must be created. It will contain the ...
    • Responses & Exceptions - PHP SDK

      Response Objects All the API calling methods will return one of the following responses, which serve as a wrapper objects for the Zoho CRM APIs' responses. Responses Description APIResponse Returns a single API response object. BulkAPIResponse ...