3

We are trying to update a service cloud custom object from marketing cloud. Can we make a REST api call within a script in Automation Studio.It will be great if someone in this forum can confirm they have already done it.

  • Why use the REST API, when there are AMPscript functions for updating SF objects from SFMC? – Adam Spriggs Jul 8 '18 at 11:18
  • Hi Adam,Thanks. We do not want to use cloud page ,We are trying to do this as a scheduled activity through Automation .Can we achieve that through AMPscript functions ? – Monomit Bhowmik Jul 8 '18 at 16:02
  • I'm not referring to CloudPages. You include content areas or blocks that contain AMPscript with using SSJS . See the SSJS Content Functions for details. – Adam Spriggs Jul 8 '18 at 19:40
7

I've done a REST API call from a Script Activity. Here's an example:

<script type="javascript" runat="server">

Platform.Load("core","1.1.5");

var DE = "Contacts_To_Delete";
var logDE = "Contacts_To_Delete_Log";
var log = DataExtension.Init(logDE);

var url = 'https://auth.exacttargetapis.com/v1/requestToken';
var contentType = 'application/json';
var  payload = '{"clientId":"CLIENT_ID_GOES_HERE",';
payload += '"clientSecret":"CLIENT_SECRET_GOES_HERE"}';

var accessTokenResult = HTTP.Post(url, contentType, payload);
var statusCode = result["StatusCode"];
var response = accessTokenResult["Response"][0];
var accessToken = Platform.Function.ParseJSON(response).accessToken;

url = "https://www.exacttargetapis.com/contacts";
url += "/v1/contacts/actions/delete?type=listReference";
var headerNames = ["Authorization"];
var headerValues = ["Bearer " + accessToken];
payload = '{';
payload += ' "deleteOperationType": "ContactAndAttributes",';
payload += ' "targetList": {';
payload += '   "listType": {';
payload += '     "listTypeID": 3';
payload += '   },';
payload += '   "listKey": "' + DE  + '"';
payload += ' },';
payload += ' "deleteListWhenCompleted": false,';
payload += ' "deleteListContentsWhenCompleted": true';
payload += '}';

try {

  var result = HTTP.Post(url, contentType, payload, headerNames, headerValues);
  result = Stringify(result).replace(/[\n\r]/g, '');
  log.Rows.Add({"Message": "result: " + result});

} catch (e) {

  e = Stringify(e).replace(/[\n\r]/g, '')
  log.Rows.Add({"Message": "error: " + e});

}

</script>

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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