Unfortunately, there is not a way to use SSJS to automate deletion as requested, there is an alternative way to accomplish this so that that desired specific data gets deleted from All Contacts and such, as well as do it in a manner where you do not have to individually delete each one.
If you create a sendable Data Extension with only a Contact Key field, then import the data that needs to be deleted (only keeping the Contact Key), you can delete just the intended data by doing the following:
(from the Parent BU)
- Select the Contact Builder app (Audience Builder > Contact Builder)
- Select the All Contacts tab at the top
- Select All Contacts from the left sidebar
- Select the delete dropdown (trashcan symbol)
- Select Delete contacts from the data extension
From there, you can initiate the deletion process. Note that you can choose that same delete dropdown to View Pending Deletions to check the status of that deletion request.
Please note that this will remove all contacts that match the Contact Key listed on the created DE across all provisioned channels, so please make sure that only contacts intended to be removed in that manner are in the Data Extension.
Also please note the following, from the earlier attached documentation concerning Contact Deletion in Contact Builder:
This functionality includes a 14-day default period where Contact Builder suppresses contact information from showing in channel apps such as Email or MobileConnect. You can change the length of this time period in your account. The information remains in your account, but you cannot view contact records or access it to send activities. Once the period elapses, we delete contact information for deleted contacts from lists and sendable data extensions. This process does not apply to any non-sendable data extensions not included in a population via Data Designer, and you are responsible for deleting applicable information from those sources on your own.
- Deletion process initiated
- Suppression period - contact information remains in your account, but you cannot view or access it
- Final deletion - Marketing Cloud removes deleted contact information from your account
I do recommend you to follow best practices to delete contacts:
This can be achieved as well by REST API call:
As additional information, "All Contacts" refer to the contact within Mobile Connect. "All Subscribers" are subscribers within the All Subscribers list in Email Studio. The count for "All Contacts" in mobile connect does not count toward the "All Subscribers" list. However, if you send an email to a contact in "All Contact", that contact will be added to the "All Subscribers" list and therefore adding to the All Subscriber list count.
To have automated deletion for "All Contacts" considered for future deployment, you could go to the Idea Exchange page, and post an idea to have the ability to the custom setting within the Managed package. Our product team monitors these ideas, and the more votes they get, the higher priority they take for future upgrades on releases.
If you would like to do this, you can go to the Idea Exchange by following this link: