Syntax

new Script.Util.HttpGet(url)
1 argument

Script.Util.HttpGet creates an HTTP GET request handler. Unlike Platform.Function.HTTPGet, it caches content for use in mail sends and supports custom headers via setHeader(). Only works with HTTP on port 80 and HTTPS on port 443.

For full control over HTTP method, timeouts, and all status codes, use Script.Util.HttpRequest instead.

Parameters

Name Type Required Description
url string Yes Target URL (HTTP port 80 or HTTPS port 443 only)

Return Value

Returns an HttpGetInstance. Call send() to execute the request.

HttpGetInstance Properties

Property Type Default Description
retries number 1 Number of retry attempts on failure
continueOnError boolean false If true, does not throw on HTTP error status
emptyContentHandling number 0 Indicates what to do if the GET request doesn’t return any content. 0 = continue, 1 = stop the request, 2 = continue to the next subscriber (only works in email sends)

HttpGetInstance Methods

Method Returns Description
clearHeaders() void Remove all custom headers
removeHeader(name) void Remove a specific header by name
send() HttpResponseInstance Send the request
setHeader(name, value) void Set a custom request header

HttpResponseInstance Object

HttpResponseInstance is equal for HttpGet and HttpRequest.

The resp object returned by req.send() has these properties:

Property Type Description
content CLR string Response body (must use String() to convert)
contentType string The content type returned in the response
encoding string The encoding type returned in the response
headers object Response headers
returnStatus number A status value: 0 = OK, 1 = Empty URL, 2 = Call failed, 3 = Call succeeded with empty content
statusCode number HTTP status code

Examples

Basic GET request

var req = new Script.Util.HttpGet("https://api.example.com/data");
var resp = req.send();
if (resp.statusCode == 200) {
    var result = Platform.Function.ParseJSON(String(resp.content));
    Write(Stringify(result));
}

GET with auth header

var req = new Script.Util.HttpGet("https://api.example.com/items");
req.setHeader("Authorization", "Bearer " + accessToken);
req.retries = 2;
req.continueOnError = true;
var resp = req.send();
if (resp.statusCode == 200) {
    var items = Platform.Function.ParseJSON(String(resp.content));
    for (var i = 0; i < items.length; i++) {
        Write(items[i].name + "<br>");
    }
}

Notes

  • Only works with HTTP on port 80 and HTTPS on port 443. Other ports require Script.Util.HttpRequest.
  • Caches the response content for use in mail send personalisation — unless setHeader() is called (which disables caching).
  • Does not require Platform.Load.

See Also