hwctblanc

Zoho v3 PHP SDK POC

Sep 28th, 2022
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.65 KB | None | 0 0
  1. <?php
  2. class Record
  3. {
  4.     public static function getRecord()
  5.     {
  6.         /**
  7.          * Configuration variables
  8.          */
  9.         $autoRefreshFields = false; // all the modules' fields will be auto-refreshed in the background, every hour.
  10.         $pickListValidation = false; // validates user input for a pick list field and allows or disallows the addition of a new value to the list.
  11.         $enableSSLVerification = true; // enable or disable curl certificate verification
  12.         $connectionTimeout = 2; // The number of seconds to wait while trying to connect. Use 0 to wait indefinitely.
  13.         $timeout = 2; // The maximum number of seconds to allow cURL functions to execute.
  14.         $resourcePath = realpath(__DIR__) . '/phpsdk-application/'; // Absolute directory path to store user specific files containing module fields information.
  15.  
  16.         /* Path of the file that will store the OAuth token */
  17.         $token_file_path = realpath(__DIR__) . '/php_sdk_token.txt';
  18.  
  19.         /* OAuth token persistance */
  20.         $token_store = new FileStore($token_file_path);
  21.  
  22.         /* Logger for exception, and API feedbacks */
  23.         $log_file_path = realpath(__DIR__) . '/php_sdk_log.log';
  24.         $logger = Logger::getInstance(Levels::INFO, $log_file_path);
  25.  
  26.         /* Instance of UserSignature that identifies the current user */
  27.         $user = new UserSignature('MY ACCOUNT EMAIL');
  28.  
  29.         /* Configures API environment which decides the domain and the URL to make API calls. */
  30.         $environment = USDataCenter::PRODUCTION();
  31.  
  32.         /* Creates an instance of OAuthToken using the information got after registering your Zoho client */
  33.         $token = new OAuthToken("MY CLIENT ID", "MY CLIENT SECRET", "MY GRANT TOKEN FROM ZOHO SELF CLIENT", TokenType::REFRESH, "http://localhost/poc-zoho/");
  34.  
  35.         /* Instance of SDKConfig containing SDK configurations */
  36.         $sdkConfig = (new SDKConfigBuilder())
  37.             ->setAutoRefreshFields($autoRefreshFields)
  38.             ->setPickListValidation($pickListValidation)
  39.             ->setSSLVerification($enableSSLVerification)
  40.             ->connectionTimeout($connectionTimeout)
  41.             ->timeout($timeout)
  42.             ->build();
  43.  
  44.         /* (useless ?) Instance of RequestProxy containing the proxy properties of the user. */
  45.         // $requestProxy = new RequestProxy("proxyHost", "proxyPort", "proxyUser", "password");
  46.  
  47.         Initializer::initialize($user, $environment, $token, $token_store, $sdkConfig, $resourcePath, $logger);
  48.  
  49.         /**
  50.          * Things getting serious here
  51.          */
  52.         try {
  53.             /* Output instance */
  54.             $recordOperations = new RecordOperations();
  55.  
  56.             /* Parameters instance */
  57.             $paramInstance = new ParameterMap();
  58.             $paramInstance->add(GetRecordsParam::approved(), "both");
  59.  
  60.             /* ? Request headers */
  61.             $headerInstance = new HeaderMap();
  62.  
  63.             /* ??? Get only records modified since a given date ???? */
  64.             $ifmodifiedsince = date_create("2020-06-02T11:03:06+05:30")->setTimezone(new \DateTimeZone(date_default_timezone_get()));
  65.             $headerInstance->add(GetRecordsHeader::IfModifiedSince(), $ifmodifiedsince);
  66.  
  67.             /* Module name is available here : https://crm.zoho.com/crm/orgXXXXX/settings/modules */
  68.             $moduleAPIName = "Contacts";
  69.  
  70.             /* Query and its response */
  71.             $response = $recordOperations->getRecords($moduleAPIName, $paramInstance, $headerInstance); // Call getRecord method that takes paramInstance, moduleAPIName as parameter
  72.  
  73.         } catch (\Exception $e) {
  74.             print_r($e);
  75.         }
  76.  
  77.     }
  78. }
  79.  
Advertisement
Add Comment
Please, Sign In to add comment