Update a Subscriber verified

Learn how to update a Subscriber 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 attributes = {
    FirstName: "John",
    LastName: "Doe"
}

var result = lst.Subscribers.Upsert("example@mail.com", attributes);
<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 attributes = {
            FirstName: "Jane",
            LastName: "Doe"
        }

        var result = lst.Subscribers.Upsert("example@mail.com", attributes);

        Write(Stringify(result));

    } catch (error) {

        Write(Stringify(error));

    }

</script>
"OK"

WARNING

Upsert method adds a new Subscriber when not existing.

WSProxy

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

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

var options = {
    SaveOptions: [
        {
            PropertyName: '*',
            SaveAction: 'UpdateAdd'
        }
    ]
};

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

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

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

    try {

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

        var options = {
            SaveOptions: [
                {
                    PropertyName: '*',
                    SaveAction: 'UpdateAdd'
                }
            ]
        };

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

        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",
                "EmailAddress": "example@mail.com",
                "Lists": null,
                "Attributes": [
                    {
                        "Name": "FirstName",
                        "Value": "Jane",
                        "Compression": null
                    },
                    {
                        "Name": "LastName",
                        "Value": "Doe",
                        "Compression": null
                    }
                ],
                "UnsubscribedDate": "0001-01-01T00:00:00.000",
                "Status": "Active",
                "PartnerType": null,
                "EmailTypePreference": "Text",
                "GlobalUnsubscribeCategory": null,
                "SubscriberTypeDefinition": null,
                "Addresses": null,
                "PrimarySMSAddress": null,
                "PrimarySMSPublicationStatus": "OptedIn",
                "PrimaryEmailAddress": null,
                "Locale": null,
                "Client": 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
        }
    ]
}

WARNING

Status in the config object refers to the general subscriber's status in All Subscribers. In order to change the subscriber's status withing a given list, it must be added in the List object(s): Lists: [{ ID: "12345", Status: "Active" }]

Statuses

Here is the list of available statuses for the list subscribers:

  • Active
  • Bounced
  • Held
  • Unsubscribed
  • Deleted

Reference

Ressources and references related to the current methods.

Official documentation
SOAP object

Last Updated: