HTTP.PostRequest
Core library HTTP POST with status code — sends a POST request and captures both the HTTP response code and body.
HTTP.PostRequest sends a POST request and returns both the HTTP status code and the response body.
Requires Platform.Load("core", "1.1.5") before use.
Syntax
var statusCode = [0];
var body = HTTP.PostRequest(url, contentType, payload, statusCode [, headerNames, headerValues]);
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
url |
string | Yes | Target URL |
contentType |
string | Yes | MIME type of the request body |
payload |
string | Yes | Request body string |
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. Updates statusCode[0] with the HTTP status.
Examples
Platform.Load("core", "1.1.5");
var payload = Stringify({ action: "subscribe", email: email });
var statusCode = [0];
var response = HTTP.PostRequest(
"https://api.example.com/preferences",
"application/json",
payload,
statusCode,
["Authorization"],
["Bearer " + accessToken]
);
if (statusCode[0] >= 200 && statusCode[0] < 300) {
var result = Platform.Function.ParseJSON(response + "");
Write(Stringify({ status: "ok", id: result.id }));
} else {
Platform.Response.SetResponseCode(statusCode[0], "Upstream Error");
Write(Stringify({ error: "Upstream returned " + statusCode[0] }));
}