I need to pull a comprehensive unsub list and automate this process daily, and unfortunately the data view _Subscribers only goes back 6 months so a query is out. The best solution I have found to accomplish this is through an API call to the Subscriber Object.

I built this using SSJS and a do/while with ContinueRequest to go beyond the 2500 limit, but after around 8500 records it errors and I have no idea why. The error message, as usual, is completely useless and just comes back with "An error has occurred".

Could this be a time-out issue? We are looking at around 88,000 unsub records that will be pulled with probably around 1mil or more total records in this MID.

Below is a sample of my SSJS API call:

<script runat="server">

    var rr = Platform.Function.CreateObject("RetrieveRequest");
    Platform.Function.SetObjectProperty(rr, "ObjectType", "Subscriber");

    Platform.Function.AddObjectArrayItem(rr, "Properties", "SubscriberKey");
    Platform.Function.AddObjectArrayItem(rr, "Properties", "Status");
    Platform.Function.AddObjectArrayItem(rr, "Properties", "UnsubscribedDate");

    var sfp = Platform.Function.CreateObject("SimpleFilterPart");
    Platform.Function.SetObjectProperty(sfp, "Property", "Status");
    Platform.Function.SetObjectProperty(sfp, "SimpleOperator", "equals");
    Platform.Function.AddObjectArrayItem(sfp, "Value", "Unsubscribed");

    Platform.Function.SetObjectProperty(rr, "Filter", sfp);

    do { 
        var results = [0,0];
        var rows = Platform.Function.InvokeRetrieve(rr, results);

        var runstatus = results[0];
        var requestId = results[1];

        if (rows != null) {

            for (var i in rows) {
                var subkey = rows[i].SubscriberKey;
                var status = rows[i].Status;
                var unsubdate = rows[i].UnsubscribedDate;

                Platform.Variable.SetValue("@status", status);


            <script runat="server" language="ampscript">

               UpsertDE("MYDataExtension", 1, "EmailAddress", @subkey, "Status", @status, "UnsubscribedDate", @unsubdate)


            <script runat="server">    
        rr.ContinueRequest = requestId;

    } while (runstatus == "MoreDataAvailable")


Got the answer from SFMC support - apparently some of my Subscribers have the status of Unsubscribed, but have a null value inside of the UnsubscribedDate field, which is not an acceptable input inside of an UPSERT to a date/time field. So by changing the date/time field to a text field, it went through without issue.

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.