PHP SDK for Zoho CRM APIs

The PHP SDK for Zoho CRM allows developers to easily create PHP applications that can be integrated with Zoho CRM. It serves as a wrapper for the Zoho CRM REST APIs, making it easier to access and utilize the services of Zoho CRM.

Authentication to access the CRM APIs is facilitated through OAuth2.0, and the authentication process is streamlined through the use of the PHP SDK. The grant and access/refresh tokens are generated and managed within the SDK code, eliminating the need for manual handling during data synchronization between Zoho CRM and the client application.

The latest version of PHP SDK (v2.0.0) supports version 7 of Zoho CRM APIs. For more information on the released PHP SDK versions, refer here

Prerequisites

  • Ensure that the client app has PHP version 7 or above, with curl extension enabled.
  • An IDE such as Visual Studio Code or Eclipse
  • Zoho CRM account.

Note

  • If you are facing SSL related issues, make sure your SSL certificate is valid and configured properly. You can download the certificate bundle from here. To add the SSL certificate, locate the php.ini file in the PHP folder in your system,  and add these lines to your certificate:

    curl.cainfo="<filepath>/cacert.pem"
    openssl.cafile="<filepath>/cacert.pem"
  • serialize_precision, int - The number of significant digits stored while serializing floating point numbers. From PHP 7.1.0, the default value for this key is -1. This means that the floating point value will not be rounded off during serializing and un-serializing the JSON. 
    Prior to PHP 7.1.0, the default value was 17, meaning the floating point number will be rounded off to 17 digits(or to the number specified in this key). You can change this value in php.ini file according to the number of decimal places you have set for currency or decimal fields in your CRM org.

Step 1: Register your application

Before you get started with authorization and make any API calls using the Zoho CRM PHP SDKs, you need to register your application with Zoho CRM.

  1. Go to Zoho API console and click on Add Client
  2. Choose the client type as Self Client or Server-based Applications depending on your requirements.
  3. Enter the required credentials.
  4. Click CREATE
  5. Make a note of the Client ID and Client Secret generated for your application.

register a client

Step 2 : Install PHP-SDK in your project

In this step, you will create a new project in your preferred IDE, install Zoho CRM PHP SDK and include the SDK in your project. We will be using Visual Studio Code IDE in this guide.

  1. Create a project in your preferred IDE
  2. Install PHP SDK using composer. Run the following command in the workspace terminal to install version 7 SDK: 
    composer require zohocrm/php-sdk-7.0
  3. Add the following to your PHP file to include the PHP SDK in your project:
    require 'vendor/autoload.php';

create PHP project and add dependencies

Step 3 : Generation of Grant token

Generate a grant token from the Zoho API Console by following the steps described in this page.

generate grant token

Step 4: Configuration and Initialization

In the configuration step, you will set up details such as user authentication, environment, token persistence, logging, and API call timeout settings. The following table gives the details of all the keys you can configure, with detailed explanation.

KeyDescriptionSample
environment
mandatory
Represents the domain information to make API calls in Domain.Environment pattern.
Domains: USDataCenter, EUDataCenter, INDataCenter, CNDataCenter, AUDataCenter
Environments: PRODUCTION(), DEVELOPER(), SANDBOX()
Environment environment = USDataCenter.PRODUCTION;
token
mandatory
Contains user token details. Depending on the tokens, you can choose grantToken flow, refreshToken flow, or accessToken flow.Token token= new OAuthToken.Builder()
.clientID("clientId")
.clientSecret("clientSecret")
.grantToken("grantToken")
.redirectURL("redirectURL")
.build();
logger
optional
Contains the configuration for logging exceptions and API call information. By default, the logs will be available in the workspace as sdk_logs.log.Logger logger = new Logger.Builder()
.level(Levels.INFO)
.filePath("/Users/php_sdk_log.log")
.build();
store
optional
Contains details for the Token Persistence object. You can choose between DB Store, File Store, or Custom Store and configure accordingly. To know more about token persistence, refer here.TokenStore tokenstore = new DBStore.Builder()
.host("hostName")
.databaseName("databaseName")
.tableName("tableName")
.userName("userName")
.password("password")
.portNumber("portNumber")
.build();
SDKConfig
optional
Contains additional configuration details like timeout, autorefresh fields, picklistvalidation, etc.SDKConfig sdkConfig = new SDKConfig.Builder()
.autoRefreshFields(false)
.pickListValidation(true)
.build();
requestProxy
optional
Contains the details of the proxy if you are using a proxy server to authenticate and make the API calls.RequestProxy requestProxy = new RequestProxy.Builder()
.host("host")
.port(proxyPort)
.user("userName")
.password("password")
.userDomain("userDomain")
.build();
resourcePath
optional
The path containing the absolute directory path to store user-specific files containing the module fields information.String resourcePath = "/Users";

For detailed instructions on how to configure the above keys and get started, refer here. Find a sample code for initialization here.

SDK initialization

Step 5 : Making requests using PHP SDK

After you have configured and initialised, you can start making your requests using PHP SDK and utilise the functionalities of Zoho CRM. Here is a sample code to insert a new record in to the Leads module.

Making API calls

Responses and Exceptions

When working with the Zoho CRM PHP SDK, it is important to understand the responses and exceptions that can be encountered during API calls.

Note:

  • The APIResponse object holds the results of your request. You can access the actual response data using the getObject() method.
  • The APIResponse<ResponseHandler>and APIResponse<ActionHandler> are the common wrapper objects for handling responses from Zoho CRM APIs. This depends on the API. For more details, refer here.
  • APIException: This exception is thrown for errors that are related to the API itself, such as authentication errors or invalid request parameters.
  • SDKException: This exception is thrown for errors that are related to the Zoho CRM SDK, such as network errors or SDK implementation errors.

For more details on the Responses and Exceptions, refer here.

Older versions