Here we learn how to Get All record with ZOHO 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 below link:
https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx
To install composer on Windows system use 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' => 'your refresh code' );
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 get-record.php file and add 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 Get_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 getRecords() { $moduleGet = ZCRMRestClient::getInstance()->getModuleInstance("{module_name}"); // to get the instance of the module $moduleGetRecord = $moduleGet->getRecords( "Field_name_to_sort_by" , "sort_order", "$page = 1, $perPage = 20 ); // get all record from given module $recordsArray = $moduleGetRecord->getData(); // get all data from record } } $obj = new Get_records(); $obj->getRecords();
Where,
Module_name: The API name of the module
Possible_Module_name: leads, accounts, contacts, deals, campaigns, tasks, cases, events, calls, solutions, products, vendors, pricebooks, quotes, salesorders, purchaseorders, invoices, custom, and notes.
Field_name_to_sort_by : To get list of all records specific field wise. e.g : Last_Name, Email
Sort_order : To get List in Ascending or Descending Order
page : 1,2,3,4
per_page : How many record want to display per page