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
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
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");
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
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")