mac/Linux | curl -sS https://getcomposer.org/installer | php (terminal command) |
windows |
composer require zohocrm/php-sdk-2.1 |
require 'vendor/autoload.php'; |
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. |
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) ); |
Key | Description |
user mandatory | Represents the mail id, which is used to identify and fetch tokens from the File or DB. |
environment mandatory | Represents the data centre details in Domain::Environment pattern. Domains : USDataCenter, EUDataCenter, INDataCenter, CNDataCenter, AUDataCenter Environments : PRODUCTION(), DEVELOPER(), SANDBOX() |
token mandatory | Contains user token details. Depending on the tokens, you can choose grantToken flow, refreshToken flow or accessToken flow. |
logger optional | Contains the configuration for logging exceptions and API call information. By default, the logs will be available in the workspace as sdk_logs.log. |
store optional | Contains details for the Token Persistence object. You can choose between DB Store, File Store or Custom Store, and configure accordingly. |
SDKConfig optional | Contains additional configuration details like timeout, autorefresh fields, picklistvalidation, etc |
requestProxy optional | Contains the details of the proxy, if you are using a proxy server to authenticate and make the API calls. |
resourcePath optional | The path containing the absolute directory path to store user specific files containing the module fields information. |
$token = (new OAuthBuilder()) ->clientId("clientId") ->clientSecret("clientSecret") ->grantToken("grantToken") ->redirectURL("redirectURL") ->build(); |
$token = (new OAuthBuilder()) ->clientId("clientId") ->clientSecret("clientSecret") ->refreshToken("refreshToken") ->redirectURL("redirectURL") ->build(); |
$token = (new OAuthBuilder() ->accessToken("accessToken") ->build(); |
$logger = (new LogBuilder()) ->level(Levels::INFO) ->filePath("/Documents/php_sdk_log.log") ->build(); |
$tokenstore = (new DBBuilder()) ->host("hostName") ->databaseName("dataBaseName") ->userName("userName") ->password("password") ->portNumber("portNumber") ->tableName("tableName") ->build(); |
$tokenstore = new FileStore("absolute_file_path"); |
$tokenstore = new CustomStore(); |
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. |
timeout Default Value : 0 | The maximum time (in seconds) to allow cURL functions to execute. Use 0 to wait indefinitely. |
$requestProxy = (new ProxyBuilder()) ->host("proxyHost") ->port("proxyPort") ->user("proxyUser") ->password("password") ->build(); |
$resourcePath = "/Documents/phpsdk-application"; |
<?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() { $user = new UserSignature("patricia@zoho.com"); $environment = USDataCenter::PRODUCTION(); $token = (new OAuthBuilder()) ->clientId("1000.xxxxxxxxxxxxxxxx") ->clientSecret("554a9776d10ff016a92c1eb01xxxxxxxxxx") ->refreshToken("1000.xxxxxxxxxxxxxxxxxxxx") ->redirectURL("www.zoho.com") ->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(); } } ?> |
<?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() { $user = new UserSignature('myname@mydomain.com'); $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(); |
Writer is a powerful online word processor, designed for collaborative work.