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.