Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
CNX18-RASA-contact-delete
<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 = "";
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 += '{';
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": "result: " + result});
} catch (e) {
e = Stringify(e).replace(/[\n\r]/g, '')
log.Rows.Add({"Message": "error: " + e});
}
</script>
@amrutha01

This comment has been minimized.

Copy link

amrutha01 commented Nov 19, 2019

I get error when running the above code in ssjs script automation activity.
Can any one help me

@wvpv

This comment has been minimized.

Copy link
Owner Author

wvpv commented Nov 19, 2019

If you have questions like this, I'd recommend asking them on https://salesforce.stackexchange.com. Please include all you've tried and the exact errors you are receiving.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.