This series aims to equip developers with all they need to build extensions for Zoho Desk in Zoho Sigma and publish them in Zoho Marketplace.
In our previous post, we introduced you to creating widgets in Zoho Desk with different APIs. We also gave a rundown on other data API sets and their functions. In this post, we'll continue this brief by showing you how to use Request APIs in the Zoho platform (Sigma) to build extensions for Zoho Desk.
Request API
While building an extension, you may be required to communicate with third-party applications through APIs. Let's say you want to request information from a third-party app and view it within your own. A request API allows you to reach the third-party app's API and obtain the information you need. It also avoids CORS-related issues and successfully runs the third-party API in your extension, meaning that you have consistent access to the information without having to run the request over and over.
Calling third-party APIs
A request API requires an object as its parameter. The request object must contain the values for the following keys.
- url: Refers to the third-party API
- headers: HTTP header
- type: HTTP method type
- data: Pass a query parameter as an object
- postBody: Parameters to be set to API
- connectionLinkName: Name of the connector that is configured in Sigma to contact a third party
Here is a sample code snippet of the request API's request object:
var reqObj=
{
type : 'GET',
data : { 'test' : "key" },
postBody : {},
connectionLinkName : "connectionLinkName specified in the connectors section in plugin-manifest file"
}
ZOHODESK.request( reqObj ).then(function(response){
// Response for the url
}).catch(function(err){
// Error handling
})
Scenario: Let's consider you are building an extension that needs to fetch customer data from the Contacts module in Zoho CRM and add it to the Customers module in Zoho Desk. To execute this function, you must establish a connection between Zoho Desk and Zoho CRM with the required parameters. This will allow you to make requests to these services by invoking their APIs. Check out "Building Extensions #6" to learn more about these connections.
Once the connection is established, a JSON file will be created. It then has to be added to the 'zohoAuthorisation' key of the plugin-manifest.json file.
Note: When you create a connection using Zoho OAuth, you need to add "type":"connectors" along with the other keys. Refer to the code snippet given below.
Also, under whiteListedDomains, the API domains of Zoho CRM and Zoho Desk must be added to ensure a secure data transfer between the two applications.
Note: Data transfer between Zoho Desk and any other third-party providers can also be facilitated in the same way.
Once the connection is established and the configurations are completed in the plugin-manifest.json file, you can go ahead and call the required APIs to implement the feature.
As mentioned earlier, we need to fetch a record from the Contacts module of Zoho CRM and push that data to the Customers module of Zoho Desk. So let's see how these APIs are invoked using the ZOHODESK.request JS SDK method.
The code below demonstrates how a particular record can be fetched from Zoho CRM and pushed in to Zoho Desk.
- Use ZOHODESK.request and invoke Zoho CRM's "get record" API. In our code, we have fetched a record by its ID.
Construct the request object for ZOHODESK.request.
{
type : 'GET',
data : {},
connectionLinkName : 'zohocrm',
postBody : {},contentType: "application/json",dataType: "json",service : ""
}
- Extract the required values from the response of the request.
- Use ZOHODESK.request to invoke Zoho Desk's "Create Contacts" API.
Now use the data extracted from Zoho CRM to construct the request object for pushing the data into Zoho Desk.
{
type : 'POST',
data : {},
connectionLinkName : 'zohocrm',
postBody : {"lastName" : name,
"email" : email},
contentType: "application/json",
dataType: "json",
service : ""
}
In this code, the email and last name of a particular contact from the Contacts module in Zoho CRM is chosen to be pushed into the Customers module in Zoho Desk.
We hope that the example code above has given you a clear picture on how to use the JS SDK method ZOHODESK.request. Stay tuned for our next post where we will discuss another SDK method.