[SalesForce] Unsubscribing a Subscriber using AMPscript

We want to create a simple custom subscription center with an 'Unsubscribe' button.

I'm trying to figure out what the best approach would be to do this using AMPscript (that is, what AMPscript code to execute when the form button is submitted). I was thinking of creating a CloudPage URL that looks like this:

http://campaign.company.com/unsubscribe?id=123456

Where 123456 is the subscriber key. I've found this example but it looks pretty over the top and requires the following URL parameters in addition to Subscriber Key:

SET @jid = RequestParameter("jobid")
SET @listid = RequestParameter("listid")
SET @batchid = RequestParameter("batchid")

Is this really necessary? All I want to do is to unsubscribe a SubscriberKey from the All Subscribers list (I assume that I have to use the InvokeExecute API AMPscript function).

Best Answer

This article outlines the minimal required for logging an unsub event. Here's the relevant section:

Subscriber Context

The Subscriber Context is defined by the SubscriberID, SubscriberKey and EmailAddress parameters. You must supply at least one of these parameters. If you provide more than one of these parameters, we retrieve the Subscriber using one of the values and validate that the other values match the retrieved Subscriber. If they do not match, an error will be returned.

If the SubscriberKey business rule is turned on and you supply the EmailAddress parameter, you MUST supply either the SubscriberID or the SubscriberKey.

Job Context

The Job Context is defined by the JobID, ListID and BatchID parameters. These values are used to determine which Job the UnsubEvent will be tracked against. The subscriber will also be unsubscribed from the List that the Job was sent to. You do not need to supply all three values. We will look up any missing values using the following rules:

  • If the JobID is supplied, we can lookup a missing ListID and/or BatchID.
  • If the ListID is supplied, we can lookup a missing JobID and/or BatchID.
    • If the JobID is missing, we will use the most recent JobID that the subscriber was sent to.
    • This may not be the Job that the Subscriber is acting upon.
  • If only the BatchID is supplied, we cannot lookup the remaining information and the job context will not be defined.

If the job context cannot be established because you did not supply any of these parameters or only supplied the BatchID, the UnsubEvent will not be created. The subscriber will also be Master Unsubscribed from the system instead of being unsubscribed from a particular list.

Unsub Reason

This is used to specify the reason the subscriber is being unsubscribed from the system. If the reason is not supplied, the default value will be used:Unsubscribed via Log Unsub Event Execute call

Related Topic