Platform.Response lets you control the HTTP response sent back to the browser. Useful for REST-style CloudPage APIs, redirects, cookie management, and setting response headers and content type.

Does not require Platform.Load.

Methods

Method Returns Description
Platform.Response.Write(content) void Write content to the HTTP response output
Platform.Response.SetResponseHeader(headerName, value) void Set a response header
Platform.Response.RemoveResponseHeader(headerName) void Remove a response header
Platform.Response.SetCookie(name, value [, expires [, secure]]) void Set a response cookie
Platform.Response.RemoveCookie(name) void Remove a cookie
Platform.Response.Redirect(url, movedPermanently) void Redirect the browser

Properties

Property Type Description
Platform.Response.ContentType string Gets or sets the Content-Type of the HTTP response
Platform.Response.CharacterSet string Gets or sets the character set of the HTTP response

Property: ContentType

Platform.Response.ContentType = "application/json";

Gets or sets the Content-Type header of the HTTP response. Set this before writing any output.

Examples

Platform.Response.ContentType = "application/json";
Platform.Response.Write(Stringify({ status: "ok", id: newId }));
Platform.Response.ContentType = "text/plain";
Platform.Response.Write("plain text response");

Property: CharacterSet

Platform.Response.CharacterSet = "UTF-8";

Gets or sets the character set of the HTTP response.

Examples

Platform.Response.ContentType = "application/json";
Platform.Response.CharacterSet = "UTF-8";
Platform.Response.Write(Stringify(data));

Method: Write

Platform.Response.Write(content)

Writes a string directly to the HTTP response output. Does not require Platform.Load.

This is distinct from the global Write() function. The global Write() requires Platform.Load("core", "1.1.5") and writes to the rendered page output. Platform.Response.Write() does not require Core and writes to the HTTP response body — use it in scripts where Core is not loaded.

Parameters

Name Type Required Description
content string Yes String to write to the response

Examples

// JSON API endpoint — no Platform.Load required
Platform.Response.ContentType = "application/json";
Platform.Response.Write(Stringify({ status: "ok" }));
// With Core loaded, either Write() or Platform.Response.Write() works
Platform.Load("core", "1.1.5");
var rows = DataExtension.Init("MyDE").Rows.Retrieve();
Platform.Response.Write(Stringify(rows));

Method: SetResponseHeader

Platform.Response.SetResponseHeader(headerName, value)

Sets a header on the HTTP response.

Parameters

Name Type Required Description
headerName string Yes Name of the response header
value string Yes Value for the response header

Examples

Platform.Response.SetResponseHeader("Content-Type", "application/json");
Platform.Response.Write(Stringify({ status: "ok" }));
// Security headers
Platform.Response.SetResponseHeader("X-Content-Type-Options", "nosniff");
Platform.Response.SetResponseHeader("X-Frame-Options", "DENY");

Method: RemoveResponseHeader

Platform.Response.RemoveResponseHeader(headerName)

Removes a previously set HTTP response header.

Parameters

Name Type Required Description
headerName string Yes Name of the response header to remove

Examples

Platform.Response.RemoveResponseHeader("X-Powered-By");

Method: SetCookie

Platform.Response.SetCookie(name, value [, expires [, secure]])

Sets a cookie in the response.

Parameters

Name Type Required Description
name string Yes Cookie name
value string Yes Cookie value
expires string No Expiration datetime string
secure boolean No Send only over HTTPS

Examples

// Session cookie (expires when browser closes)
Platform.Response.SetCookie("sessionToken", token);

function dateAdd(timestamp,intervalToAdd,intervalType) {
    Platform.Variable.SetValue("@dateAdd_ts",timestamp);
    Platform.Variable.SetValue("@dateAdd_add",intervalToAdd);
    Platform.Variable.SetValue("@dateAdd_type",intervalType);
    return Platform.Function.TreatAsContent("%%=DateAdd(@dateAdd_ts, @dateAdd_add, @dateAdd_type)=%%");
}

// Persistent cookie with expiry
function formatDate(dateString,dateFormat,timeFormat,isoLocale) {
    Platform.Variable.SetValue("@formatDate_string",dateString);
    Platform.Variable.SetValue("@formatDate_date",dateFormat);
    Platform.Variable.SetValue("@formatDate_time",timeFormat);
    Platform.Variable.SetValue("@formatDate_iso",isoLocale);
    return Platform.Function.TreatAsContent("%%=FormatDate(@formatDate_string, @formatDate_date, @formatDate_time, @formatDate_iso)=%%");
}
var expiry = formatDate(
    dateAdd(Now(), 30, "D"),
    "ddd, DD MMM YYYY HH:mm:ss",
    "en-US"
) + " GMT";
Platform.Response.SetCookie("rememberMe", userId, expiry, true);

// Clear a cookie (set expired date)
Platform.Response.SetCookie("sessionToken", "", "Thu, 01 Jan 1970 00:00:00 GMT");

Method: RemoveCookie

Platform.Response.RemoveCookie(name)

Removes a cookie from the client browser by setting its expiration to a past date.

Parameters

Name Type Required Description
name string Yes Name of the cookie to remove

Examples

Platform.Response.RemoveCookie("sessionToken");

Method: Redirect

Platform.Response.Redirect(url , movedPermanently)

Redirects the browser to the specified URL.

Parameters

Name Type Required Description
url string Yes Destination URL
movedPermanently boolean Yes true for 301 redirect, false/omitted for 302

Examples

// Temporary redirect (302)
Platform.Response.Redirect("https://example.com/thank-you", false);

// Permanent redirect (301)
Platform.Response.Redirect("https://new-domain.com/page", true);

// Conditional redirect
var isLoggedIn = !!Platform.Request.GetCookieValue("session");
if (!isLoggedIn) {
    Platform.Response.Redirect("/login?next=" +
        Platform.Function.UrlEncode(Platform.Request.RequestURL), false);
}

See Also