httpRequest
Make an HTTP request to an external service.
This function is restricted. Use of this function in your script will require a manual review before it will execute on the Sentinel infrastructure.
Signatures
beacon.hmac(requestMethod, url, [headers], [body]);
Parameters
requestMethod
The HTTP method, such as GET
, POST
, HEAD
, OPTIONS
, PUT
, DELETE
, and more. The function is not limited to these listed methods.
url
The URL to request. Sentinel scrips support only https URLs.
headers
An object with header names for keys and the header value for values.
body
The data to send in the body of the request.
Return Values
Type | Notes |
---|---|
Object | An object containing the response details. success as boolean, body as string, status as number, and headers as object. |
Examples
Make a POST request to an API
const headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer notARealToken',
};
const body = JSON.stringify({
key: 'value',
});
const url = 'https://api.example.com/v1/pretendToDoThing';
const response = beacon.httpRequest('POST', url, headers, body);
if (response.success) {
beacon.debugPrint('It worked');
} else {
beacon.debugPrint('It did not work');
}