with the GDPR laws in place, it's important to have the possibility to remove contacts from Marketing Cloud. I'm trying to automate the process with existing tools and am looking for possible solutions.

Right now I'm trying to use the Remove() function from the Subscriber Object in the Core SSJ library:

<script runat="server">


    var subObj = Subscriber.Init("000-T-01-API-Delete");

    var status = subObj.Remove();


The contact was created manually in Mobile Connect and exists in All Contacts. Although the query completes without errors, the contact remains in the system.

Any idea how to fix the script to perform the deletion?

I am thinking this might not be the best approach since it would be a 1 by 1 deletion of contacts performed in a loop, but I don't see an option like the API allows to tell the system to delete contacts stored in a data extension.

Any advice or ideas how to automate this process would be greatly appreciated.


Please see the example of how I use this for bulk deletion. You should use the REST API, using the DeleteByListReference endpoint. Here it works together with a sendable DE, and SSJS activity in Automation Studio:

<script runat=server>
Platform.Load("Core", "1");

var url = 'https://auth.exacttargetapis.com/v1/requestToken'; 
var contentType = 'application/json'; 
var payload = '{"clientId": "","clientSecret": ""}'; //Update with correct credentials

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

if(accessToken !='')

var url1 = 'https://www.exacttargetapis.com/contacts/v1/contacts/actions/delete?type=listReference';
var contentType1 = 'application/json';
var payload1 = '{"deleteOperationType": "ContactAndAttributes","targetList": {"listType": {"listTypeID": 3},"listKey": "99E99999-2E8B-4D2C-AF6C-F84DD64C04B0"},"deleteListWhenCompleted": false,"deleteListContentsWhenCompleted": false}'; //replace with external key of the sendable data extension containing contacts to delete
var headerNames = ["Authorization"]; 
var s1="Bearer ";
var headerValues = s1.concat(accessToken); 
var result = HTTP.Post(url1, contentType1, payload1, headerNames, [headerValues], content);

Remember to have the Data Extension created as sendable, and the only column required is the Subscriber Key. Also do ensure that Contact Deletion is enabled on your account. Here is how you do it.

This code has been developed before the introduction of Tenant-Specific Subdomains for APIs. I will suggest adjusting it accordingly.

  • 2
    Lukas, I'm extremely grateful for this answer. It's really a great piece of code for someone like me that's just learning to use the API and scripts in Automation Studio. With proper deletion settings (suppression period set to 0) the contact is already gone from the system :) Thank you so much! – Rafał Wolsztyniak Jan 8 '19 at 13:46
  • 3
    Please find here a more detailed code with error handling by @adamspriggs gist.github.com/wvpv/… – zeljazouli Jan 8 '19 at 14:54
  • @zeljazouli, thank you for that link. The code looks great. – Rafał Wolsztyniak Jan 9 '19 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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