1

I noticed that you can unsubscribe a user through SSJS, is it possible to use SSJS to change the unsubscribe reason?

I notice that doing it through the API seems to be popular? why is that?

Thanks

3 Answers 3

2

You can easily do this using WSPRoxy:

  /* Declare WSProxy */
  var prox = new Script.Util.WSProxy();

  var props = [
    {Name:"SubscriberKey", Value:SubscriberKey},
    {Name:"JobID", Value:JobID},
    {Name:"ListID", Value:Listid},
    {Name:"BatchID", Value:BatchID},
    {Name:"Reason", Value:"Consent Centre Unsubscribe"},
  ];
  var data = prox.execute(props, "LogUnsubEvent");
1
  • Thanks. Since I'm relatively new to SSJS in Marketing Cloud, how should I adjust the code? Taking into account the use-case, do I need to replace just the Listid with the actual value and then run in as Script Activity in Automation Studio? Also, do I need to import those opt-outs from DE to a list first before executing your code? Thanks
    – nix9247
    Feb 10, 2020 at 13:39
1

As far as I am aware, unsubscribe reason is only insertable with an unsubscribe event. See the following only has retrieve: https://developer.salesforce.com/docs/atlas.en-us.mc-apis.meta/mc-apis/unsubevent.htm

The last unsubscribe event/reason is described in the All Subs list so if you want to replace you could just resubmit an unsubscribe event using ssjs https://developer.salesforce.com/docs/atlas.en-us.mc-apis.meta/mc-apis/unsubscribing_and_logging_an_unsubevent_with_a_logunsubevent_execute_call.htm

0

FYI this also seems to have worked:

    var key = Attribute.GetValue('_subscriberkey');
    var email = Attribute.GetValue('emailaddr');
    var jobId = Attribute.GetValue('jobid');
    var batchId = Attribute.GetValue('_JobSubscriberBatchID');
    var listId = Attribute.GetValue('listid');;

    Write("\nSSJS Unsubscribe Status:\n");
    var lists = List.Retrieve({Property: "ID", SimpleOperator: "equals", Value: listId});
    var list = List.Init(lists[0].CustomerKey);
    var status = list.Subscribers.Upsert(email, {"Status" : "Unsubscribed", "Reason" : "Hello World")

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .