Retrieve all Subscribers from a List verified

Learn how to retrieve all Subscribers from a List in Salesforce Marketing Cloud (SFMC) with SSJS (server-side JavaScript). Code snippets include Core and WSProxy method.

Core

var customerKey = "S0M3-GU1D-K3Y-G03SR1G4T-H3R3";

var lst = List.Init(customerKey);

var result = lst.Subscribers.Retrieve(filter);
<script runat="server">

    Platform.Load("core", "1");

    try {

        var request = List.Retrieve({
            Property: "ListName",
            SimpleOperator: "equals",
            Value: "MyNewList"
        });

        var customerKey = request[0].CustomerKey;

        var lst = List.Init(customerKey);

        var result = lst.Subscribers.Retrieve(filter);

        Write(Stringify(result));

    } catch (error) {

        Write(Stringify(error));

    }

</script>
[
  {
    "ID": 123456789,
    "EmailAddress": "example@mail.com",
    "SubscriberKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
    "PartnerKey": null,
    "Status": "Active",
    "CreatedDate": "2020-04-21T08:30:00.000",
    "UnsubscribedDate": "0001-01-01T00:00:00.000",
    "EmailTypePreference": "HTML"
  },
  {
    "ID": 987654321,
    "EmailAddress": "example2@mail.com",
    "SubscriberKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
    "PartnerKey": null,
    "Status": "Active",
    "CreatedDate": "2020-04-21T08:30:00.000",
    "UnsubscribedDate": "0001-01-01T00:00:00.000",
    "EmailTypePreference": "HTML"
  }
]

WSProxy

var api = new Script.Util.WSProxy();

var cols = [
    "ObjectID",
    "SubscriberKey",
    "CreatedDate",
    "ModifiedDate",
    "Client.ID",
    "Client.PartnerClientKey",
    "ListID",
    "Status"
];

var filter = {
    Property: "ListID",
    SimpleOperator: "equals",
    Value: "123456"
};

var result = api.retrieve("ListSubscriber", cols, filter);
<script runat="server">

    Platform.Load("core", "1");

    var api = new Script.Util.WSProxy();

    try {

        var req1 = api.retrieve("List", ["ListName", "Category", "ID"], {
            Property: "ListName",
            SimpleOperator: "equals",
            Value: "MyNewList"
        });

        var id = req1.Results[0].ID;

        var cols = [
            "ObjectID",
            "SubscriberKey",
            "CreatedDate",
            "ModifiedDate",
            "Client.ID",
            "Client.PartnerClientKey",
            "ListID",
            "Status"
        ];

        var filter = {
            Property: "ListID",
            SimpleOperator: "equals",
            Value: id
        };

        var opts = {
            BatchSize: 300
        };

        var props = {
            QueryAllAccounts: false
        };

        var result = [],
            moreData = true,
            reqID = data = null;

        while(moreData) {

            moreData = false;

            if(reqID) props.ContinueRequest = reqID;

            var req2 = api.retrieve("ListSubscriber", cols, filter, opts, props);

            if (req2) {

                moreData = req2.HasMoreRows;
                reqID = req2.RequestID;

                var results = req2.Results;

                for (var k in results) {
                    var subscriber = results[k];
                    result.push(subscriber);
                }

            }
        }

        Write(Stringify(result));

    } catch (error) {

        Write(Stringify(error));

    }

</script>
[
    {
        "SubscriberKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
        "Client": {
            "ID": 100000000000,
            "ClientID1": 0,
            "PartnerClientKey": null,
            "UserID": 0,
            "PartnerUserKey": null,
            "CreatedBy": 0,
            "ModifiedBy": 0,
            "EnterpriseID": 0,
            "CustomerKey": null,
            "CustomerID": null
        },
        "ListID": 12345678,
        "Status": "Active",
        "CreatedDate": "2022-11-16T06:01:00.000",
        "PartnerKey": null,
        "PartnerProperties": null,
        "ModifiedDate": "2022-11-16T06:01:00.000",
        "ID": 0,
        "ObjectID": "12345678",
        "CustomerKey": null,
        "Owner": null,
        "CorrelationID": null,
        "ObjectState": null,
        "IsPlatformObject": false
    }
]

Reference

Ressources and references related to the current methods.

Official documentation
SOAP object

Last Updated: