I am writing a Server Side activity in salesforce marketing cloud to communicate with an external web service to perform an action in a 3rd party platform. The call to the web service with the JSON payload executes successfully through postman - the web service call is recorded in a log file.
Here is a sample code which I have in the server side activity(based on marketing cloud documentation)
var payload = {};
payload.field_1 = "field_1";
payload.field_2 = "field_2";
payload.field_3 = "field_3";
payload.field_4 = "field_4";
var req = new Script.Util.HttpRequest(url);
req.emptyContentHandling = 0;
req.retries = 2;
req.continueOnError = true;
req.setHeader("Content-Type","application/json");
req.setHeader("authhash", "xxx");
req.method = "POST";
req.postData = Stringify(payload);
logMessage('Information', 'Call to post data', Stringify(payload));
var resp = req.send();
logMessage('Information', 'Call to post data', resp.returnStatus);
logMessage('Information', 'Call to post data', String(resp.content));
logMessage('Information', 'Call to post data', String(resp.statusCode));
The log message function is just a JS function to record the steps in a log data extension (It works fine)
Response return status recorded is 0 and status code is 0. There is no call recorded in the server log file which leads me to understand the call did not reach the server.
Any tips/help??
Regards Sid
url
defined, right? You might also look to use thereq.contentType
instead of creating the 'Content-Type' header viasetHeader
. Here are a couple links to my blog that may also help shine more light on these functions: (gortonington.com/restapimethodinssjs) and (gortonington.com/…)