How to call Zoho CRM APIs using Client Script

How to call Zoho CRM APIs using Client Script



Welcome back to another exciting Client Script post!
In this post, we will discuss one of the most frequently asked questions: How do you call Zoho CRM APIs from Client Scripts?

In this kaizen post,


1. Ways to make calls to Zoho CRM APIs using Client Script
      1.A  Client Script ZDK CRM APIs
      1.B. Using Connections
2. Requirement
3. Solution
      3.A. Create a Connection
      3.B. Invoke API using Client Script
4. Summary
5. Related Links



1. Ways to make calls to Zoho CRM APIs using Client Script

1.A  Client Script ZDK CRM APIs 
  • You can use the available Client Script ZDK CRM APIs to call v2 APIs directly from within your Client Script. 
  • To view this documentation, click on the help icon next to CRM API in the Library Section of the Client Script Editor. Here is how the screenshot of the documentation looks.


1.B. Using Connections

For calling other Zoho CRM APIs(other than the APIS covered in Client Script's ZDK CRM API) or third-party services, you will have to use Connections along with Client Script. In this post, let us see how to call Zoho CRM APIs. Check the Kaizen post on Third Party Integration using Client Script to know how to call Third Party APIs from Client Script.

2. Requirement

To retrieve all open deals for the currently viewed account.

3. Solution

To fetch app open deals for an account, you can use  COQL API. You can also use the Related Records API, get deals of a given account ID, and then filter the open deals.
But COQL API is recommended due to the following reasons.
- There is no indexing delay.
- You can use comparators such as is null, is not null, between, in, not in, like, and not like in your search query.
- You can fetch data from other lookup modules if any. Click this Kaizen Post for more details.
To accomplish this requirement, create a connection with the scopes for the API you want to call and create a Client Script

3.A. Create a Connection
  • To setup Connection, follow the below steps.
  • In Zoho CRM, go to Setup → Developer Hub → Connections and click "Create Connection".

  1. Select Zoho OAuth in Default Services and click "Create and Connect".

  • Specify a name for the Connection and select the Scopes required for COQL API.
ZohoCRM.coql.READ (and) ZohoCRM.modules.READ
(or)
ZohoCRM.modules.{module_name}.{operation_type}

  • Click Create and Connect.


3.B. Invoke API using Client Script
  • Go to Setup → Developer Space →Client Script. Click +New Script.
  • Specify the details to create a script and click Next.

  • Enter the following script and Click Save.

  1. var acc=$Page.record_id;
  2. var parameters = {
  3. "select_query": `SELECT Stage,Account_Name.id from Deals where Stage not in ('Closed Lost','Closed Won','Closed - Lost to Competition') and Account_Name.id = ${acc}`
  4. };
  5. var response = ZDK.Apps.CRM.Connections.invoke("c", "https://www.zohoapis.com/crm/v6/coql", "POST", 2, parameters, {});
  6. log(JSON.stringify(response));
  • You can invoke COQL API using Connections in Client Script using invoke() method.


Click here to know more about the Connections.
Here ,
  • Connection name is test
  • url is https://www.zohoapis.com/crm/v7/coql
  • method is POST
  • param_type is 2
  • parameters is the query stored in parameters variable.
  • headers - there are no headers in this case.
Summary

In this post we have discussed the following.
1. How to call COQL API using Client Script 
2. Steps involved to include the scopes via Connection
3. Advantages of COQL API