Hello and welcome to another Kaizen week!
In this week's post, we'll show you how to get started with Zoho CRM's PHP SDK, and walk you through the configuration and initialization process.
PHP Software Development Kit
PHP SDK allows you to create client PHP applications that can be integrated with Zoho CRM effortlessly. It serves as a wrapper for the
REST APIs, thus making it easier to use the services of Zoho CRM.
Why PHP SDK?
Easy authentication: You don't have to worry about manually managing authentication because the PHP SDK takes care of generating access/refresh tokens for you.
Easy and Efficient data exchange: With the PHP SDK, you can easily exchange data between Zoho CRM and your client PHP application, where the CRM entities are modelled as classes. You can declare and define CRM API equivalents as simple functions in your PHP application.
Prerequisites
- The client app must have PHP 7 or above with a cURL extension. cURL extension is used to connect and communicate with the Zoho CRM APIs.
- The client app must have the PHP SDK installed through Composer.
How to start using the PHP SDK?
- Prerequisite : Register your application with Zoho CRM.
- Install the PHP SDK.
- Knowledge Base : Token Persistence
- Configuration
- initialization.
1. Register your application with Zoho CRM
Registering your application with Zoho CRM is a mandatory step in order to authenticate and authorize API calls using the OAuth2.0 standards.
- Go to https://api-console.zoho.com
- Click on Get Started or +ADD CLIENT.
- Choose the Client Type.
- Fill in the necessary details and click CREATE. Once you successfully register your self-client, you will receive a Client ID and Client Secret.

2. Install PHP SDK
1. Install Composer, if not already installed. Please check the corresponding link for installation instructions.
2. Install PHP-SDK using Composer
3. To use the SDK in your project, add the following line in your project PHP files. This loads and includes our PHP-SDK library in your project. If you skip this step, you will get a fatal error in response due to the missing libraries.
require 'vendor/autoload.php'; |
3. Token Persistence
Token persistence refers to storing and utilizing authentication tokens provided by Zoho, enabling the SDK to refresh the access tokens without the need for user intervention. The SDK offers three types of persistence - File, DB, and Custom - with file persistence being the default method.
The persistence is achieved by writing an implementation of the inbuilt TokenStore interface, which has the following callback methods.
Method | Description |
getToken($user, $token) | Invoked before firing a request to fetch the saved tokens. This method returns an implementation of Token interface object for the library to process it. |
saveToken($user, $token) | Invoked after fetching access and refresh tokens from Zoho. This method saves the token details. |
deleteToken($token) | This method is used to delete the given token details. |
getTokens() | This method is used to retrieve all the stored tokens. |
deleteTokens() | The method to delete all the stored tokens. |
getTokenById($id, $token) | This method is used to retrieve the user token details based on the unique ID. |
a. Token Persistence using a Database
Database persistence is a technique that involves storing and retrieving data from a database. If you prefer using database persistence, you can use MySQL.
Create a table in your database with the required columns. For example, if you want to persist your tokens in a table named token in database named zoho, use the following:
CREATE DATABASE zoho; // use this to create database named zoho // use this to create a table named token, with the necessary columns CREATE TABLE token ( id varchar(255) NOT NULL, user_mail varchar(255) NOT NULL, client_id varchar(255), client_secret varchar(255), refresh_token varchar(255), access_token varchar(255), grant_token varchar(255), expiry_time varchar(20), redirect_url varchar(255), primary key (id) ); |
In this example, your tokens will be persisted in the token table in your zoho database.
b. File Persistence
File Persistence allows storing and retrieving the authentication tokens from the given file path. The file contains
id, user_mail, client_id, client_secret, refresh_token, access_token, grant_token, expiry_time and
redirect_url. c. Custom Persistence
Custom Persistence refers to a technique where users can create their own method of storing and retrieving authentication tokens. To use this method, users need to implement the TokenStore interface and override its methods according to their own logic.
4. Configuration
Configuration is a critical step in which you set up SDK's configuration details like user authentication, token persistence, logging and API call timeout settings, and more. Listed below are the keys that you define in this step.
Key | Description |
| Represents the mail id, which is used to identify and fetch tokens from the File or DB. |
| Represents the data centre details in Domain::Environment pattern. Domains : USDataCenter, EUDataCenter, INDataCenter, CNDataCenter, AUDataCenter Environments : PRODUCTION(), DEVELOPER(), SANDBOX() |
| Contains user token details. Depending on the tokens, you can choose grantToken flow, refreshToken flow or accessToken flow. |
| Contains the configuration for logging exceptions and API call information. By default, the logs will be available in the workspace as sdk_logs.log. |
| Contains details for the Token Persistence object. You can choose between DB Store, File Store or Custom Store, and configure accordingly. |
| Contains additional configuration details like timeout, autorefresh fields, picklistvalidation, etc |
| Contains the details of the proxy, if you are using a proxy server to authenticate and make the API calls. |
| The path containing the absolute directory path to store user specific files containing the module fields information. |
Let us discuss how to configure each of them, in detail.
a. user : The user key will be used to store and identify the tokenstore details in the DB or File Storage for token persistence. Create an instance of UserSignature that identifies the current user with the following :
b. environment : The API environment which decides the domain and the URL to make API calls.
- $environment = USDataCenter::PRODUCTION();
c. token : Create an instance of OAuthToken with the information that you get after registering your Zoho client. Depending on the tokens available with you, you can choose one of the following flows.
Note : You need to generate the tokens (grant/access/refresh) beforehand.
d. logger : Create an instance of Logger Class to log exception and API information. You can set the level you want to log (FATAL, ERROR, WARNING, INFO, DEBUG, TRACE, ALL, OFF), and also configure the file path and file name for the log file.
$logger = (new LogBuilder()) ->level(Levels::INFO) ->filePath("/Documents/php_sdk_log.log") ->build(); |
e. store : Configure your token persistence using this method. If this is skipped, the SDK creates the sdk_tokens.txt in the current working directory to persist the tokens by default.
Custom Store - In this method, you can implement your own method for storing and retrieving the tokens. Please note that to do so, you must implement the TokenStore interface, and override its callback methods (getToken, saveToken, deleteToken, getTokens, deleteTokens, getTokenById).
$tokenstore = new CustomStore(); |
Note : The corresponding storage will have id, user_mail, client_id, client_secret, refresh_token, access_token, grant_token, expiry_time and redirect_url. The id is a unique system generated key.
f. SDKConfig : The additional SDK configurations are taken care of with this method.
Configuration Key | Description |
autoRefreshFields Default Value : False | A boolean configuration key to enable or disable automatic refreshing of module fields in the background. If set to true, fields are refreshed every hour, and if set to false, fields must be manually refreshed or deleted. |
pickListValidation Default Value : True | This field enables or disables pick list validation. If enabled, user input for pick list fields is validated, and if the value does not exist in the pick list, the SDK throws an error. If disabled, the input is not validated and the API call is made. |
enableSSLVerification Default Value : True | A boolean field to enable or disable curl certificate verification. If set to true, the SDK verifies the authenticity of certificate. If set to false, the SDK skips the verification. |
connectionTimeout Default Value : 0 | The maximum time (in seconds) to wait while trying to connect. Use 0 to wait indefinitely. |
| The maximum time (in seconds) to allow cURL functions to execute. Use 0 to wait indefinitely. |
- $autoRefreshFields = false;
- $pickListValidation = false;
- $enableSSLVerification = true;
- $connectionTimeout = 2;
- $timeout = 2;
- $sdkConfig = (new SDKConfigBuilder())
- ->autoRefreshFields($autoRefreshFields)
- ->pickListValidation($pickListValidation)
- ->sslVerification($enableSSLVerification)
- ->connectionTimeout($connectionTimeout)
- ->timeout($timeout)
- ->build();
g. requestProxy : Create an instance of RequestProxy containing the proxy properties of the user. Configure this only if you're using a proxy server to make the API calls.
$requestProxy = (new ProxyBuilder()) ->host("proxyHost") ->port("proxyPort") ->user("proxyUser") ->password("password") ->build(); |
h. resourcePath : Configure path containing the absolute directory path to store user specific files containing module fields information.
$resourcePath = "/Documents/phpsdk-application"; |
5. Initilization
Once you have completed the configuration process, you can move on to initializing the SDK and begin making API requests.
Here is a sample code to initialize the SDK, using refresh token flow and DB Persistence.
<?php use com\zoho\api\authenticator\OAuthBuilder; use com\zoho\api\authenticator\store\DBBuilder; use com\zoho\api\authenticator\store\FileStore; use com\zoho\crm\api\InitializeBuilder; use com\zoho\crm\api\UserSignature; use com\zoho\crm\api\dc\USDataCenter; use com\zoho\api\logger\LogBuilder; use com\zoho\api\logger\Levels; use com\zoho\crm\api\SDKConfigBuilder; use com\zoho\crm\api\ProxyBuilder; use com\zoho\api\authenticator\store\DBBuilder;
require_once "vendor/autoload.php";
class Initialize { public static function initialize() { $environment = USDataCenter::PRODUCTION(); $token = (new OAuthBuilder()) ->clientId("1000.xxxxxxxxxxxxxxxx") ->clientSecret("554a9776d10ff016a92c1eb01xxxxxxxxxx") ->refreshToken("1000.xxxxxxxxxxxxxxxxxxxx") ->build(); $logger = (new LogBuilder()) ->level(Levels::INFO) ->filePath("/Documents/php_sdk_log.log") ->build(); $tokenstore = (new DBBuilder()) ->host("insert_your_hostname_here") ->databaseName("insert_your_database_name_here") ->userName("insert_your_db_username_here") ->password("insert_your_db_password_here") ->portNumber("insert_your_portnumber_here") ->tableName("insert_your_table_name_here") ->build(); $autoRefreshFields = false; $pickListValidation = false; $connectionTimeout = 2; $timeout = 2; $sdkConfig = (new SDKConfigBuilder()) ->autoRefreshFields($autoRefreshFields) ->pickListValidation($pickListValidation) ->sslVerification($enableSSLVerification) ->connectionTimeout($connectionTimeout) ->timeout($timeout) ->build(); $resourcePath = "/Documents/phpsdk-application"; $requestProxy = (new ProxyBuilder()) ->host("proxyHost") ->port("proxyPort") ->user("proxyUser") ->password("password") ->build(); (new InitializeBuilder()) ->user($user) ->environment($environment) ->token($token) ->store($tokenstore) ->SDKConfig($configInstance) ->resourcePath($resourcePath) ->logger($logger) ->requestProxy($requestProxy) ->initialize(); } } ?> |
You are now all set to explore the functionalities of SDK. Here is a sample code to get the records from Leads module, with the ifmodifiedsince header.
<?php use com\zoho\api\authenticator\OAuthBuilder; use com\zoho\crm\api\dc\USDataCenter; use com\zoho\crm\api\InitializeBuilder; use com\zoho\crm\api\UserSignature; use com\zoho\crm\api\record\RecordOperations; use com\zoho\crm\api\record\GetRecordsHeader; use com\zoho\crm\api\HeaderMap; use com\zoho\crm\api\ParameterMap; require_once "vendor/autoload.php";
class Record { public static function initialize() { $environment = USDataCenter::PRODUCTION(); $token = (new OAuthBuilder()) ->clientId("1000.xxxxxxx") ->clientSecret("4b5baxxxxxxxxxxxxf") ->grantToken("1000.xxxxx") ->build(); (new InitializeBuilder()) ->user($user) ->environment($environment) ->token($token) ->initialize(); }
public static function getRecords() { $recordOperations = new RecordOperations(); $paramInstance = new ParameterMap(); $headerInstance = new HeaderMap(); $ifmodifiedsince = date_create("2022-06-01T12:00:00+05:30")->setTimezone(new \DateTimeZone(date_default_timezone_get())); $headerInstance->add(GetRecordsHeader::IfModifiedSince(), $ifmodifiedsince); $response = $recordOperations->getRecords("Leads", $paramInstance, $headerInstance); echo($response->getStatusCode() . "\n"); print_r($response); } } Record::initialize(); Record::getRecords(); |
Next week, we will dive deeper and provide more sample codes to help you further. Stay tuned!
If you have any queries, let us know the comments below, or drop an email to
support@zohocrm.com. We would love to hear from you.

Recent Topics
Celebrating Connections with Zoho Desk
September 27 is a special day marking two great occasions: World Tourism Day and Google’s birthday. What do these two events have in common (besides the date)? It's something that Zoho Desk celebrates, too: making connections. The connect through tourism
What is Resolution Time in Business Hours
HI, What is the formula used to find the total time spent by an agent on a particular ticket? How is Resolution Time in Business Hours calculated in Zohodesk? As we need to find out the time spent on the ticket's solution by an agent we seek your assistance
How use
Good morning sir I tried Zoho Mail
Adding Overlays to Live Stream
Hello folks, The company I work for will host an online event through Zoho Webinar. I want to add an overlay (an image) at the bottom of the screen with all the sponsors' logos. Is it possible to add an image as an overlay during the live stream? If so,
Email Sending Failed - SMTP Error: data not accepted. - WHMCS Not sending emails due to this error
I have been trying to figure out a fix for about a week now and I haven't found one on my own so I am going to ask for help on here. After checking all the settings and even resetting my password for the email used for WHMCS it still says: Email Sending Failed - SMTP Error: data not accepted. I have no clue how to fix it at this point. Any insight would be lovely.
Does Zoho Learn integrate with Zoho Connect,People,Workdrive,Project,Desk?
Can we propose Zoho LEarn as a centralised Knowledge Portal tool that can get synched with the other Zoho products and serve as a central Knowledge repository?
Zoho Flow - Update record in Trackvia
Hello, I have a Flow that executes correctly but I only want it to execute once when a particular field on a record is updated in TrackVia. I have the trigger filters setup correctly and I want to add an "update record" action at the end of the flow to
Add Comprehensive Accessibility Features to Zoho Desk Help Center for End Users
Hello Zoho Desk Team, We hope you're doing well. We’d like to submit a feature request to enhance the client-facing Help Center in Zoho Desk with comprehensive accessibility features, similar to those already available on the agent interface. 🎯 Current
Rename Record Summary PDF in SendMail task
So I've been tasked with renaming a record summary PDF to be sent as part of a sendmail task. Normally I would offer the manual solution, a user exports the PDF and uploads it to a file upload field, however this is not acceptable to the client in this
in zoho creator Sales Returns form has sub form Line Items return quantity when i upate the or enter any values in the sub form that want to reflect in the Sales Order form item deail sub form field Q
in zoho creator Sales Returns form has sub form Line Items return quantity when i upate the or enter any values in the sub form that want to reflect in the Sales Order form item deail sub form field Quantity Returned\ pls check the recording fetch_salesorder
Estimates with options and sub-totals
Hi It seems it would be great to be able to show multiple options in an estimate. For instance I have a core product to which I can add options, and maybe sub-options... It would be great to have subtotals and isolate the core from the not compulsory items. Thanks
Optional Items Estimate
How do you handle optional items within an estimate? In our case we have only options to choose with. (Like your software pricing, ...standard, professional, enterprise) How can we disable the total price? Working with Qty = 0 is unprofessional....
Important Update : Zendesk Sell announced End of Life
Hello Zendesk users, Zendesk has officially announced that Zendesk Sell will reach its End of Life (EOL) on August 31, 2027 (Learn more). In line with this deprecation, Zoho Analytics will retire its native Zendesk Sell connector effective October 1,
Zoho Sheets
Hi, I am trying to transition into Zoho sheets, I have attached the issues encountered. Server issues, file trying to upload for more than 30 mins, even once uploaded my data aren't loaded. Simple calculations are not working I have attached the sample.
Zoho CRM + Zoho FSM : alignez vos équipes commerciales et techniques
La vente est finalisée, mais le parcours client ne fait que commencer ! Dans les entreprises orientées service, conclure une vente représente seulement la première étape. Ce qui suit — installation, réparation ou maintenance régulière — influence grandement
Top Bar Shifting issue still not fixed yet
I mentioned in a previous ticket that on Android, the top bar shifts up when you view collections or when you're in the settings. That issue still hasn't been fixed yet. I don't wanna have to reinstall the app as I've noticed for some reason, reinstalling
Power of Automation:: Automate the process of updating project status based on a specific task status.
Hello Everyone, Today, I am pleased to showcase the capabilities of a custom function that is available in our Gallery. To explore the custom functions within the Gallery, please follow the steps below. Click Setup in the top right corner > Developer
ZOHO SHEETS
Where can I access desktop version of zoho sheets? It is important to do basic work If it is available, please guide me to the same
Attention API Users: Upcoming Support for Renaming System Fields
Hello all! We are excited to announce an upcoming enhancement in Zoho CRM: support for renaming system-defined fields! Current Behavior Currently, system-defined fields returned by the GET - Fields Metadata API have display_label and field_label properties
Billing Management: #3 Billing Unbilled Charges Periodically
We had a smooth sail into Prorated Billing, a practice that ensures fairness when customers join, upgrade, or downgrade a service at any point during the billing cycle. But what happens when a customer requests additional limits or features during the
No bank feeds from First National Bank South Africa since 12 September
I do not know how Zoho Books expects its customers to run a business like this. I have contacted Zoho books numerous times about this and the say it is solved - on email NO ONE ANSWERS THE SOUTH AFRICAN HELP LINE Come on Zoho Books, you cannot expect
Citation Problem
I had an previous ticket (#116148702) on this subject. The basic problem is this; the "Fetch Details" feature works fine on the first attempt but fails on every subsequent attempt, Back in July after having submitted information electronically and was
Open Sans Font in Zoho Books is not Open Sans.
Font choice in customising PDF Templates is very limited, we cannot upload custom fonts, and to make things worse, the font names are not accurate. I selected Open Sans, and thought the system was bugging, but no, Open Sans is not Open Sans. The real
Failing to generate Access and Refresh Token
Hello. I have two problems: First one when generating Access and Refresh Token I get this response: As per the guide here : https://www.zoho.com/books/api/v3/#oauth (using server based application) I'm following all the steps. I have managed to get
Zeptomail 136.143.188.150 blocked by SpamCop
Hi - it looks like this IP is being blocked, resulting in hard bounces unfortunately :( "Reason: uncategorized-bounceMessage: 5.7.1 Service unavailable; Client host [136.143.188.150] blocked using bl.spamcop.net; Blocked - see https://www.spamcop.net/bl.shtml?136.143.188.150
Apply transaction rules to multiple banks
Is there any way to make transaction rules for one bank apply to other banks? It seems cumbersome to have to re-enter the same date for every account.
How to bulk update records with Data Enrichment by Zia
Hi, I want to bulk update my records with Data Enrichment by Zia. How can I do this?
Need Guidance on SPF Flattening for Zoho Mail Configuration
Hi everyone, I'm hoping to get some advice on optimizing my SPF record for a Zoho Mail setup. I use Zoho Mail along with several other Zoho services, and as a result, my current SPF record has grown to include multiple include mechanisms. My Cloudflare
How do I split a large CSV file into smaller parts for import into Zoho?
Hi everyone, I’m trying to upload a CSV file into Zoho, but the file is very large (millions of rows), and Zoho keeps giving me errors or takes forever to process. I think the file size is too big for a single import. Manually breaking the CSV into smaller
Client Script Payload Size Bug
var createParams = { "data": [{ "Name": "PS for PR 4050082000024714556", "Price_Request": { "id": "4050082000024714556" }, "Account": { "id": "4050082000021345001" }, "Deal": { "id": "4050082000023972001" }, "Owner": { "id": "4050082000007223004" }, "Approval_Status":
Sync Issue Between Zoho Notebook Web App on Firefox (PC) and Android App
Hi Zoho Notebook Community, I'm facing a sync problem with Zoho Notebook. When I use the web version on Mozilla Firefox browser on my PC, I create and save new notes, and I've synced them successfully. However, these new notes aren't showing up in my
Messages not displayed from personal LinkedIn profile
Hello. I connected both our company profile and my personal profile to Zoho social. I do see all messages from our company page but none from my private page. not even the profile is being added on top to to switch between company or private profile,
lead convert between modules
Hello, The workflow we set up to automatically transfer leads registered via Zapier into the Patients module to the Leads module started to malfunction unexpectedly on September 25, 2025, at 11:00 AM. Under normal circumstances, all fields filled in the
Flow Task Limits - How to Monitor, Understand Consumption?
So, I got an email last night saying that I've exhausted 70% of my tasks for this month, and encouraging me to buy more tasks. I started to dig into this, and I cannot for the life of me figure out where to find any useful information for understanding,
Cross References Do Not Update Correctly
I am using cross references to reference Figures and current am just using the label and number, i.e. Figure #. As seen here: When I need to update the field, I use the update field button. But it will change the cross reference to no longer only including
Manage control over Microsoft Office 365 integrations with profile-based sync permissions
Greetings all, Previously, all users in Zoho CRM had access to enable Microsoft integrations (Calendar, Contacts, and Tasks) in their accounts, regardless of their profile type. Users with administrator profiles can now manage profile-based permissions
How to Track and Manage Schedule Changes in Zoho Projects
Keeping projects on track requires meticulous planning. However, unforeseen circumstances can cause changes to schedules, leading to delays. It becomes important to capture the reason for such changes to avoid them in the future. Zoho Projects acknowledges
Is there a notification API when a new note is addeding
Trying to push to Cliq, or email notification when there's a new note added in module. How to implement this?
Zoho Sheet - Desktop App or Offline
Since Zoho Docs is now available as a desktop app and offline, when is a realistic ETA for Sheet to have the same functionality?I am surprised this was not laucned at the same time as Docs.
Collaborate Feature doesn't work
Hello Team. It seems that the collaborate section is broken? I can post something but it all appears in "Discussions". In there is no way how I would mark something as Draft, Approval, post or any of the other filter categories? Also if I draft a post
Next Page