Skip to content

Instantly share code, notes, and snippets.

@jdeblank
Last active January 22, 2023 01:03
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jdeblank/985d45db07c28679d84a612334ed9e7f to your computer and use it in GitHub Desktop.
Save jdeblank/985d45db07c28679d84a612334ed9e7f to your computer and use it in GitHub Desktop.
Use SSJS and WSProxy to add/update a subscriber status in Publication List within Salesforce Marketing Cloud
<script runat="server">
Platform.Load("core","1.1.1");
var subkey = "abc123";
var email = "foo@bar.com"
var prox = new Script.Util.WSProxy();
// Set specific BU context if required
// prox.setClientId({ "ID": 7279411 });
var sub = {
SubscriberKey: subkey,
EmailAddress: email,
Lists: [{
ID: '12345',
Status: 'Active'
}]
};
var options = {
SaveOptions: [{
PropertyName: "*",
SaveAction: "UpdateAdd"
}]
};
var resp = prox.createItem("Subscriber", sub, options);
Write("Response: " + Stringify(resp));
</script>
@Dvanderlaan
Copy link

Dvanderlaan commented Jun 19, 2020

Awesome clean code. This works perfectly with a publication list update when the Allsubscriber list status is already Active. To resubscribe a customer that has an Unsubscribed on the All Subscriberlist you could add the the Active Status to the sub:

var sub = { SubscriberKey: subkey, EmailAddress: email, Status: 'Active', Lists: [{ ID: '12345', Status: 'Active' }] };

@jdeblank
Copy link
Author

Thanks @Dvanderlaan , I appreciate the kind feedback. It looks like you were able to answer your own question 😄
I have moved most of these gists and have some more examples here: https://github.com/jdeblank/sfmc_dev/tree/master/wsproxy

@Bizzare81
Copy link

Can this code be used in add/update/unsubscribe subscriber to multiple publication lists at once?

@Sohail-publicis
Copy link

Hey Everone, How do I achieve same task using the DE. So I have DE where I have emailaddress and subscriberkey field. So I want the script read every record from DE and then certainly add to particular list? Is that possible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment