While seamless data exchange is possible between Zoho CRM and third-party applications using connectors or custom variables as the binding knot, managing data updates in real-time lies a step ahead. Webhooks can help with this, as they serve as web callbacks to provide real-time data updates between applications on the occurrence of an event. To learn about Webhooks in more detail, please refer here.
In this post, we'll look at an example that depicts a Zoho CRM inbound webhook. This webhook sends data updates to Zoho CRM in real time, based on the occurrence of an event in the integrated third-party application, SurveyMonkey.
Let's assume a scenario where a survey created with SurveyMonkey will be sent to the Zoho CRM contact after successful completion of a deal in order to obtain their feedback. The inbound webhook in our example would be configured to trigger a post action whenever the contact responds to and completes the survey. This response will be updated in real-time to the Zoho CRM account, which could be used to make further data manipulations as per business requirements.
Let's take a look at the major pointers that will be explained in this example to create an inbound webhook and achieve the above mentioned functionality:
➤ Establish a connection between Zoho CRM and SurveyMonkey
➤ Define a REST API function that needs to be subscribed with SurveyMonkey
➤ Create and test your webhook
Establishing Connection between Zoho CRM and SurveyMonkey
- Create a connector to integrate SurveyMonkey with Zoho CRM. SurveyMonkey supports OAuth method for user authentication. Please refer here to find the detailed steps involved in creating a connector.
- Define the webhook API of SurveyMonkey with the specified parameters to create a webhook, along with the other essential API's (Get all survey details, Get survey details by ID).
SurveyMonkey Connector's API details:
API Name
| Method
| URL
|
Get survey by ID
| GET
| |
Get Surveys
| GET
| |
Create Webhook
| POST
| |
Refer to the API documentation of SurveyMonkey for header and body parameter specifications of the APIs. After creating the connector and adding the API, publish and associate it with your respective extension.
Note: SurveyMonkey Webhooks can be configured for various events. For our example, we have subscribed the event "response-completed" for Surveys. Whenever a user completes responding to a survey, callback will happen, which in turn will trigger the REST API function.
Defining a Rest API function
SurveyMonkey webhook requires a subscription URL to be constructed as one of the parameters for the Create Webhook API. In order to obtain this URL, we need to define a REST API function that is capable of being triggered from the SurveyMonkey application during callback. The Survey Monkey webhook that will be configured (steps included in the upcoming parts of the post) will deliver the response to the subscribed REST API function. You can access this response through the REST API function input parameter and handle them as per your business process requirements.
1. Log in to Zoho Sigma, then 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. Click Next, then enter the code in the Deluge editor.
Note: Once the webhook is created successfully, this REST API function will also be successfully subscribed with the third party. When the subscribed event (survey completion) occurs, the third-party will perform the callback and the response will be sent to this function. The response format may vary between third-party applications. Based on the third-party application that you integrate with, extract the required data from the response using the input parameter, crmAPIRequest of the REST API function. The value can be acquired using the different data types as mentioned in this post. After retrieving the required values, data manipulations can be performed according to business logic.
5. Click Save & Close.
After defining the code for the REST API function, click Invoke as REST API button to obtain the URL. The sandbox URL provided with the zapi key value can be used to test the functionality locally in the sandbox environment. The production URL displayed along with the value of zapi key will serve as the subscription URL while creating the Webhook. The zapi key acts as the REST API function's method of authentication.
Creating the webhook
Create a webhook by passing the required values needed for the Webhook API. In our example, we have chosen to create the webhook and subscribe the REST API function during the authorization of the connector.
Note: You have the option to perform actions through custom function while installing an extension, uninstalling an extension, authorizing a connector, or revoking a connector. You can choose the best option that fits your needs.
1. Choose Connectors under Install Actions from the left panel of the Zoho Developer console under Build.
2. Choose On Authorization. Enter the code functionality to be performed during the connector authorization.
Code snippet
// Fetching the value of the ZAPI key to be appended in the subscription url
m = {"nameSpace":"xxx.surveymonkey4"};
apikeyresp = zoho.crm.invokeConnector("crm.zapikey",m);
zapikey = apikeyresp.get("response");
// Invoking the Get Surveys API call
resp = zoho.crm.invokeConnector("surveymonkey4.surveymonkeyconnector.getsurveys",dynamic_map1);
response = resp.get("response");
data = response.get("data");
for each dataa in data
{
// Retrieving the survey ID from response of the Get Surveys API call
id = dataa.get("id");
info id;
dynamic_map = Map();
// Assigning the ID retrieved to the object_id parameter
dynamic_map.put("object_id",id);
// Assigning the combined value of url and zapikey obtained to URL parameter
dynamic_map.put("url",{REST API URL} + zapikey);
// Invoking Create webhook API to subscribe the webhook with SurveyMonkey
resp = zoho.crm.invokeConnector("surveymonkey4.surveymonkeyconnector.createwebhook",dynamic_map);
}
return "";
|
➤ The Zapi keyvalue is obtained and stored in a variable called zapikey.
➤ The Get Surveys API call of the SurveyMonkey connector is invoked, and the survey ID is obtained from its response. The retrieved ID is assigned to the object_id parameter required for the Create Webhook API.
➤ Similarly, the url parameter required for the Create Webhook API call is assigned with the value obtained by appending the url (Production URL) and zapikey variable values fetched earlier.
➤ The Create Webhook API of the connector is invoked using zoho.crm.invokeConnector after constructing the required parameters.
➤ The webhook will be subscribed with SurveyMonkey when the connector is authorized and real-time updates can flow in from SurveyMonkey to Zoho CRM.
You can choose to further enhance the functionality by performing data manipulations on the response received from a third-party application via the REST API function, according to your business needs. For more information on extension, keep following this space.