Serverless architecture, also known as “Function-as-a-service”(Faas), provides a platform for developers to execute their own codes in response of various business events. In Zoho CRM, all these codes can be written through deluge scripts and can be run without provisioning or managing servers. These codes once written can be triggered from any other third party services or it can be called directly triggered from any web or mobile app.
Though it is called “Serverless”, it requires servers to run code. So, the word “Serverless” defines that the developers or organizations need not buy or provision or rent any servers to run their code.
Calling Functions using REST APIs
A function lets you have additional functionalities and features in your CRM apart from the conventional features. Functions needs a trigger to call it. The trigger could be in the form of a workflow, blueprint, related list or through the click of a button.
If the function needs to be triggered without employing these methods or from external sources, you can create standalone functions and make them available as API calls. Triggering functions through REST APIs which gives the flexibility to trigger it from anywhere inside Zoho CRM or from any third party application.
You can call functions as an API in two ways:
Apart from using functions as APIs, you can also use functions within other functions. This is made possible since the entire function is reduced to a single line of code.
However, there are some precautions that you need to take when calling a function in another function. The following is a sample code snippet which denotes a function called within another function.
Function within a function(using APIs)
- URL=<REST API Function URL>;
- param = Map();
- param.put(<argument-name>, <argument-value>);
- param.put(<argument-name>, <argument-value>);
- param.put(<argument-name>, <argument-value>);
- argument = Map();
- argument.put("arguments", param);
- response = invokeurl
- [
- url: URL
- type: GET | POST
- parameters: argument
- headers: {}
- ];
- return response;
Functions in Postman
Functions which are given as API calls can be tested using POSTMAN application. However, there are a few things that you need to keep in mind when executing a function in that app.
Argument:
- arguments=
- {
- "emailAddress":"abc@gmail.com",
- "extraDetails":{
- "name":"Abc",
- "signature":"XYZ"
- }
- }
Note
Please avoid using the name "arguments" as an argument within the function. This is because all of the arguments passed inside the JSON will be mapped to the single "arguments" and the others will be left empty.
Request URL
HTTP Methods
The arguments given below are in encoded format.
You cannot pass the arguments as a JSON object within the request URL. Please encode the arguments in case they are to be given within the request URL.
- arguments=%7B%0D%0A%09"emailAddress"%3A"abc@gmail.com"%2C%0D%0A%09"extraDetails"%3A%7B%0D%0A%09%09"name"%3A"Abc"%2C%0D%0A%09%09"signature"%3A"XYZ"%0D%0A%09%7D%0D%0A%7D%0D%0A
You can call the arguments as a Header in the API. For instance, URL would be "{Rest API URL}?age=15&name=Robert", where "age" and "name" are arguments in the function.
Additionally, for any extra arguments that are not defined in the function, but used in the API, normally an error would be thrown. However, you can preemptively add an extra argument in the function under the name "CRM API Request". This argument would contain or take in all the extra arguments that you pass within the API call.
Request Body
In the Body > form-data section, create a key with the name "arguments".
- arguments={"emailAddress":"abc@gmail.com","extraDetails":{"name":"Abc","signature":"XYZ"}}
Note
POST request - Arguments Limit
- In Request URL - 5000 lines.
- In Body - 95000 lines (as JSON object).
Calling a Function within another Function
Often, there might be some requirements where functions needed to be called within other functions. Just like how you call a function within Workflows, you can call them within other functions. Let us consider two functions, A and B.
In order to pass the arguments(parameters) from function A to B, they would have to be passed either in the Query URL String or in form-data. In order to achieve that, please make use of the snippet given below within your function.
The above code snippet showcases a sample where the arguments from function A are called as parameters in the . You need to create a list with the name 'file' and decide how the params of the function A will be made use of in function B.
The headers of the function is form-data and the 'file' needs to be called.
You can directly copy the below code snippet within your function.
- param = Map();
- param.put("{key}","{value}");
- param.put("{key}","{value}");
- param.put("{key}","{value}");
- files = list();
- for each key in param.keys()
- {
- stringpart = Map();
- stringpart.put("stringPart","true");
- stringpart.put("content","" + param.get(key));
- stringpart.put("paramName",key);
- files.add(stringpart);
- }
- response = invokeurl
- [
- url :"{Function_API_URL}"
- type :POST
- headers:{"Content-Type":"multipart/form-data"}
- files:files
- ];