Hello everyone! Welcome to Kaizen #106.
In continuation to our
last post, today, we will discuss invoke URLs in functions, how they are different from integration tasks, and how authentication works for them.
What are invokeURL tasks?
invokeUrl task is a task designed to trigger HTTP API endpoints of Zoho apps or any external services. invokeUrl makes the authorization part much easier by setting up
connectors.
How are invoke URLs authenticated?
Connections allow you to connect to various third-party apps or other Zoho services. Connections essentially use the OAuth 2.0 protocol. It abstracts the entire OAuth2.0 authorization flow and keeps your code simple, clean, and crisp.
If you set up a connection once, and authorize it once, you can make API calls to and from the external system and Zoho CRM.
You can create a single connection for your org and other users of your org can use the same connection by authenticating it with their credentials. Other users of your org can use your connection. In such cases, your connection will appear as a "shared connection" in their accounts.
Similarly, if you use your credentials to authenticate a connection created by some other user, it will be listed under the "shared connections" of your account.
For more details on types of connections, refer to
this page.
Default Services
Zoho CRM has integrated with various third-party apps and they are listed under Default Services. All you have to do is
- Go to Setup > Developer Space > Connections > Create Connection.
- Under "Pick your service", choose the app you want to connect to. Here, I have chosen Gsheet.
- Click Create Connection.
- Specify the Connection Name and choose the scopes from the list. Note that this will vary based on the service you choose.
- Click Create and Connect.
- You will be redirected to a screen asking for your consent to connect to the service.
- Provide your login credentials.
- Click Connect. You will be redirected to Zoho Flow's authentication page, asking for your consent to connect to the service and redirect you to the service's login page.
- On the service's login page, provide your credentials and login.
- The service shows a pop up explaining the data that Zoho flow will use through the connection.
- Click Allow.
- The connection will be created in Zoho CRM.
- The sample code contains the snippet of the invoke URL you must use in your function to use the Gsheet's endpoints.
By simply using the connection name in your code, you can connect to third-party apps without worrying about token generation or configuration.
Components of the invoke URL
url - The third party's API endpoint you want to access.
type - The type of API call it is going to be. Supports GET, POST, PUT and DELETE.
parameters - The body of the request.
connection - The name of the connection you want to use.
For more details on invoke URL task, refer to
this page.
Custom Service
Use this option when the service you want to connect to is not listed under "Default Services".
To create a custom service and connect to it, you must give the details of the service like its name, authorization type, and other attributes, and take care of token generation.
Differences between integration tasks and invoke URLs
Integration Tasks | Invoke URLs |
API wrappers to Zoho APIs. Can be called just like built-in functions. | HTTP requests that are triggered explicitly. |
All integration task actions are triggered under the admin’s authorization. | All invokeUrl actions that are triggered pertain to the user that authorized the connection. |
Here is a sample of a function using invoke URL and the connection named "mine".
headermap = map();
headermap.put("this goes in the header", "value");
paramMap = map();
paramMap.put("this goes in the body", "body");
info paramMap;
response = invokeUrl [
type: POST
headers: headermap
content-type: "application/json"
parameters: paramMap.toString()
connection: "mine"
];
info response;
return ""; |
Here is the response.
As you can see, as the connection is already authenticated using OAuth2.0, the connection directly supplies the access token.
We hope you found this post useful. Let us know what you think in the comments, or email us at
support@zohocrm.com.
Cheers!