Solved

How to re-subscribe to Klaviyo if user has previously unsubscribed?

  • 27 March 2024
  • 3 replies
  • 75 views

Badge +2

We’re using the JSON:API method to subscribe/unsubscribe users.

We store a “wants_email_updates” flag in our database, and when the user changes this value we either subscribe them, or unsubscribe them.

We have a list set up in Klaviyo that is single opt-in.

We subscribe them with a payload similar to:

 

$this->request('POST', '/profile-subscription-bulk-create-jobs', [
'data' => [
'type' => 'profile-subscription-bulk-create-job',
'attributes' => [
'profiles' => [
'data' => [
[
'type' => 'profile',
'attributes' => [
'email' => $email,
'subscriptions' => [
'email' => [
'marketing' => [
'consent' => 'SUBSCRIBED',
'consented_at' => now()->toJSON(),
],
],
],
],
],
],
],
],
'relationships' => [
'list' => [
'data' => [
'type' => 'list',
'id' => $this->listId,
],
],
],
],
]);

Then we unsubscribe them via a payload similar to:

$this->request('POST', '/profile-subscription-bulk-delete-jobs', [
'data' => [
'type' => 'profile-subscription-bulk-delete-job',
'attributes' => [
'profiles' => [
'data' => [
[
'type' => 'profile',
'attributes' => [
'email' => $email,
],
],
],
],
],
'relationships' => [
'list' => [
'data' => [
'type' => 'list',
'id' => $this->listId,
],
],
],
],
]);

However, once the user unsubscribes from the list via our UI, It globally suppresses them.

So if we call our “subscribe” function again using the request above, it doesn’t seem to do anything.

But I can go into the klaviyo UI and manually resubscribe them to the list via using the button provided.

How can we automatically resubscribe users via the JSON:API who have previously opted out and now want to opt in?

Thanks

icon

Best answer by KeviSunshine 28 March 2024, 12:14

View original

3 replies

Userlevel 4
Badge +7

Hi @owen_fnatic,

I remembered Klaviyo doing something similar with the older versions of the API–you wouldn’t be able to re-subscribe someone unless you updated their profile for a list (or something like that).

However, I just tried the two endpoints you’re using and they worked for my use case. Let me explain…

  • My profile was subscribed to a list “Test”
  • I called the endpoint `profile-subscription-bulk-delete-job` and my profile was removed from the list and unsubscribed from email
  • Then I called `profile-subscription-bulk-delete-job` and my profile was re-added to the list, and re-subscribed to email marketing.

I’ll share my code snippets just in case…

// Subscribe.
{
"data": {
"type": "profile-subscription-bulk-create-job",
"attributes": {
"profiles": {
"data": [
{
"type": "profile",
"attributes": {
"email": "EMAIL_HERE",
"subscriptions": {
"email": {
"marketing": {
"consent": "SUBSCRIBED"
}
}
}
}
}
]
}
},
"relationships": {
"list": {
"data": {
"type": "list",
"id": "LIST_ID_HERE"
}
}
}
}
}

// Unsubscribe.
{
"data": {
"type": "profile-subscription-bulk-delete-job",
"attributes": {
"profiles": {
"data": [
{
"type": "profile",
"attributes": {
"email": "EMAIL_HERE"
}
}
]
}
},
"relationships": {
"list": {
"data": {
"type": "list",
"id": "LIST_ID_HERE"
}
}
}
}
}

Cheers,

Kevin.

Badge +2

Do you have the global unsubscribe/suppression thing turned on? Eg if you unsubscribe from 1 list, it unsubscribes from all lists?

Userlevel 4
Badge +7

I have global unsubscribe turned on for my organization.

 

 

Reply