Platform.Request provides methods to inspect every aspect of the incoming HTTP request in CloudPage, JSON Resource, and Triggered Send contexts.

Properties

Property Type Description
Platform.Request.Browser object Browser metadata: Platform, Browser, Version, MajorVersion, MinorVersion
Platform.Request.ClientIP string IP address of the requesting client
Platform.Request.HasSSL boolean Whether the current request supports SSL (HTTPS)
Platform.Request.IsSSL boolean Whether the current request used an SSL (HTTPS) connection
Platform.Request.Method string HTTP method: "GET" or "POST"
Platform.Request.QueryString string Full raw query string of the request URL
Platform.Request.ReferrerURL string URL of the referring web address
Platform.Request.RequestURL string Full resolved URL of the current page
Platform.Request.UserAgent string User-agent string of the requesting browser

All properties return null (or false for boolean properties) when no valid request object exists or the value is absent.

Methods

Method Returns Description
GetCookieValue(name) string Read a cookie value
GetFormField(name) string Read a form field (POST or GET)
GetPostData([encoding]) string Read raw POST body (optional character encoding)
GetQueryStringParameter(name) string Read a URL query parameter
GetRequestHeader(name) string Read a request header
GetUserLanguages() string Read the browser Accept-Language header value

Method: GetQueryStringParameter

Platform.Request.GetQueryStringParameter(parameterName)

Returns the value of a URL query string parameter. Returns "" if not present.

Parameters

Name Type Required Description
parameterName string Yes Query parameter name

Examples

// URL: /page?id=42&mode=preview
var id = Platform.Request.GetQueryStringParameter("id");     // "42"
var mode = Platform.Request.GetQueryStringParameter("mode"); // "preview"
var missing = Platform.Request.GetQueryStringParameter("foo"); // ""

Method: GetFormField

Platform.Request.GetFormField(fieldName)

Reads a field from either a GET query string or POST form body (application/x-www-form-urlencoded or multipart/form-data).

Examples

var email = Platform.Request.GetFormField("email");
var firstName = Platform.Request.GetFormField("firstName");

Method: GetPostData

Platform.Request.GetPostData([encoding])

Returns the raw POST body as a string. Typically used for JSON or XML payloads sent with content-type application/json.

When encoding is omitted, the platform default applies (often a legacy Windows code page). Pass an encoding name such as "UTF-8" when the client sends UTF-8.

Examples

// CORRECT — read once, reuse the variable
var rawBody = Platform.Request.GetPostData();
var payload = Platform.Function.ParseJSON(rawBody + "");

// WRONG — second call returns ""
var a = Platform.Request.GetPostData();
var b = Platform.Request.GetPostData(); // b === ""

Checking Request Method First

if (Platform.Request.Method === "POST") {
    var rawBody = Platform.Request.GetPostData();
    if (rawBody) {
        var data = Platform.Function.ParseJSON(rawBody + "");
        // process data
    }
}

Method: GetUserLanguages

Platform.Request.GetUserLanguages()

Returns the raw value of the HTTP Accept-Language header (for example a comma-separated list with quality values). Returns null when the header is absent.

Examples

var langs = Platform.Request.GetUserLanguages();
if (langs) {
    Write("<!-- Accept-Language: " + langs + " -->");
}

Method: GetRequestHeader

Platform.Request.GetRequestHeader(headerName)

Returns the value of an HTTP request header. Header names are case-insensitive.

Examples

var contentType = Platform.Request.GetRequestHeader("Content-Type");
var authHeader = Platform.Request.GetRequestHeader("Authorization");
var customToken = Platform.Request.GetRequestHeader("X-API-Token");

// Token authentication pattern
var token = Platform.Request.GetRequestHeader("X-Auth-Token");
var expectedToken = Platform.Function.Lookup("Config", "value", "key", "apiToken");
if (token !== expectedToken) {
    Write(Stringify({ status: 401, statusMessage: "Unauthorized", error: "Unauthorized" }));
    return;
}

Method: GetCookieValue

Platform.Request.GetCookieValue(cookieName)

Returns the value of a cookie sent with the request.

Examples

var sessionId = Platform.Request.GetCookieValue("sfmc_session");
if (!sessionId) {
    // No session — redirect to login
    Platform.Response.Redirect("/login", false);
}

Property: RequestURL

Platform.Request.RequestURL

Returns the full URL of the current CloudPage as it was resolved, including CloudPages URL encryption parameters.

Examples

var currentUrl = Platform.Request.RequestURL;

Property: Browser

Platform.Request.Browser

Returns an object describing the requesting client’s browser with the following fields: Platform, Browser, Version, MajorVersion, MinorVersion.

Examples

var browser = Platform.Request.Browser;
Write(Stringify(browser));
// { "Platform": "WinNT", "Browser": "Chrome", "Version": "124.0", "MajorVersion": 124, "MinorVersion": 0 }

Property: ClientIP

Platform.Request.ClientIP

Returns the IP address of the requesting client as a string.

Examples

var ip = Platform.Request.ClientIP;
Write("Request from: " + ip);

Property: HasSSL

Platform.Request.HasSSL

Returns true if the current request supports SSL (HTTPS), false otherwise.

Examples

if (!Platform.Request.HasSSL) {
    Platform.Response.Redirect("https://" + Platform.Request.RequestURL, false);
}

Property: IsSSL

Platform.Request.IsSSL

Returns true if the current request was made over an SSL (HTTPS) connection. Alias of HasSSL.


Property: QueryString

Platform.Request.QueryString

Returns the full raw query string of the request URL (everything after ?). Use GetQueryStringParameter(name) to read individual values.

Examples

var qs = Platform.Request.QueryString;
// e.g. "id=42&mode=preview"

Property: ReferrerURL

Platform.Request.ReferrerURL

Returns the URL of the referring web address (the HTTP Referer header value). Returns null when no referrer is present.

Examples

var referrer = Platform.Request.ReferrerURL;
if (referrer) {
    Write("<!-- Referred from: " + referrer + " -->");
}

Property: UserAgent

Platform.Request.UserAgent

Returns the user-agent string from the HTTP request. Use with Platform.Function.IsCHTMLBrowser() to detect browser types.

Examples

var ua = Platform.Request.UserAgent;
var isCHTML = Platform.Function.IsCHTMLBrowser(ua);

Complete Request Handler Pattern

var method = Platform.Request.Method;

if (method === "GET") {
    var id = Platform.Request.GetQueryStringParameter("id");
    if (!id) {
        Write(Stringify({ status: 400, statusMessage: "Bad Request", error: "id is required" }));
    } else {
        var record = Platform.Function.Lookup("Records", "data", "id", id);
        Platform.Response.ContentType = "application/json";
        Write(Stringify({ id: id, data: record }));
    }
} else if (method === "POST") {
    var rawBody = Platform.Request.GetPostData();
    try {
        var body = Platform.Function.ParseJSON(rawBody + "");
        // process body...
        Platform.Response.ContentType = "application/json";
        Write(Stringify({ status: "ok" }));
    } catch(e) {
        Write(Stringify({ status: 400, statusMessage: "Bad Request", error: "Invalid JSON" }));
    }
}

See Also