REST.call Function Reference
The scripting environment allows you to make external HTTP requests to interact with third-party APIs or services using the REST.call function. This is the current and recommended version for making REST API calls.
Syntax
REST.call(URL, method, headers, body);
Parameters
The REST.call function takes the following parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| URL | String | Yes | The URL endpoint for the REST API call. |
| method | String | Yes | The HTTP method to use (e.g., GET, POST, PUT, DELETE, etc.). |
| headers | Object | Yes | An object containing key-value pairs for the request headers (e.g., { 'Content-Type': 'application/json', 'Authorization': 'Bearer ...' }). |
| body | Any | Yes | The body of the request. The expected type depends on the method and the Content-Type header. For GET requests, the body is typically null or an empty object. For POST/PUT requests, it could be a JSON object, string, form data, etc. |
Return Value
Different types of return values can be given. Once a GET request is successfully done, the attributes can be shown by using console.log to see the return value. Make sure to remove this log once the return value is checked, as it is not a relevant log to keep inside a script.
Example: Making a GET Request
This example shows how to make a simple GET request to fetch data from an API endpoint using REST.call.
let response = REST.call('https://www.google.com', 'GET', {}, {});
if (response.headers) {
console.log('Data fetched successfully:', response);
} else {
console.log('Failed to fetch data. Status:', response);
}