Here we learn how to Search records with ZOHO REST API using SDK in PHP.
To integrate ZOHO API Using SDK follow the below steps,
1) You need to create a ZOHO Application. If you have not created then please create 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 to 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 as given below:composer require zohocrm/php-sdk
- The PHP SDK will be installed in your application and a package named vendor would be created.
3) A refresh token is required to use ZOHO REST API. Refer to the below URL to generate a refresh token.
http://staging.thecodehubs.com/generate-refresh-token-for-zoho/
4) Create config.php file and add below code,
return array ( 'userIdentifier' => 'testingtest@gmail.com', 'client_id' => 'client_id', 'client_secret' => 'client secret Key', 'redirect_uri' => 'http://api.testing.com/sdk/function.php', 'token_persistence_path' => 'zcrm_oauthtokens.txt', 'scope' => 'ZohoCRM.modules.ALL', 'refresh_code' => 'refresh code', // which is get from postman );
Here,
client_id: This is getting from your Zoho app or Zoho account.
client_secret: This is getting from your Zoho app or Zoho account.
redirect_uri: This Callback URL that you registered during the Zoho app registration.
token_persistence_path: is the path for token storage;
Scope: Choose what data can be accessed by your application.
refresh code: Code which is getting from the access token.
5) Create a search-record.php file and add the below code,
<?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 Search_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 search_record() { $moduleSearch = ZCRMRestClient::getInstance()->getModuleInstance("module_name"); $response = $moduleSearch->searchRecordsByCriteria("("( ( Last_Name:starts_with:g ) and ( Email:equals:testingtest@gmail.com ) )" )",1,200 ); //To get module records that match the criteria $records = $response->getData(); } } $obj = new Search_contacts(); $obj->search_record;
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, sales orders, purchase orders, invoices, custom, and notes.
Parameter to pass to search record in Zoho Module.
1) criteria :
=> Below criteria are used for searching records.
(({api_name}:{starts_with|equals}:{value})and/or({api_name}:{starts_with|equals}:{value}))
example:
((Last_Name:equals:Burlie,B)and(First_Name:starts_with:L));
2) email: search records by email parameter
3) phone : search record by phone parameter
4) page: To get the list of records from the respective pages.
=> Default value for page is 1.
5) per_page : To get the list of records available per page.
=> Default value for page is 200.