Kaizen 202 - Answering Your Questions | Testing and Using REST APIs in Widgets

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)
Here are the queries that we have already answered for you from this milestone:
  1. Kaizen #200 - Answering Your Questions | Token generation using the Python SDK
  2. Kaizen #201 - Answering Your Questions | Webhooks, Functions, and Schedules

Widget Testing

One of the queries we received was simply stated
Quote
Widget Testing
 without any specific context. Since the user has not provided detailed input, we are assuming this is about how to test a widget during development.

You can test your Zoho CRM widget locally using the Zoho CLI. Run the following command from the root directory of your widget project:

zet run

This launches the widget on a local server where you can validate the UI and functionality before pushing it live.


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. 

Notes
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:
Quote
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. 

For assistance, refer to the step-by-step guide on Creating Client Script and Commands.



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.

You can also check out the Kaizen #99 on Rendering Widgets using Client Script for a detailed guide based on a real-time use case. 

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


------------------------------------------------------------------------------------------------------------------------
    • Sticky Posts

    • Kaizen #197: Frequently Asked Questions on GraphQL APIs

      🎊 Nearing 200th Kaizen Post – We want to hear from you! Do you have any questions, suggestions, or topics you would like us to cover in future posts? Your insights and suggestions help us shape future content and make this series better for everyone.
    • Kaizen #198: Using Client Script for Custom Validation in Blueprint

      Nearing 200th Kaizen Post – 1 More to the Big Two-Oh-Oh! Do you have any questions, suggestions, or topics you would like us to cover in future posts? Your insights and suggestions help us shape future content and make this series better for everyone.
    • Celebrating 200 posts of Kaizen! Share your ideas for the milestone post

      Hello Developers, We launched the Kaizen series in 2019 to share helpful content to support your Zoho CRM development journey. Staying true to its spirit—Kaizen Series: Continuous Improvement for Developer Experience—we've shared everything from FAQs
    • Kaizen #193: Creating different fields in Zoho CRM through API

      🎊 Nearing 200th Kaizen Post – We want to hear from you! Do you have any questions, suggestions, or topics you would like us to cover in future posts? Your insights and suggestions help us shape future content and make this series better for everyone.
    • Client Script | Update - Introducing Commands in Client Script!

      Have you ever wished you could trigger Client Script from contexts other than just the supported pages and events? Have you ever wanted to leverage the advantage of Client Script at your finger tip? Discover the power of Client Script - Commands! Commands
    • Recent Topics

    • How to filter deals for anything not yet delivered

      Hello I want to be able to filter my deals for anything where the Sales Order is not delivered. I'm stuck because I want to include deals with and without Sales Orders, and just exclude ones with an associated Sales Order which is stage Delivered Does
    • Currency fields and decimal places in CRM email templates

      Hi, How do I get more than the standard 2 decimal places showing in a Currency field, on an email template? In the Layout for my Currency field, it is set to 6 decimal places. I want to show up to 6 places in the email template (unrounded). See attached
    • Package Dimensions

      Packages need to have dimensions that are sent to carriers in addition to just the weight. Without the package dimensions being transmitted to carriers, the correct dimensional weight is not calculated for the label price, which results in corrections
    • Zoho One for Multiple Organisation under a Parent Company

      Dear Zoho One, We are a two companies running different business (service and sales) in Malaysia, with our parent HQ in Germany, and we have multiple sister companies scattered across the region of Asia.  Currently, our malaysia branch is using Zoho CRM and are in the process of upgrading our accounting system with Zoho One. However, there is one huge problem, and that is Zoho Apps does not allow us to run multiple organisations with a single subscription. This is our only deal breaker at the moment/
    • Track All Emails from Company Domain

      For our business model, it's almost impossible to keep track of all emails sent to clients, under the way ZohoCRM currently tracks emails to customer records via the user account only. We'd like to see a way of tracking emails via domain only, separate
    • New in Zoho Sign: Allow recipients to review and change associated recipients

      Greetings! We are happy to announce the addition of a new recipient role, Manages recipients, in our signature workflows. This role enables a recipient to review, modify, or add details for any recipients associated with them in the workflow. This ensures
    • Workable tutorials on Zoho RPA sorely needed - who can share?

      Hi folks, I own several RPA tools and would love to switch to Zoho RPA just to keep everything in the same ecosystem. However, Zoho RPA documentation lacks examples of how to do the most basic activities where RPA is most common. In particular: 1. opening
    • Need head start/ideas for a new application using the portal

      Hi, I am just looking for ideas, or direction, about a new app. Simply put, I have multiple vendors offering products, and multiple customers buying those products. BUT the administrator controls the product offering and prices. For example, Vendor "A"
    • SMTP zoho email + prestashop problem

      Hi,  i just created an email for my domain with an e-shop built on prestashop... however, after setting the SMTP (myemail@mydomain.com, password is correct, server is smtp.zoho.com, port 465, SSL) i still get an error message saying i should check my settings. with gmail address it works fine, but zoho has a problem.. anybody encountered this problem, or has any idea or solution? thanks a lot.
    • Cannot paste consistently

      When authoring and editing articles in Zoho Learn, I often find that I am unable to paste content. Some days, Zoho will let me paste a few times using keyboard shortcuts (Ctrl-V), but then will randomly stop allowing this function.  I have also tried
    • Recording stripe fees for sales w/out invoices

      In my business, people make many purchases w/out an invoice using a credit card. With invoice payments, I record them as sales and deposit the $ to credit card clearing, deduct stripe fees associated on the bank fees line, and then I record the stripe
    • Fields from Zoho CRM not appearing in merged document

      Hi, I have a custom CRM module where certain fields are looked up from "Contacts". When I then try to run a mail merge from my custom module, the date from the fields which were fetched from contacts do not appear in the document. I just see the field
    • Going back to older version

      Hi, One of our tech did a new version of our app, but created problems that we do not have time to repair, we just want to go back to an older version for the moment. To make sure we choose the right older version, we also want to double-check the dates
    • Zoho Creator HTML Page

      Hello Team, I have a query related to the HTML page I created in Zoho Creator. I would like to apply some filters on this page without passing them through URL parameters. Could someone please guide me on how this can be achieved? Thanks & Regards, Piyush
    • Remote Assist Reboot - User can't login

      Last night one of our support agents was using Zoho Assist doing a remote assist session.  A reboot was required. Upon rebooting the Windows 10 user says he can't login and that he is getting an invalid password error.   Is this a known problem? Any thoughts?  Awaiting customer to arrive at work today to attempt safe mode boot.
    • Move a ticket from one department to another without creating the product in both departments

      Hello everyone, I am having serious problems with the products. When a customer creates a ticket in a department and selects a product by mistake and we move it to the corresponding department it automatically creates in both departments the product.
    • How do I setup product syncing between Desk and CRM?

      How do I setup product syncing between Desk and CRM? I can see in Desk where to add products, but it doesn't show the existing products I imported into CRM. Where do I turn on the syncing? I assume there's an option somewhere similar to the option to
    • multiple users unable to view campaigns

      I have just added two users to zoho campaigns.  when they log in they don't see the details regarding the email campaigns already run.  i would like all users to access this.
    • If a contact is deleted from Zoho CRM, will all related activities be deleted related to the contact?

      I think question is clear.
    • Factur-X

      Bonjour, J'ai découvert dans la dernière release notes de Zoho Books, l'apparition du support du format Factur-X (Export Transactions in Factur-X Format | Help | Zoho Books), mais il faut apparemment activer une nouvelle fonctionnalité de taxes. Quelqu'un
    • On Duty Requests using API

      Currently we can only do attendance entries using API, we need to make on Duty Requests using API Use Case We are using different on premise devices to track meetings, we want to sync this data with Zoho People Currently we are manually making on duty
    • Zoho desk Instant messaging no notification

      We are using whatsapp inside zoho desk instant messaging, however my agents are not notified if there is someone who send a message. We all miss messages because there is no indication there has been a message send. No notification badge, no notifications
    • need help to set up feeds to Zoho books with CRM Perks plugin

      Hi there, I need help setting up feeds with the CRM Perks plugin. It is supposed to send various feeds, like orders, payments, etc., from Woocommerce to Zoho Books. I have been trying so hard but seem to be too thick to get it done :-( For months, I worked
    • Instagram Visiual Planner

      Hello, I am loving the new updates with Zoho Social, especially the Canva integration. Is Zoho planning to offer the Instagram Visual Planner where you can preview what posts will look like on your timeline grid view before posting? There are many programs
    • How to distribute expenses evenly over the year?

      I want to distribute cost of f.e. licences or inssurance that occour once a year over the year. How can I do this? Is this even possible?
    • Free webinar: Zoho Sign in Q1 2025 - A quick walkthrough

      Hi, The first quarter of 2025 has flown by, and the Zoho Sign team has been hard at work releasing enterprise-grade features to enhance overall collaboration. Join us for our upcoming webinar, where we'll discuss what's new and what's to come. What will
    • How do I make a recurring subtask?

      I have a user that has a monthly task with several subtasks. I can set the main task to monthly recurrence but I've been unable deter how to get the subtasks to transfer with the recurring task. Should I setup tasks with dependency instead?
    • Workflow Failure - Notifications

      Good afternoon, I have just experienced an error whereby a Workflow failed, for a reason currently unknown. The problem is that one of my users had to flag this manually (thankfully he's very thorough) and this otherwise would have flown under the radar.
    • Introducing Linkthread by Zoho Social — our new link in bio tool

      Hey everyone, We hope you're all doing amazing. We always love bringing features and tools to make your social media marketing journey easier, and today, we've got a brand new tool that we'd like to introduce to you. We know how important it is to make
    • Determine agent work hours and break timings with Desk's agent availability report

      Hello everyone, We are excited to tell you about updates to the agent availability report, designed to enhance efficiency in tracking agents’ activities. What is the agent availability report? The agent availability report helps managers monitor team
    • Planned, actual and forecast hours

      Hi there, I'm attempting to use Zoho to plan projects and time, but it's so confusing. I have two questions: Why, in the screen shot below, is my planned hours saying 8? I have assigned 8 work hours to the task, and I have logged 4 hours of actuals. I
    • Add Comment/Notes to Each Action in Zoho Flow for Internal Documentation

      It would be great if Zoho Flow could introduce a field to every action where we can make an internal note about why we are doing something with a specific action. This is especially helpful if more than one person from the organization handles automation
    • Kaizen #188 - Building a Timer and Worklog Widget (Part 2)

      Welcome back, Tech Wizards! In Part 1, we developed a Timer Widget that logs active work sessions into the Timer Entries module. Now, let's enhance this functionality by transferring these entries into the Work Log subform within the Cases module using
    • How to use Quoted/Invoiced_Items custom fields APIs in Deluge ?

      Hi, I'm trying to do a function to create an invoice from my existing quote, but I can't use some datas in the mandatory Quoted_Items Subform as it's from custom fields I've created and it's available only using APIs V2.1. So I tried what I found in the
    • Can Not Categorize Sales vs Services for "On The Fly" Line Items

      We can not categorize Sales (Goods) and Services with Zoho Books for "on the fly" line items when creating a transaction (quote or invoice). Zoho Books does not provide the basic ability to separate product sales and services for "on the fly" line items
    • Can a Custom Button (custom action) ask for user input?

      We have already a few buttons adding the actual date to some fields on Stages changes, now we need to ask the user for a Date and add it to a field. Can it be done using a button? or any other way?
    • Canvas Flex Box containers should not require a width/height.

      Flexbox containers are often used as organizational concepts, to ease re-flow on mobile etc. - I cannot use % for flexbox W or H - I cannot omit W or H This means that the content cannot dictate, and a Flexbox container cannot be used merely as an organizational
    • Is is available to access notes from mobile app?

      As you know we have a notes section in the mail system at the website but can I access the Notes from the mobile app? Thanks in advance
    • Outlook sync (365) Restricting which contacts signals are created for & seeing my sales ppls email activity

      Hi All, As per the subject I want to restrict which contacts the signals notifications are activated for, and indeed which contacts email are tracked in the crm - my boss does not want his sensitive emails to end up in there but he does want to track
    • [Free Webinar] Learning Table Series - Zoho Creator for AI-Enhanced Property Management

      Hello Everyone! We’re excited to invite you to another edition of Learning Table Series, where we showcase how Zoho Creator empowers industries with innovative and automated solutions. About Learning Table Series Learning Table Series is a free, 45-60
    • Next Page