ZOHO

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:

https://accounts.zoho.com/developerconsole

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:
    https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx

    To install composer on Windows system use the below link:

    https://getcomposer.org/doc/00-intro.md#installation-windows
  • 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,

http://staging.thecodehubs.com/generate-access-code-using-postman-for-zoho

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

<?php

return array (
  'userIdentifier'         => 'testingtest@gmail.com',
  'client_id'     => 'put client_register_id',
  'client_secret'          => 'put client_register_secrete_key',
  'redirect_uri'    => 'http://api.testing.com/sdk/function.php',
  'token_persistence_path' => 'zcrm_oauthtokens.txt',
  'scope'            => 'ZohoCRM.modules.ALL',
  'refresh_code'    => '1000.76576b86fd625c202486cdade38692c8.6dc79d9d56a5c0eaf10cd925ea235538',
);

Here,
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

<?php
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
        );
        ZCRMRestClient::initialize($configuration);
    }
   
    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();
$obj->createRecords();

Where,
Module_name
: 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
Jigna Mavani

I am a Senior WordPress developer at vision Infotech. I'm specialized in WordPress, WooCommerce, PHP, HTML, and jQuery.

Share
Published by
Jigna Mavani

Recent Posts

Testing hk

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Operation

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

TETS NEW

test

3 years ago