Download the PHP package zohocrm/php-sdk without Composer
On this page you can find all versions of the php package zohocrm/php-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zohocrm/php-sdk
More information about zohocrm/php-sdk
Files in zohocrm/php-sdk
Package php-sdk
Short Description Zoho CRM API SDK for PHP
License
Homepage https://github.com/zoho/zohocrm-php-sdk
Informations about the package php-sdk
Archival Notice:
This SDK is archived. You can continue to use it, but no new features or support requests will be accepted. For the new version, refer to https://www.zoho.com/crm/developer/docs/sdk/server-side/php-sdk.html
ZOHO CRM PHP SDK
Table Of Contents
- Overview
- Registering a Zoho Client
- Environmental Setup
- Including the SDK in your project
- Persistence
- DataBase Persistence
- File Persistence
- Custom Persistence
- Configuration
- Initialization
- Class Hierarchy
- Responses And Exceptions
- Multi-User support in the PHP SDK
- Sample Code
Overview
Zoho CRM PHP SDK offers a way to create client PHP applications that can be integrated with Zoho CRM.
Registering a Zoho Client
Since Zoho CRM APIs are authenticated with OAuth2 standards, you should register your client app with Zoho. To register your app:
-
Visit this page https://api-console.zoho.com/
-
Click on
ADD CLIENT
. -
Choose a
Client Type
. -
Enter Client Name, Client Domain or Homepage URL and Authorized Redirect URIs then click
CREATE
. -
Your Client app would have been created and displayed by now.
-
Select the created OAuth client.
- Generate grant token by providing the necessary scopes, time duration (the duration for which the generated token is valid) and Scope Description.
Environmental Setup
PHP SDK is installable through Composer. Composer is a tool for dependency management in PHP. SDK expects the following from the client app.
-
Client app must have PHP(version 7 and above) with curl extension enabled.
- PHP SDK must be installed into client app though Composer.
Including the SDK in your project
You can include the SDK to your project using:
-
Install Composer (if not installed).
-
Run this command to install the composer.
-
To install composer on mac/linux machine:
- To install composer on windows machine:
-
-
Install PHP SDK.
-
Navigate to the workspace of your client app.
-
Run the command below:
- The PHP SDK will be installed and a package named vendor will be created in the workspace of your client app.
-
-
Using the SDK.
- Add the below line in PHP files of your client app, where you would like to make use of PHP SDK.
Through this line, you can access all the functionalities of the PHP SDK. The namespaces of the class to be used must be included within the "use" statement.
Token Persistence
Token persistence refers to storing and utilizing the authentication tokens that are provided by Zoho. There are three ways provided by the SDK in which persistence can be utilized. They are DataBase Persistence, File Persistence and Custom Persistence.
Table of Contents
-
DataBase Persistence
-
File Persistence
- Custom Persistence
Implementing OAuth Persistence
Once the application is authorized, OAuth access and refresh tokens can be used for subsequent user data requests to Zoho CRM. Hence, they need to be persisted by the client app.
The persistence is achieved by writing an implementation of the inbuilt TokenStore interface, which has the following callback methods.
-
getToken($user, $token) - invoked before firing a request to fetch the saved tokens. This method should return an implementation of Token interface object for the library to process it.
-
saveToken($user, $token) - invoked after fetching access and refresh tokens from Zoho.
-
deleteToken($token) - invoked before saving the latest tokens.
-
getTokens() - The method to retrieve all the stored tokens.
- deleteTokens() - The method to delete all the stored tokens.
Note:
-
$user instanceof UserSignature.
- $token instanceof Token interface.
DataBase Persistence
In case the user prefers to use the default DataBase persistence, MySQL can be used.
-
The database name should be zohooauth.
-
There must be a table name oauthtoken with columns.
-
user_mail varchar(255)
-
client_id varchar(255)
-
refresh_token varchar(255)
-
access_token varchar(255)
-
grant_token varchar(255)
- expiry_time varchar(20)
-
MySQL Query
Create DBStore object
File Persistence
In case of default File Persistence, the user can persist tokens in the local drive, by providing the the absolute file path to the FileStore object.
-
The File contains.
-
user_mail
-
client_id
-
refresh_token
-
access_token
-
grant_token
- expiry_time
-
Create FileStore object
Custom Persistence
To use Custom Persistence, the user must implement TokenStore interface (com\zoho\api\authenticator\store\TokenStore) and override the methods.
Configuration
Before you get started with creating your PHP application, you need to register your client and authenticate the app with Zoho.
-
Create an instance of Logger Class to log exception and API information.
-
Create an instance of UserSignature that identifies the current user.
-
Configure API environment which decides the domain and the URL to make API calls.
-
Create an instance of OAuthToken with the information that you get after registering your Zoho client.
-
Create an instance of TokenStore to persist tokens, used for authenticating all the requests.
-
Create an instance of SDKConfig containing SDK configurations.
-
Create an instance of RequestProxy containing the proxy properties of the user.
- The path containing the absolute directory path to store user specific files containing module fields information.
Initializing the Application
Initialize the SDK using the following code.
- You can now access the functionalities of the SDK. Refer to the sample codes to make various API calls through the SDK.
Class Hierarchy
Responses and Exceptions
All SDK method calls return an instance of the APIResponse class.
Use the getObject() method in the returned APIResponse object to obtain the response handler interface depending on the type of request (GET, POST,PUT,DELETE).
APIResponse<ResponseHandler> and APIResponse<ActionHandler> are the common wrapper objects for Zoho CRM APIs’ responses.
Whenever the API returns an error response, the response will be an instance of APIException class.
All other exceptions such as SDK anomalies and other unexpected behaviours are thrown under the SDKException class.
-
For operations involving records in Tags
- APIResponse<RecordActionHandler>
-
For getting Record Count for a specific Tag operation
- APIResponse<CountHandler>
-
For operations involving BaseCurrency
- APIResponse<BaseCurrencyActionHandler>
-
For Lead convert operation
- APIResponse<ConvertActionHandler>
-
For retrieving Deleted records operation
- APIResponse<DeletedRecordsHandler>
-
For Record image download operation
- APIResponse<DownloadHandler>
-
For MassUpdate record operations
-
APIResponse<MassUpdateActionHandler>
- APIResponse<MassUpdateResponseHandler>
-
GET Requests
-
The getObject() of the returned APIResponse instance returns the response handler interface.
-
The ResponseHandler interface interface encompasses the following
- ResponseWrapper class (for application/json responses)
- FileBodyWrapper class (for File download responses)
- APIException class
-
The CountHandler interface encompasses the following
- CountWrapper class (for application/json responses)
- APIException class
-
The DeletedRecordsHandler interface encompasses the following
- DeletedRecordsWrapper class (for application/json responses)
- APIException class
-
The DownloadHandler interface encompasses the following
- FileBodyWrapper class (for File download responses)
- APIException class
- The MassUpdateResponseHandler interface encompasses the following
- MassUpdateResponseWrapper class (for application/json responses)
- APIException class
POST, PUT, DELETE Requests
-
The getObject() of the returned APIResponse instance returns the action handler interface.
-
The ActionHandler interface encompasses the following
- ActionWrapper class (for application/json responses)
- APIException class
-
The ActionWrapper class contains Property/Properties that may contain one/list of ActionResponse interfaces.
-
The ActionResponse interface encompasses following
- SuccessResponse class (for application/json responses)
- APIException class
-
The ActionHandler interface encompasses following
- ActionWrapper class (for application/json responses)
- APIException class
-
The RecordActionHandler interface encompasses following
- RecordActionWrapper class (for application/json responses)
- APIException class
-
The BaseCurrencyActionHandler interface encompasses following
- BaseCurrencyActionWrapper class (for application/json responses)
- APIException class
-
The MassUpdateActionHandler interface encompasses following
- MassUpdateActionWrapper class (for application/json responses)
- APIException class
- The ConvertActionHandler interface encompasses following
- ConvertActionWrapper class (for application/json responses)
- APIException class
Multi-User support in the PHP SDK
The PHP SDK (from version 3.x.x) supports both single user and a multi-user app.
Multi-user App
Multi-users functionality is achieved using Initializer's static switchUser().
To Remove a user's configuration in SDK. Use the below code
-
The program execution starts from main().
-
The details of "user1" are is given in the variables user1, token1, environment1.
-
Similarly, the details of another user "user2" is given in the variables user2, token2, environment2.
-
Then, the switchUser() function is used to switch between the "user1" and "user2" as required.
- Based on the latest switched user, the $this->getRecords($moduleAPIName) will fetch record.
SDK Sample code
All versions of php-sdk with dependencies
ext-json Version *
ext-curl Version *