Ruby SDK for Zoho CRM APIs
The Ruby SDK for Zoho CRM allows developers to easily create Ruby applications that can be integrated with Zoho CRM. It serves as a wrapper for the Zoho CRM REST APIs, making it easier to access and utilize the services of Zoho CRM.
Authentication to access the CRM APIs is facilitated through OAuth2.0, and the authentication process is streamlined through the use of the Ruby SDK. The grant and access/refresh tokens are generated and managed within the SDK code, eliminating the need for manual handling during data synchronization between Zoho CRM and the client application.
The latest version of Ruby SDK (v2.0.0) supports version 7 of Zoho CRM APIs. For more information on the released Ruby SDK versions, refer here.
Prerequisites
- Ensure that the client app has Ruby version 2.6 or above.
- An IDE such as Visual Studio Code
- Zoho CRM account.
Step 1: Register your application
Before you get started with authorization and make any API calls using the Zoho CRM Ruby SDKs, you need to register your application with Zoho CRM.
- Go to Zoho API console and click on Add Client
- Choose the client type as Self Client or Server-based Applications depending on your requirements.
- Enter the required credentials.
- Click CREATE
- Make a note of the Client ID and Client Secret generated for your application.
Step 2 : Create a project and add Ruby SDK in your project.
In this step, you'll create a new project in your preferred IDE and add the Ruby SDK in your project. We will be using Visual Studio Code IDE in this guide.
- Create a project in your preferred IDE
- Install Ruby SDK by using gem. See Including the SDK in your project to learn more.
Step 3 : Generation of Grant token
Generate a grant token from the Zoho API Console by following the steps described in this page.
Step 4: Configuration and Initialization
In the configuration step, you will set up details such as user authentication, environment, token persistence, logging, and API call timeout settings. The following table gives the details of all the keys you can configure, with detailed explanation.
Key | Description | Sample |
---|---|---|
mandatory | The instance of UserSignature that identifies the current user, that takes user Email as parameter | user_signature = ZOHOCRMSDK::UserSignature.new('abc@zohocorp.com') |
mandatory | Represents the domain information to make API calls. Domains: USDataCenter, EUDataCenter, INDataCenter, CNDataCenter, AUDataCenter Environments: PRODUCTION(), DEVELOPER(), SANDBOX() | environment = ZOHOCRMSDK::DC::USDataCenter::PRODUCTION |
mandatory | Contains user token details. Depending on the tokens, you can choose grantToken flow, refreshToken flow, or accessToken flow. | token = ZOHOCRMSDK::Authenticator::OAuthToken.new(client_id: "clientId", client_secret:"clientSecret", grant_token:"grant_token", refresh_token:"refresh_token", redirect_url:"redirectURL", id:"id", access_token:"access_token") |
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. | log = ZOHOCRMSDK::SDKLog::Log.initialize(level: ZOHOCRMSDK::Levels::INFO, path:"/Users/user_name/Documents/rubysdk_log.log") |
optional | Contains details for the Token Persistence object. You can choose between DB Store, File Store, or Custom Store and configure accordingly. To know more about token persistence, refer here. | tokenstore = ZOHOCRMSDK::Store::FileStore.new("/Users/user_name/Documents/ruby_sdk_token.txt") |
optional | Contains additional configuration details like timeout, autorefresh fields, picklistvalidation, etc. | sdk_config = ZOHOCRMSDK::SDKConfig.new(auto_refresh_fields: false, pick_list_validation: true, open_timeout: 60, read_timeout: 60, write_timeout: 60,keep_alive_timeout: 2) |
optional | Contains the details of the proxy if you are using a proxy server to authenticate and make the API calls. | request_proxy = ZOHOCRMSDK::RequestProxy.new(host:"proxyHost", post:"proxyPort", user_name:"proxyUser", password:"password") |
resourcePath optional | The path containing the absolute directory path to store user-specific files containing the module fields information. | resource_path = "/Users/user_name/Documents/rubysdk-application" |
For detailed instructions on how to configure the above keys and get started, refer here. Find a sample code for initialization here.
Step 5 : Making requests using Ruby SDK
After you have configured and initialised, you can start making your requests using Ruby SDK and utilise the functionalities of Zoho CRM. Here is a sample code to insert a new record in to the Leads module.
Responses and Exceptions
When working with the Zoho CRM Ruby SDK, it is important to understand the responses and exceptions that can be encountered during API calls.
Note:
- The APIResponse object holds the results of your request. You can access the actual response data using the getObject() method.
- The APIResponse<ResponseHandler>and APIResponse<ActionHandler> are the common wrapper objects for handling responses from Zoho CRM APIs. This depends on the API. For more details, refer here.
- APIException: This exception is thrown for errors that are related to the API itself, such as authentication errors or invalid request parameters.
- SDKException: This exception is thrown for errors that are related to the Zoho CRM SDK, such as network errors or SDK implementation errors.
For more details on the Responses and Exceptions, refer here.