REST.callV1 Function Reference
The scripting environment allows you to make external HTTP requests to interact with third-party APIs or services using the REST.callV1 function. This is an older version of the REST.call function. The core functionality is similar to REST.call.
It has two main differences:
- The body and header are optional. If no body is provided, it is deemed to be an empty object
- It returns a string value.
Syntax
REST.callV1(URL, method, headers, body);
Parameters
The REST.callV1 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 | No | An object containing key-value pairs for the request headers (e.g., { 'Content-Type': 'application/json', 'Authorization': 'Bearer ...' }). |
| body | Any | No | 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 of a script.
Example: Making a POST Request
This example shows how to make a POST request with a JSON body using REST.callV1.
let getData = {
// Add your data payload here for the POST request
"key1": "value1",
"key2": "value2"
};
let headers = {
'Content-Type': 'application/json'
};
let response = REST.callV1('https://www.google.com', 'POST', headers, getData); // Changed method to POST for this example
if (response.statusCode >= 200 && response.statusCode < 300) {
console.log('Item created successfully:', response.body);
} else {
console.log('Failed to create item. Status:', response.statusCode, 'Body:', response.body);
}