Remove a Subscriber from a List verified

Learn how to remove (unsubscribe) a Subscriber from a List in Salesforce Marketing Cloud (SFMC) with SSJS (server-side JavaScript). Code snippets include Core and WSProxy methods.

Core

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

var lst = List.Init(customerKey);

var result = lst.Subscribers.Unsubscribe("example@mail.com");
<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.Unsubscribe("example@mail.com");

        Write(Stringify(result));

    } catch (error) {

        Write(Stringify(error));

    }

</script>
"OK"

WSProxy

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

var config = {
    SubscriberKey: "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
    EmailAddress: "example@mail.com",
    Lists: [
        {
            ID: "12345",
            Action: "delete"
        }
    ]
};

var result = api.updateItem("Subscriber", config);
<script runat="server">

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

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

    try {

        var request = api.retrieve("List", ["ListName", "ID"], {
            Property: "ListName",
            SimpleOperator: "equals",
            Value: "All Subscribers"
        });

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

        var config = {
            SubscriberKey: "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
            EmailAddress: "example@mail.com",
            Lists: [
                {
                    ID: id,
                    Action: "delete"
                }
            ]
        };

        var result = api.updateItem("Subscriber", config);

        Write(Stringify(result));

    } catch (error) {

        Write(Stringify(error));

    }

</script>
{
    "Status": "OK",
    "RequestID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
    "Results": [
        {
            "Object": {
                "SubscriberKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
                "Client": null,
                "EmailAddress": "example@mail.com",
                "Status": "Active",
                "Lists": [
                    {
                        "Status": "Active",
                        "ID": 123456,
                        "Action": "delete",
                        "List": null,
                        "Client": null,
                        "Subscriber": null,
                        "PartnerKey": null,
                        "PartnerProperties": null,
                        "CreatedDate": "0001-01-01T00:00:00.000",
                        "ModifiedDate": null,
                        "ObjectID": null,
                        "CustomerKey": null,
                        "Owner": null,
                        "CorrelationID": null,
                        "ObjectState": null,
                        "IsPlatformObject": false
                    }
                ],
                "Attributes": null,
                "UnsubscribedDate": "0001-01-01T00:00:00.000",
                "PartnerType": null,
                "EmailTypePreference": "Text",
                "GlobalUnsubscribeCategory": null,
                "SubscriberTypeDefinition": null,
                "Addresses": null,
                "PrimarySMSAddress": null,
                "PrimarySMSPublicationStatus": "OptedIn",
                "PrimaryEmailAddress": null,
                "Locale": null,
                "PartnerKey": null,
                "PartnerProperties": null,
                "CreatedDate": "0001-01-01T00:00:00.000",
                "ModifiedDate": null,
                "ID": 12345678,
                "ObjectID": null,
                "CustomerKey": null,
                "Owner": null,
                "CorrelationID": null,
                "ObjectState": null,
                "IsPlatformObject": false
            },
            "UpdateResults": null,
            "ParentPropertyName": null,
            "StatusCode": "OK",
            "StatusMessage": "Updated Subscriber.",
            "OrdinalID": 0,
            "ErrorCode": 0,
            "RequestID": null,
            "ConversationID": null,
            "OverallStatusCode": null,
            "RequestType": "Synchronous",
            "ResultType": null,
            "ResultDetailXML": null
        }
    ]
}

Reference

Ressources and references related to the current methods.

SOAP object

Last Updated: