0

Need a clarification in contact delete by lust reference.

We have a parent BU (business unit) at the top of the tree, and one of the other BUs is TEST. In TEST we have created an Installed Package and in that installed package we have added a Server-to-Server API Integration. Is this correct? In the Access tab of that API Integration we've enabled the integration for the Parent BU, and have enabled it for the TEST BU.

Which account id I need to Pass in the payload.. either the TEST BU account id or the parent BU account id?

Below is my script .. it doesn't delete any contact..My target DE is in TEST BU . it has a subscriber key as well.

<script runat="server">
Platform.Load("Core", "1");
var payload = '{"grant_type":"client_credentials",';
payload += '"client_id":"XXX",';
payload += '"client_secret":"XXX",';
payload += '"scope":null,';
payload += '"account_id":"XXXXXXXX"}';
var url = "https://XXXX.auth.marketingcloudapis.com/v2/Token";
var contentType = 'application/json'; /* perform HTTP Post request to get a new OAuth 2.0 access token */
var accessTokenResult = HTTP.Post(url, contentType, payload);
var tokenObj = Platform.Function.ParseJSON(accessTokenResult["Response"][0]);
var accessToken = tokenObj.access_token;
// Write("OAuth 2.0 Access Token: " + accessToken);
/* execute */
var endpoint = 'https://XXX.rest.marketingcloudapis.com/contacts/v1/contacts/actions/delete?type=listReference';
var headerNames1 = ["Authorization"];
var headerValues1 = ["Bearer " + accessToken];
var deKey = 'XXXXX';
var payload1 = '{';
payload1 += ' "deleteOperationType": "ContactAndAttributes",';
payload1 += ' "targetList": { ';
payload1 += ' "listType": { ';
payload1 += ' "listTypeID":3';
payload1 += ' },';
payload1 += ' "listKey": "' + deKey + '"';
payload1 += ' },';
payload1 += ' "deleteListWhenCompleted":false,';
payload1 += ' "deleteListContentsWhenCompleted":true';
payload1 += '}';
//Write("<br>today: " + payload1);
//Write("<br>accesstoken: " + accessToken);
var result = HTTP.Post(endpoint, contentType, payload1, headerNames1, headerValues1);
//Write("<br>Result: " + result);
</script>

Kindly suggest.

3
  • 1
    contact delete HAS to be done at the EID (top level) account, so your install package must be made there
    – EazyE
    Feb 24, 2022 at 18:46
  • 1
    To add to above, Contact Delete doesn’t delete just from „one target DE”, it deletes basically from every DE or list where it can find that particular contact - make sure that this is what you need, otherwise if you just need to delete from one target DE there might be other, better ways to do it
    – zuzannamj
    Feb 24, 2022 at 20:30
  • thanks @EazyE After creating the package at parent BU, the script worked.
    – DSK
    Feb 27, 2022 at 11:28

0

You must log in to answer this question.

Browse other questions tagged .