联系人删除Salesforce Marketing Cloud

时间:2019-05-12 21:42:28

标签: javascript salesforce-marketing-cloud

我正在尝试使用我编写的代码从Salesforce Marketing Cloud的“所有联系人”列表中删除联系人,并且在我请求令牌时,在第一个Http请求中收到Error-400。

我已经确认我的URL和ClientID和ClientSecret是正确的。

谢谢!

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

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

var DE = "E****************F";
var logDE = "1***************F";
var log = DataExtension.Init(logDE);

var url = 
'https://mc*****************.auth.marketingcloudapis.com/v1/requestToken';
 var contentType = 'application/json';

 var payload = "";
 payload += '{"clientId":"***********************",';
 payload += '"clientSecret":"********************"}';

 try {

   var accessTokenResult = HTTP.Post(url,contentType,payload);

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


 if(accessToken !=''){

 var statusCode = result["StatusCode"];
 var response = accessTokenResult["Response"][0];
 var accessToken = Platform.Function.ParseJSON(response).accessToken;

 url =         "https://mc******************.rest.marketingcloudapis.com/contacts";
 url += "/v1/contacts/actions/delete?type=listReference";

 var headerNames = ["Authorization"];
 var headerValues = ["Bearer " + accessToken];

 payload = "";
 payload += '{';
 payload += ' "deleteOperationType": "ContactAndAttributes",';
 payload += ' "targetList": {';
 payload += '   "listType": {';
 payload += '     "listTypeID": 3';
 payload += '   },';
 payload += '   "listKey": "' + DE  + '"';
 payload += ' },';
 payload += ' "deleteListWhenCompleted": false,';
 payload += ' "deleteListContentsWhenCompleted": true';
 payload += '}';

 try {

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

 } catch (e) {

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

 }

 </script>

0 个答案:

没有答案