Create a new Subscriber verified

Learn how to create (add) a new Subscriber in Salesforce Marketing Cloud (SFMC) with SSJS (server-side JavaScript). Code snippets include the WSProxy method.

WSProxy

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

var config = {
    SubscriberKey: GUID(),
    EmailAddress: "example@mail.com",
    Status: "Active",
    EmailTypePreference: "HTML",
    Attributes: [
        {
            Name: "FirstName",
            Value: "John"
        },
        {
            Name: "LastName",
            Value: "Doe"
        }
    ]
}

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

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

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

    try {

        var config = {
            SubscriberKey: GUID(),
            EmailAddress: "example@mail.com",
            Status: "Active",
            EmailTypePreference: "HTML",
            Attributes: [
                {
                    Name: "FirstName",
                    Value: "John"
                },
                {
                    Name: "LastName",
                    Value: "Doe"
                }
            ]
        }

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

        Write(Stringify(result));

    } catch (error) {

        Write(Stringify(error));

    }

</script>
{
    "Status": "OK",
    "RequestID": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
    "Results": [
        {
            "NewID": 12345678,
            "NewObjectID": null,
            "PartnerKey": null,
            "Object": {
                "SubscriberKey": "S0M3-GU1D-K3Y-G03SR1G4T-H3R3",
                "Client": null,
                "EmailAddress": "example@mail.com",
                "Status": "Active",
                "Lists": null,
                "Attributes": [
                    {
                        "Name": "FirstName",
                        "Value": "John",
                        "Compression": null
                    },
                    {
                        "Name": "LastName",
                        "Value": "Doe",
                        "Compression": null
                    }
                ],
                "UnsubscribedDate": "0001-01-01T00:00:00.000",
                "PartnerType": null,
                "EmailTypePreference": "HTML",
                "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
            },
            "CreateResults": null,
            "ParentPropertyName": null,
            "StatusCode": "OK",
            "StatusMessage": "Created Subscriber.",
            "OrdinalID": 0,
            "ErrorCode": 0,
            "RequestID": null,
            "ConversationID": null,
            "OverallStatusCode": null,
            "RequestType": "Synchronous",
            "ResultType": null,
            "ResultDetailXML": null
        }
    ]
}

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: