Skip to main content
Solved

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

  • March 27, 2024
  • 3 replies
  • 345 views

Forum|alt.badge.img+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

Best answer by KeviSunshine

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.

View original
Did this topic or the replies in the thread help you find an answer to your question?

3 replies

KeviSunshine
Expert Problem Solver III
Forum|alt.badge.img+8
  • Expert Problem Solver III
  • 160 replies
  • Answer
  • March 28, 2024

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.


Forum|alt.badge.img+2
  • Author
  • Contributor I
  • 1 reply
  • March 30, 2024

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


KeviSunshine
Expert Problem Solver III
Forum|alt.badge.img+8
  • Expert Problem Solver III
  • 160 replies
  • April 1, 2024

I have global unsubscribe turned on for my organization.