I have a problem with unsubscribe link in newsletter and can't figure out what I'm doing wrong.
The link in the newsletter is <a title="Unsubscribe" data-msys-unsubscribe="1" href="https://example.com/en/site/unsubscribe">Unsubscribe</a>"
.
I have created a webhook with the same target URL and it seems te be getting triggered since it says "Oh yeah! Last successful batch delivered on March 04, 2016 10:02 am".
I'm implementing this in PHP and at first I thought I'm not reading it correctly (using file_get_contents('php://input')
but when I tried the TEST from Sparkpost webhook interface the response for var_dump(file_get_contents('php://input'))
was:
HTTP/1.1 200
Date: Fri, 04 Mar 2016 09:17:57 GMT
Server: Apache
X-Powered-By: PHP/5.5.32
Content-Length: 1290
Connection: close
Content-Type: text/html; charset=utf-8
"<pre>string(1254) \"[{\"msys\":{\"unsubscribe_event\":{\"type\":\"list_unsubscribe\",\"campaign_id\":\"Example Campaign Name\",\"customer_id\":\"1\",\"event_id\":\"92356927693813856\",\"friendly_from\":\"sender@example.com\",\"mailfrom\":\"recipient@example.com\",\"message_id\":\"0e0d94b7-9085-4e3c-ab30-e3f2cd9c273e\",\"rcpt_meta\":{\"customKey\":\"customValue\"},\"rcpt_tags\":[\"male\",\"US\"],\"rcpt_to\":\"recipient@example.com\",\"raw_rcpt_to\":\"recipient@example.com\",\"rcpt_type\":\"cc\",\"subaccount_id\":\"101\",\"template_id\":\"templ-1234\",\"template_version\":\"1\",\"timestamp\":1454442600,\"transmission_id\":\"65832150921904138\"}}},{\"msys\":{\"unsubscribe_event\":{\"type\":\"link_unsubscribe\",\"campaign_id\":\"Example Campaign Name\",\"customer_id\":\"1\",\"event_id\":\"92356927693813856\",\"friendly_from\":\"sender@example.com\",\"mailfrom\":\"recipient@example.com\",\"message_id\":\"0e0d94b7-9085-4e3c-ab30-e3f2cd9c273e\",\"rcpt_meta\":{\"customKey\":\"customValue\"},\"rcpt_tags\":[\"male\",\"US\"],\"rcpt_to\":\"recipient@example.com\",\"raw_rcpt_to\":\"recipient@example.com\",\"rcpt_type\":\"cc\",\"subaccount_id\":\"101\",\"template_id\":\"templ-1234\",\"template_version\":\"1\",\"timestamp\":1454442600,\"transmission_id\":\"65832150921904138\",\"user_agent\":\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36\"}}}]\"\nstring(2) \"qq\"\n"
The same dump when clicking on the unsubscribe link in newsletter is an empty string (string(0) ""
).
Am I doing something wrong?
I expect based on the date of this question that you already have your answer so I will put this here for the next person.
The unsubscribe link does not need to be the same as your webhook endpoint. The way it will work is you will get "unsubscribe" webhook event but the user will also be redirected to the link that you provide.
Here is a doc at SparkPost that describe this in more detail: https://www.sparkpost.com/docs/user-guide/setting-up-unsubscribe-links/
If you need a quick way to test you can use my WebHook monitor here: https://github.com/yepher/webhook_monitor
Or use the running version here: http://webhook.yepher.com:3000/
When you visit that page you will get a "unique" URL. Just add that as one of your webhooks. Then send the email and click the unsubscribe link. After a little time, you will see the "unsubscribe event". You could open a second webhook monitor and use that as your "unsubscribe link" then you will see both. The webhook event will be a "POST" and the actual click by the end user will be a "GET"