Extension Pointers: Handling real-time data updates between Zoho CRM and third-party applications using webhooks

Extension Pointers: Handling real-time data updates between Zoho CRM and third-party applications using webhooks

A webhook is a web callback triggered by a specific event to provide real-time data updates between applications.


How does a webhook work?

Webhooks help enhance the connection between two applications. When an event occurs in a web application that implements a webhook, the webhook notices the event, serializes and collects the data, and posts the data to the URL configured in the form of a HTTP request.

You can implement either an inbound webhook or an outbound webhook. If an event triggered in your Zoho CRM account causes an action in a third-party application, it is called as an outbound webhook (going from your application to a third-party application) and the opposite is called an inbound webhook (incoming to your application from the third-party application).

How functions play a role in implementing webhooks

If Zoho CRM should be notified when a particular event occurs at the third-party end, you can create webhooks to post a callback on the occurrence of that event. In order to implement this, you need to define a function in your extension that can be triggered from the third-party application. Unlike standard functions, REST API functions can be triggered from anywhere (either from an extension or a third-party application) and thus help with timely interaction. 

Webhook URLs and how to obtain them

You need to create a webhook and subscribe to events for real-time updates between applications. In order to create a webhook, a webhook URL is required. By subscribing your own webhook URL, you can customize, extend and integrate it with other third-party applications, facilitating instant web notifications.

The REST API functions/Standalone deluge functions can be written and exposed as REST APIs. The API names of these functions can be used as the webhook URL while creating your webhook.

In this post, we'll look at the basic steps on how to create an inbound webhook, where a third-party application event triggers a post-data action to your Zoho CRM account.

Note: The term "event" here refers only to the events supported by the third-party application, which you can subscribe during the creation of a webhook.

The steps to achieve this functionality while building your extension are:

➤ Establish a connection with your selected third-party application.
➤ Define a REST API function, to handle the response from the third party application.
Subscribe the webhook URL of the REST API function with the third-party application.




Establishing connection with the third-party application

1. Before proceeding with implementation, it is important to check whether the third-party application supports webhooks. Establish a connection between Zoho CRM and the third-party application using the authentication methods supported by the application. You can learn more about the authentication methods for developing third-party integrations here.

2. If the method of user authentication supported by the third-party application is
3. Define the third-party application's API to create a webhook with the required parameters specified by the third-party application.

Note: The subscription URL is termed in different ways by each application and is an important parameter to be noted while creating webhooks. In order to send the response to Zoho CRM, the third-party applications require a URL to perform HTTP POST request from their end. The following section defines the steps required to obtain this URL.

Defining a REST API function and obtaining a webhook URL

After establishing the connection, the next step is to define a REST API function that can be invoked by the third-party application whenever a subscribed event occurs in the third-party application.

1.  Log in to Zoho Sigma and go to the Extension Details page.
2. Choose Functions under Automate from the left panel of the Zoho Developer console under Build, then click New Function.



3. Enter the name of the function. Choose Yes for the Invoke as REST API option to create the function as a REST API function.



4. The crmAPIRequest argument of the function is categorized as Map type by default. The entire request object is mapped automatically to the crmAPIRequest argument and holds the response from the third-party when the trigger event occurs.



5. The input for the function can be acquired from the following types:

Component
Format
Value fetched using component of crmAPIRequest
 body
request_body =   crmAPIRequest.get("body");
Content that is passed as a stream to the request
 params
parameters = crmAPIRequest.get("params");
Key-value pair or as JSON object to the request
 file_content
filecontent = crmAPIRequest.get("file_content");
File content passed to the request
 user_info
user_info = crmAPIRequest.get("user_info");
Information about the user

 method
method = crmAPIRequest.get("method");
HTTP method name in the request
 auth_type
authtype = crmAPIRequest.get("auth_type");
The name of the Authentication method(API key)
 headers
headers = crmAPIRequest.get("headers");
Additional information of the request available in the header

6. The default return type of a Rest API function version 2.0 is a string. You can choose to return the response as a string or use the response object crmAPIResponse to define the following specifications of the response:

 Specification key
 Default value
 status_code
 200
 Content-Type
 application/json;charset=utf-8
 headers
 {"Content-Disposition", "attachment;filename=response.json"}
 body
 empty

7. When you have finished defining the REST API code, click Invoke as the REST API button.


8. The URLs to invoke the function will be displayed and are termed as webhook URLs, which will be used for subscribing the function with the third-party.


Unlike the sandbox URL provided with a predefined ZAPI key, the production URL requires the value of the user's ZAPI key.

Why ZAPI key?

For authentication purposes, the REST API functions use API keys as the method of authentication. It requires the value of the ZAPI key in order to authenticate a user.

Code snippet to obtain ZAPI Key
  m = {"nameSpace":"<portal_name.extension_namespace>"};
  apikeyresp = zoho.crm.invokeConnector("crm.zapikey",m);
  zapikey = apikeyresp.get("response");

9. The ZAPI key value can be passed in the Production URL, which will serve as a webhook URL to subscribe a webhook and invoke this function.

Creating and subscribing a webhook

➤ REST API functions can be triggered from a third-party application only when it is subscribed with that application while creating an inbound webhook.

➤ The webhook URL mentioned in the previous section will serve as the subscription URL while creating the webhook.

By following these steps, you can implement webhooks for third-party integrations using REST API functions. In our upcoming post, we'll look at a working example depicting this process.

We hope you found this guide helpful in creating and using custom webhooks to link your Zoho CRM account to third-party applications.For tips and guides like this, keep following this community forum.

SEE ALSO








                            Zoho Desk Resources

                            • Desk Community Learning Series


                            • Digest


                            • Functions


                            • Meetups


                            • Kbase


                            • Resources


                            • Glossary


                            • Desk Marketplace


                            • MVP Corner


                            • Word of the Day



                                Zoho Marketing Automation


                                        Manage your brands on social media



                                              Zoho TeamInbox Resources

                                                Zoho DataPrep Resources



                                                  Zoho CRM Plus Resources

                                                    Zoho Books Resources


                                                      Zoho Subscriptions Resources

                                                        Zoho Projects Resources


                                                          Zoho Sprints Resources


                                                            Qntrl Resources


                                                              Zoho Creator Resources


                                                                Zoho WorkDrive Resources



                                                                  Zoho Campaigns Resources

                                                                    Zoho CRM Resources

                                                                    • CRM Community Learning Series

                                                                      CRM Community Learning Series


                                                                    • Tips

                                                                      Tips

                                                                    • Functions

                                                                      Functions

                                                                    • Meetups

                                                                      Meetups

                                                                    • Kbase

                                                                      Kbase

                                                                    • Resources

                                                                      Resources

                                                                    • Digest

                                                                      Digest

                                                                    • CRM Marketplace

                                                                      CRM Marketplace

                                                                    • MVP Corner

                                                                      MVP Corner

                                                                    





                                                                    




                                                                        Design. Discuss. Deliver.

                                                                        Create visually engaging stories with Zoho Show.

                                                                        Get Started Now