You can get the entire Request Object within the function using the "crmAPIRequest" argument.
Say you've created a function and defined 2 arguments. Now you need to use the same function in 2 different webhooks, each of which might contain different types and amount of information. One of them uploads data as a JSON object and the other one uploads a CSV file. Now those two are different types of data and may not be available in an argument inside the function.
In this case, you can make use of the crmAPIRequest argument to get the corresponding content.
The "crmAPIRequest" argument can be used to get the data from the "Body", "Parameter", "Header" or "User" information. With this single argument, the need to create multiple arguments within the function is not needed, as it dynamically stores the information from the request and makes it available inside the function.
- You don't have to manually pass values to the crmAPIRequest. The CRM maps the request object to the argument.
- Still, if any value is passed for the crmAPIRequest argument, it will be overidden by the request info.
A sample output from POSTMAN
Response object
The user can define how the response of the API is going to be. If the user wants to display/get a particular response code as the response of the function, he can specify it within the function.
In addition to status codes, the user can also choose to get the response in a specific file type, such as a JSON, HTML, Text, etc.
The crmAPIResponse in the function serves as the argument that lets you determine the type and the content of the output response.
Status Code
There are only a few status codes that are usually used to identify if the API call is successful or if it a bad request. You can define the status code to be displayed for the API call.
The default status code is 200.
To set the status code
- /**
- Your Business Logic here
- **/
- response = Map();
- // to override the status code to 204.
- response.put("status_code",204);
- return {"crmAPIResponse":response};
Content-Type
In addition to status codes, the response which is usually given as a JSON object can be set to be obtained in a different format.
The default value of this key is application/json;charset=utf-8.
To get the response in text format
- /**
- Your Business Logic here
- **/
- response = Map();
- // to override the content type, default is application/json
- response.put("Content-Type","application/text");
- return {"crmAPIResponse":response};
Headers
Response headers are useful in defining the size and type of file/data that the API call gives out as a response. In some cases, people prefer to view the response headers, since they are useful in determining the next course of action, i.e, next API call.
The default value of this key is {"Content-Disposition", "attachment;filename=response.json"}.
To get the response headers
- /**
- Your Business Logic here
- **/
- response = Map();
- headers = Map();
- headers.put("X-ZOHO-SOURCE","CRM");
- headers.put("X-Frame-Options","SAMEORIGIN");
- headers.put("X-RATELIMIT-LIMIT","60");
- response.put("headers",headers);
- return {"crmAPIResponse":response};
Body
Response body will contain the information that you need to send to the 3rd party as a response to their request.
The default value of body is empty.
To get the response headers
- /**
- Your Business Logic here
- **/
- response = Map();
- body = "{<XML>}"
- response.put("body",body);
- return {"crmAPIResponse":response};