Insert Record In CRM Module Using SDK PHP

The SDK is an open-source PHP library that is used for integrating your PHP application.
Here we learn how to create records with ZOHP REST API using SDK in PHP.

To integrate ZOHO API Using SDK follow below step,

1) you need to create a ZOHO Application. If you have not created then please create it by using the below link:

2) We need to include the vendor/autoload.php file. so first we need to install PHP SDK using composer.

  • Run the below command for install composer

    To install composer on mac/ Linux system use the below link:

    To install composer on Windows system use the below link:
  • Install PHP SDK
    1) Give the path of your client app(In which you want to add vendor folder).
    2) Run the command below:
    composer require zohocrm/php-sdk
  •   The PHP SDK will be installed and a package named vendor would be created in the workspace of your client app.

3) Now we need to generate a refresh code for security purposes. so  follow steps of the below URL,

4) Create config.php file and add config file below code


return array (
  'userIdentifier'         => '',
  'client_id'		   => 'put client_register_id',
  'client_secret'          => 'put client_register_secrete_key',
  'redirect_uri'	   => '',
  'token_persistence_path' => 'zcrm_oauthtokens.txt',
  'scope'	           => 'ZohoCRM.modules.ALL',
  'refresh_code'	   => '1000.76576b86fd625c202486cdade38692c8.6dc79d9d56a5c0eaf10cd925ea235538',

client_id, client_secret, and redirect_uri that you get after registering your Zoho application.
token_persistence_path is a path for token storage;
The scope is to Choose what data can be accessed by your application.
refresh code is code that is getting from the access token.

5) Create an insert-record.php file and add the below code in this file

use zcrmsdk\crm\crud\ZCRMInventoryLineItem;
use zcrmsdk\crm\crud\ZCRMRecord;
use zcrmsdk\crm\crud\ZCRMTax;
use zcrmsdk\crm\setup\restclient\ZCRMRestClient;
require 'vendor/autoload.php';

$configs = include("config.php");
$client_id     = $configs['client_id'];
$client_secret = $configs['client_secret'];
$redirect_uri  = $configs['redirect_uri'];
$identifier    = $configs['userIdentifier'];
$token_persistence_path = $configs['token_persistence_path'];

class Create_contacts{
    public function __construct()
        global $client_id, $client_secret, $redirect_uri, $identifier, $token_persistence_path; 
        $configuration = array(
              "client_id"              => $client_id,
              "client_secret"          => $client_secret,
              "redirect_uri"           => $redirect_uri,
              "currentUserEmail"       => $identifier,
              "token_persistence_path" => $token_persistence_path
    public function createRecords()
        $moduleInsert = ZCRMRestClient::getInstance()->getModuleInstance("{module_name}"); // to get the instance of the module
        $records = array();
        $record = ZCRMRecord::getInstance("{module_name}", null); // To get Record instance
        $record->setFieldValue( "Last_Name", "xyz" ); // set fields value
        $record->setFieldValue( "Account_Name", "4155085001350282060" );
        array_push($records, $record); 
        $responseIn = $moduleInsert->createRecords($records); 
        foreach ($responseIn->getEntityResponses() as $responseIns) {
            echo "HTTP Status Code: " . $responseIn->getHttpStatusCode() . "<br/>"; 
            echo "Status: " . $responseIn->getStatus() . "<br/>"; 
            echo "Message: " . $responseIn->getMessage() . "<br/>"; 
            echo "Code: " . $responseIn->getCode() . "<br/>";
            echo "Details: " . json_encode($responseIn->getDetails());

$obj = new Create_contacts();

: The API name of the module
Possible_Module_name: leads, accounts, contacts, deals, campaigns, tasks, cases, events, calls, solutions, products, vendors, price books, quotes, salesorders, purchase orders, invoices, custom, and notes.

While creating new records there are some mandatory fields that you need to mention.

Module mandatory field
Leads Last_Name – Single Line
Contacts Last_Name – Single Line
Accounts Account_Name – Single Line
Deals Deal_Name- Single Line
Stage – Picklist
Tasks Subject – Multi-Line
Calls Subject – Multi-Line
Call_Type – Picklist
Call_Start_Time – Date/Time
Call_Duration – Single Line
Events Event_Title- Single Line
Start_DateTime – Date/Time
End_DateTime – Date/Time
Products Product_Name – Single Line
Quotes Subject- Single Line
Product_Details – Product Line Item
Invoices Subject- Single Line
Product_Details – Product Line Item
Campaigns Campaign_Name – Single Line
Price Books Price_Book_Name- Single Line
Pricing_Details- JSON Array with “from_range”, “to_range”, “discount”
Cases Case_Origin – Picklist
Status- Picklist
Subject – Single Line
Solutions Solution_Title- Single Line
Purchase Orders Subject- Single Line
Vendor_Name- Lookup
Product_Details – Product Line Item
Sales Orders Subject- Single Line
Product_Details – Product Line Item

Submit a Comment

Your email address will not be published. Required fields are marked *


Select Categories