Understanding SSJS Request Methods in Salesforce Marketing Cloud
In the world of server-side scripting, few methods are as crucial as the mighty request methods. As businesses increasingly rely on real-time data exchange and dynamic content delivery, understanding how to use this feature can enhance not only customer engagement but also operational efficiency. Whether you’re fetching data from an external API or processing user data to send to a third-party system, mastering the SSJS Request Method lays the groundwork for building robust, scalable applications within Salesforce Marketing Cloud.
What is SSJS?
Server-Side JavaScript (SSJS) is a scripting language used within Salesforce Marketing Cloud to enable complex business logic, API integrations, and seamless user interactions. Unlike client-side languages that run in the user’s browser, SSJS executes on the server, making it essential for secure data handling and processing. Having access to such a powerful scripting language opens up new ways to enhance your platform’s capabilities. Even in today’s world, where heavy segmentation is increasingly shifting to customer data platforms, I still believe that having SSJS at your disposal can open new doors and solve many business challenges—unlike platforms where such functionality doesn’t exist.
What is Request method?
In the context of Server-Side JavaScript (SSJS) in Salesforce Marketing Cloud (SFMC), request methods refer to the HTTP methods you use when sending or receiving data between systems.
More broadly, request methods are part of the HTTP protocol, which defines how data is exchanged between a client (like your SFMC server script) and an external server (like an API endpoint).
GET request methods in Salesforce Marketing Cloud
In Salesforce Marketing Cloud, GET methods are used to retrieve data from external systems or APIs. They don’t modify any data on the server – they simply request and return information.
To my surprise, I recently discovered that there are quite a few ways to execute a GET request in Salesforce Marketing Cloud. Let’s tackle them one by one.
HTTP.Get()
Performs an HTTP GET request with supplied URL and optional header name/value pairs. Works only on HTTP port 80 or HTTPS port 443.
Parameters:
- Destination URL – String (Required)
- Header names – Array
- Header values – Array
Returns a JSON object which contains:
- StatusCode – numeric
- Response – (body of the GET request)
Example
<script runat=server>
Platform.Load('Core','1');
var url = "https://api.example.com/data?id=123";
var hdrNames = ["Accept"];
var hdrValues = ["application/json"];
// without core library you call the same function Platform.Function.HTTPGet()
var result = HTTP.Get(url, hdrNames, hdrValues);
Write("Status: " + result.StatusCode);
Write("Body: " + result.Response);
</script>
Platform.Function.HTTPGet()
The main difference is that the Core library doesn’t need to be loaded, as shown in the example above. On top of that, it comes equipped with more options you can work with.
Properties
The HTTP Get function in Server-Side JavaScript (SSJS) accepts several parameters that define how the request behaves and how errors or responses are handled. Below is a summary of each one:
- URL (String, required) – The address to fetch content from.
- Continue on Error (Boolean, required) –
true: stop if an error occursfalse: continue even if there’s an error
- Empty Content Handling (Numeric) –
0: allow empty content1: return an error2: skip the subscriber
- Headers (Array, required) – Header names and values to include in the request.
- Response Codes (Array, required) – Captures HTTP response codes.
- Status Variable (String) – Stores the request’s status code.
Example
<script runat="server">
var status = [0];
try {
var content = Platform.Function.HTTPGet(
"https://api.example.com",
false,
0,
["x-request-id"],
["12345"],
status);
if(status[0] == 0) {
Platform.Response.Write(content);
};
} catch(e) {
Platform.Response.Write(Platform.Function.Stringify(e));
};
</script>
Script.Util.HttpGet()
For those who fancy good old object-oriented programming (OOP), Salesforce Marketing Cloud also offers the Script.Util.HttpGet() object.
It provides more control over your request – letting you set headers, define retry behavior, handle errors, and manage empty responses in a cleaner, structured way.
Based on the documentation, this method is recommended for use in email sends because it caches the content response from previous calls.
So if the same GET request (same URL and parameters) is made multiple times – for example, once per subscriber during an email send – the system will reuse the previously retrieved content instead of calling the external server again.
If this still isn’t ringing any bells, it basically means you can send your million morning emails faster than you would with any of the other GET request functions mentioned above.
I’ve just learnt it today! What I will do with this information? I will most probably forget it in a week, but I leave it for my future self, and you hopefully.
Properties
- continueOnError (Boolean) – Whether to continue execution if an error occurs.
- emptyContentHandling (Numeric) – Defines how to handle empty responses:
0: Allow empty content1: Return an error2: Skip subscriber
- retries (Numeric) – Number of retry attempts if the request fails.
- setHeader(name, value) – Adds a custom HTTP header to the request.
- send() – Executes the request and returns a response object.
Response
- statusCode – HTTP status code returned by the request (e.g., 200, 404).
- content – The response body as a string.
- errorCode – Error code, if the request failed.
- errorMessage – Description of the error, if any.
Example
<script runat="server">
Platform.Load("Core", "1");
// Define the API endpoint
var url = "https://api.example.com/data?id=123";
// Create a new HttpGet request
var request= new Script.Util.HttpGet(url);
// Optional configuration
request.setHeader("Accept", "application/json");
request.continueOnError = true; // Keep running even if an error occurs
request.emptyContentHandling = 0; // 0 = allow empty content
request.retries = 2; // Retry twice if request fails
// Send the request
var response= request.send();
if (response.statusCode == 200) {
/* Following lines are required to parse response successfully */
var responseString = String(response.content);
var responseJSON = Platform.Function.ParseJSON(responseString);
/* Output the response body */
Write(Stringify(responseJSON));
} else {
Write("Something went wrong");
}
</script>
Now with the get requests done we can move on to the POST requests.
POST request methods in Salesforce Marketing Cloud
POST methods in Salesforce Marketing Cloud are used to send data to an external system or API – for example, submitting form data, creating new records, or triggering workflows.
Unlike GET requests that only retrieve information, POST requests push data out and often include a request body (usually in JSON format).
You can perform POST requests using Platform.Function.HTTPPost(), HTTP.Post(), or the OOP-style Script.Util.HttpRequest() for more control.
HTTP.Post()
This method works similarly to the one above but is part of the Core library, so you must load it before using. It’s a good choice when your script already relies on the Core library for other operations.
This function only works with HTTP on port 80 and HTTPS on port 443.
Parameters
- destinationUrl (String) – Required. The destination URL for the HTTP POST request.
- contentType (String) – Required. The value to include in the
Content-Typeheader. - content (String) – Required. The body content of the POST request.
- headerNames (Array) – Required. An array of header names to include in the request.
- headerValues (Array) – Required. An array of header values corresponding to the header names.
<script runat="server">
Platform.Load('Core','1');
var url = "https://api.example.com/create";
var contentType = "application/json";
var payload = '{"name":"Jane","email":"jane@example.com"}';
var headerNames = ["Authorization"];
var headerValues = ["Bearer xyz123"];
var result = HTTP.Post(url, contentType, payload, headerNames, headerValues);
Write("Status Code: " + result.StatusCode + "<br>");
Write("Response: " + result.Response);
</script>
Platform.Function.HTTPPost()
This is the simplest way to send data using a POST request in Salesforce Marketing Cloud.
It doesn’t require loading the Core library, making it ideal for lightweight operations on CloudPages or email sends where you just need to send data quickly.
This function only works with HTTP on port 80 and HTTPS on port 443
Properties
- URL (String) – Required. The destination URL to which the data will be sent.
- Content Type (String) – Required. The value of the
Content-Typeheader to use in the request. - Payload (Object) – Required. The body content of the POST request.
- Header Names (Array) – Required. An array containing the names of the headers to include in the request.
- Header Values (Array) – Required. An array containing the values for each corresponding header name.
- Response Data (Array) – Required. An array that captures the response data returned from the POST request.
<script runat="server">
Platform.Load('Core','1');
// Define request parameters
var url = "https://api.example.com/submit";
var contentType = "application/json";
var payload = '{"name":"value"}';
var headerNames = ["header1", "header2"];
var headerValues = ["value1", "value2"];
// Initialize an array to capture the response
var response = [0];
try {
// Execute POST request
var statusCode = Platform.Function.HTTPPost(
url,
contentType,
payload,
headerNames,
headerValues,
response
);
// Check if request was successful
if (statusCode == 200) {
Write("Response: " + response[0]);
} else {
Write("Request failed. Status Code: " + statusCode);
}
} catch (e) {
// Handle unexpected errors
Write("Error: " + Stringify(e));
}
</script>
We’ve covered plenty of GET and POST request methods, but there are other HTTP verbs as well. And for those, you guessed it — there’s one ultimate function to rule them all
Script.Util.HttpRequest()
If you’ve ever wished for one function that can handle GET, POST, PUT, PATCH, or DELETE requests – this is it.
Script.Util.HttpRequest() is the most versatile HTTP handler in Server-Side JavaScript for Salesforce Marketing Cloud.
It’s an object-oriented class that gives you full control over the request:
you can define the method, headers, content type, body, retry logic, and error handling, all in one place.
It’s like a one-stop shop – you can impress, or confuse, your colleagues by using this single OOP-style function for all your http calls.
There’s just one limitation – it can only be used with ports 443 (HTTPS) or 80 (HTTP).
Properties
- method (String) – The HTTP method to use, such as
"GET","POST","PUT","PATCH", or"DELETE". - contentType (String) – The MIME type of the request body (e.g.,
"application/json"). - postData (String) – The request payload or body (used for POST, PUT, or PATCH).
- continueOnError (Boolean) – Whether to continue execution if an error occurs.
- emptyContentHandling (Numeric) – Controls how to handle empty responses:
0: Allow empty content1: Return an error2: Skip the subscriber
- retries (Numeric) – Number of retry attempts if the request fails.
- setHeader(name, value) – Adds a custom HTTP header to the request.
- send() – Executes the request and returns a response object.
Response Object
- statusCode – The HTTP response status code (e.g., 200, 404, 500).
- content – The body of the server’s response.
- errorCode – The error code, if one occurred.
- errorMessage -The corresponding error message.
Example
<script runat="server">
/* Load core beacause we do not want to write Platform.Function everytime :) */
Platform.Load('Core','1');
/* Create an authentication string to pass as a request header */
var token = "exapmle_token";
var auth = "Bearer " + token;
/* Specify the request body as a string */
var requestBody = '{name: x,email:me@example.com}';
try {
/* Initialize the request handler */
var request = new Script.Util.HttpRequest("https://www.api.example.com/put");
/* Set request headers */
request.setHeader("Authentication", auth);
request.setHeader("sample-header", "HeaderValue");
/* Configure the request properties */
request.method = "PUT";
request.encoding = "UTF-8";
request.postData = requestBody;
request.contentType = "application/json";
/* Send the request */
var response = request.send();
/* Necessary lines to process the response */
var responseString = String(response.content);
var responseJSON = ParseJSON(responseString );
/* Output the response body */
Write(Stringify(responseJSON));
} catch(e) {
Write(Stringify(e));
}
</script>
Sources
- https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/ssjs_httpGet.html
- https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/ssjs_httpPost.html
- https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/ssjs_platformContentSyndicationHTTPGet.html
- https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/ssjs_platformContentSyndicationHTTPPost.html
- https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/ssjs_platformContentSyndicationScriptUtilHttpGet.html
- https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/ssjs_platformContentSyndicationScriptUtilHttpRequest.html
- https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/ssjs_platformContentSyndicationScriptUtilHttpResponse.html








