Configuration
Before you get started with creating your PHP application, you need to register your client and authenticate the app with Zoho.
Follow the below steps to configure the SDK.
Create an instance of the Logger Class to log exception and API information.
/* * Create an instance of Logger Class that takes two parameters * 1 -> Level of the log messages to be logged. Can be configured by typing Levels "::" and choose any level from the list displayed. * 2 -> Absolute file path, where messages need to be logged. */ $logger = Logger::getInstance(Levels::info, "/Users/user_name/Documents/php_sdk_log.log");
Create an instance of UserSignature that identifies the current user.
//Create an UserSignature instance that takes user Email as parameter $user = new UserSignature("abc@zoho.com");
Configure the API environment which decides the domain and the URL to make API calls.
/* * Configure the environment * which is of the pattern Domain.Environment * Available Domains: USDataCenter, EUDataCenter, INDataCenter, CNDataCenter, AUDataCenter * Available Environments: PRODUCTION(), DEVELOPER(), SANDBOX() */ $environment = USDataCenter::PRODUCTION();
Create an instance of OAuthToken with the information that you get after registering your Zoho client.
/* * Create a Token instance * 1 -> OAuth client id. * 2 -> OAuth client secret. * 3 -> OAuth redirect URL. * 4 -> REFRESH/GRANT token. * 5 -> Token type(REFRESH/GRANT). */ $token = new OAuthToken("clientId", "clientSecret", "REFRESH/GRANT token", TokenType::REFRESH/GRANT, "redirectURL");
Create an instance of TokenStore to persist tokens used for authenticating all the requests.
/* * Create an instance of DBStore. * 1 -> DataBase host name. Default value "localhost" * 2 -> DataBase name. Default value "zohooauth" * 3 -> DataBase user name. Default value "root" * 4 -> DataBase password. Default value "" * 5 -> DataBase port number. Default value "3306" */ $tokenstore = new DBStore("hostName", "DataBaseName", "userName", "password", "portNumber"); //$tokenstore = new FileStore("absolute_file_path"); //$tokenStore = new CustomStore();
Create an instance of SDKConfig containing the SDK configuration.
/* * autoRefreshFields (default value is false) * true - all the modules' fields will be auto-refreshed in the background, every hour. * false - the fields will not be auto-refreshed in the background. The user can manually delete the file(s) or refresh the fields using methods from ModuleFieldsHandler(com\zoho\crm\api\util\ModuleFieldsHandler) * * pickListValidation (default value is true) * A boolean field that validates user input for a pick list field and allows or disallows the addition of a new value to the list. * true - the SDK validates the input. If the value does not exist in the pick list, the SDK throws an error. * false - the SDK does not validate the input and makes the API request with the user’s input to the pick list * * enableSSLVerification (default value is true) * A boolean field to enable or disable curl certificate verification * true - the SDK verifies the authenticity of certificate * false - the SDK skips the verification */ $autoRefreshFields = false; $pickListValidation = false; $enableSSLVerification = true; $connectionTimeout = 2; //The number of seconds to wait while trying to connect. Use 0 to wait indefinitely. $timeout = 2; //The maximum number of seconds to allow cURL functions to execute. $sdkConfig = (new SDKConfigBuilder())->setAutoRefreshFields($autoRefreshFields)->setPickListValidation($pickListValidation)->setSSLVerification($enableSSLVerification)->connectionTimeout($connectionTimeout)->timeout($timeout)->build();
Set the absolute directory path to store user specific files containing module fields information in resourcePath
$resourcePath = "/Users/user_name/Documents/phpsdk-application";
Create an instance of RequestProxy containing the proxy properties of the user.
$requestProxy = new RequestProxy("proxyHost", "proxyPort", "proxyUser", "password");
Initialize the SDK and make API calls.