HTTP.GetRequest returns both the HTTP status code and the response body, unlike HTTP.Get which returns only the body.

Syntax

var statusCode = [0];
var body = HTTP.GetRequest(url, statusCode [, headerNames, headerValues]);

Parameters

Name Type Required Description
url string Yes Target URL
statusCode number[] Yes Single-element array — receives the HTTP status code
headerNames string[] No Additional header names
headerValues string[] No Corresponding header values

Return Value

Returns the response body as a string. The statusCode array’s first element is updated with the HTTP status code.

Examples

Platform.Load("core", "1.1.5");

var statusCode = [0];
var body = HTTP.GetRequest(
    "https://api.example.com/user/123",
    statusCode,
    ["Authorization"],
    ["Bearer " + accessToken]
);

if (statusCode[0] === 200) {
    var user = Platform.Function.ParseJSON(body + "");
    Write("Found: " + user.name);
} else if (statusCode[0] === 404) {
    Write("User not found.");
} else {
    Write("Error: " + statusCode[0]);
}

Notes

The statusCode parameter uses an array so it can be passed by reference — JavaScript does not support true pass-by-reference for primitives.

See Also