0

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

2
  • 1
    The status of 0 means the call was aborted, so the issue is definitely from your script somewhere. Dumb question, but you have url defined, right? You might also look to use the req.contentType instead of creating the 'Content-Type' header via setHeader. Here are a couple links to my blog that may also help shine more light on these functions: (gortonington.com/restapimethodinssjs) and (gortonington.com/…) Dec 1 '20 at 15:05
  • 1
    Hi @Gortonington - Thanks a lot. Moving the content type from the set header to the content type property solved the issue. Dec 1 '20 at 15:44
2

Moving from Comment to Answer

The status of 0 means the call was aborted, so the issue is definitely from your script somewhere.

I have had issues in the past setting the 'Content-Type' header via setHeader. I would recommend to instead use the req.contentType attribute.

In case you need any further assistance, here are a couple links to my blog that may also help shine more light on these functions: restapimethodinssjs and thirdpartyintegrations

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.