Salesforce Asked by Siddharth Kumar on January 14, 2021
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
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
Correct answer by Gortonington on January 14, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP