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.
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".
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.
var acc=$Page.record_id;
var parameters = {
"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}`