We want to invoke MC Campaign Creation API from SSJS. Campaign data to be created in MC we are fetching from external data source. While creating Campaign REST API Payload to invoke MC API from SSJS, we are using String concat() functions to create payload. However we are getting error "Bad Request" while creation of payload using contact().

how to create Payload if we use variable, for values in SSJS ?

Snippet :-

var mypayloadfir = '"description": "' ;
ar mypayloadsec = '","name": "';
var mypayloadth = '","campaignCode": "';
url = 'https://XXX/hub/v1/campaigns';
contentType = 'application/json';
Payload = '{' + mypayloadfir + sfdc_camp_desc +  mypayloadsec + sfdc_camp_name +mypayloadth + sfdc_camp_code + '"}';
var headerNames = ["Authorization"];
var headerValues = ['Bearer ' + accessToken];
Write(sfdc_camp_name + '<br>');
result = HTTP.Post(url, contentType, payload, headerNames, headerValues);
Write(sfdc_camp_name + '<br>');
  • It will help a lot, if you provided the SSJS in your question. It is impossible to help you with debugging a code one has never seen. Oct 1, 2020 at 7:47
  • sure , added code snippet. Oct 1, 2020 at 10:15
  • don’t put code in comments. Update your question with a code block Oct 1, 2020 at 10:16
  • yes, added in question. Oct 1, 2020 at 10:21
  • Could you also share how the generated payload looks like? I would advise to install a tool like Postman, so when you generate a payload in MC, you can test it manually outside of MC and see if it works and what tweaks need to be done to fix payload generation. Oct 1, 2020 at 12:22


You must log in to answer this question.

Browse other questions tagged .