Kaizen #202 - Answering Your Questions | Testing and Using REST APIs in Widgets
Hello Developers!
Welcome back to a fresh week of Kaizen!
Thank you for your active participation in sharing feedback and queries for the 200th milestone. This week, we will look at the following queries related to widget:
- Widget Testing
- Using REST API in Canvas Widgets: Make HTTP calls in widgets (e.g., to external tax or product APIs)

Since the localhost connection opens in a new tab and is not private, you will need to manually authorize it.
Click Advanced, then choose Proceed to 127.0.0.1 (unsafe) to continue.
Note
If your widget needs to access data from your Zoho CRM organization, such as fetching or updating records, it must be deployed within a Zoho CRM iframe. To do this, you should upload the widget through the Zoho CRM Widgets setup page.
We recommend using the
sandbox environment in such cases before deploying the widget to your production environment.
Making HTTP Calls from Widget
Following is a query we received from a user:
Using REST API in Canvas Widgets: Make HTTP calls in widgets (e.g., to external tax or product APIs)
Yes. You can make HTTP requests to external services from any type of Zoho CRM widget using the
ZOHO.CRM.HTTP object from the
Widget JS SDK.
Canvas Widget - What's Supported?
Though full widget support within Canvas is on our roadmap, currently, you can invoke widgets from a Canvas view using Client Script. This lets you render widgets inside fly-outs or pop-ups. Here is a quick start guide on how you can achieve it:
Create a Widget
1. Create a widget project and code your logic using Zoho CLI as explained in our
widget help page.
2. In Zoho CRM Developer Hub, create a new widget and set the type as
Button.

Create a Client Script
3. Navigate to Client Scripts in Developer Hub and click New Script.
4. You can create your script either in the Modules or Commands category based on your use case.
In the Category Details section, ensure to select Canvas as the page type. Canvas views are supported in the following page contexts: List, Detail, Create, and Clone.
Choose the one that aligns with where your widget needs to appear.
5. Here is the sample script to render widget in a pop-up.
ZDK.Client.openPopup({ api_name: 'Canvas_Widget', type: 'widget', animation_type: 4, height: '450px', width: '450px', }, { data: 'sample data to be passed to "PageLoad" event of widget' }); |
Here is the sample script to render widget in a fly-out.
ZDK.Client.createFlyout('myFlyout', { animation_type: 4, height: '600px', width: '500px' } ); ZDK.Client.getFlyout('myFlyout').open({ api_name: 'Canvas_Widget', type: 'widget' }); |
For detailed guidance, check out our Client API documentation on
Pop-up and
Fly-out.
Using REST APIs from External Applications
The
ZOHO.CRM.HTTP object enables you to make secure API calls directly from the Zoho CRM widget. It acts as a proxy, routing requests through Zoho servers, which eliminates the need for external applications to support CORS.
While this SDK is primarily used for integrating third-party services, it also supports
Zoho CRM API calls. This provides you with greater flexibility to:
- Customize header and parameter structures
- Maintain a consistent calling pattern for both internal and external APIs within the widget.
Here is a basic syntax of the SDK:
ZOHO.CRM.HTTP.<method>({ url: "<request-url>", headers: { // Request headers as Key-value pairs "Authorization": "Bearer <token>" // example }, params: { // Request params as Key-value pairs
"ids": "1234567890" // example }, body: "<stringified JSON>", // Required for POST, PUT and PATCH }) .then(function(response) { console.log("Response:", response); }); |
Supported Methods
- ZOHO.CRM.HTTP.get({ ... })
- ZOHO.CRM.HTTP.post({ ... })
- ZOHO.CRM.HTTP.put({ ... })
- ZOHO.CRM.HTTP.patch({ ... })
- ZOHO.CRM.HTTP.delete({ ... })
For more detail check out the HTTP method section of
JS SDK help page.
Samples using Zoho CRM Contact Roles API
Let us explore a complete CRUD (Create, Read, Update, Delete) example using Zoho CRM’s
Contact Roles API.
These structures have to be used within the JS function where you are executing your code logic.
POST Contact Roles
// Prepare the API request
var request = { url: "https://www.zohoapis.com/crm/v8/Contacts/roles", headers: { Authorization: "Zoho-oauthtoken 1000.XXXXXXXXXXXXXXXXXXX265bcf20e4" }, body: { "contact_roles": [ { "name": "Sales Lead", "sequence_number": 1 } ] } }; // Make API call ZOHO.CRM.HTTP.post(request).then(function(data) { console.log(data); }) |
GET Contact Roles
// Prepare the API request
var request = { url: "https://www.zohoapis.com/crm/v8/Contacts/roles", headers: { Authorization: "Zoho-oauthtoken 1000.XXXXXXXXXXXXXXXXXXX265bcf20e4" } }; // Make API call ZOHO.CRM.HTTP.get(request) .then(function(response) { console.log(response); }) |
UPDATE Contact Roles
// Prepare the API request var request = { headers: { Authorization: "Zoho-oauthtoken 1000.XXXXXXXXXXXXXXXXXXX265bcf20e4" }, body: { "contact_roles": [ { "name": "Evaluator", "id": "5545974000000006871" } ] } }; // Make API call ZOHO.CRM.HTTP.put(request).then(function(data) { console.log(data); })
|
DELETE Contact Roles
// Prepare the API request
var request = { params: { ids: "5545974000002617002" }, headers: { Authorization: "Zoho-oauthtoken 1000.XXXXXXXXXXXXXXXXXXX265bcf20e4" } }; // Make API call ZOHO.CRM.HTTP.delete(request).then(function(data) { console.log(data); })
|
We hope you found this post useful.
Let us know if you have any questions in the comments or drop us an email at
support@zohocrm.com.
Cheers!
------------------------------------------------------------------------------------------------------------------------
Related Reading
------------------------------------------------------------------------------------------------------------------------