Skip to main content
Problem Solver II
Sep 11, 2022 6:05 PM UTC
Solved

Controlling $consent via API

Related posts I’ve read:

 

Hi all,

I’m trying to control $consent via API; doing a custom integration.

Right now, I’m only concerned about email consent, but in the future, other types may be required.

On our remote web application we have a tickbox “opt in to Marketing” and this should map to $consent[“email”].

We’re using the v1/identify api for synchronising our records to Klaviyo profiles, and all other custom fields are synchronising correctly.

  • When creating a new contact (unique email address, e.g. subaddress for testing) if we send $consent: [] or $consent: false then the contact is still getting email consent, shown by checking the consent display block on the right hand side of the profile in Klaviyo
  • When updating a contact, I can send $consent: [“email”] to give an existing contact with no consent, email consent, but sending $consent: [] does not remove it again
    • I have tried many permutations using values null, [], false, “false”, “False”, “None”, “none”, [“none”], [“None”] with both keys $consent and $email_consent. I also tried email_consent: false and $consent: [false]
  • We can successfully add a manual_exclusion for a contact using the v1/people/exclusion api however this isn’t really correct for our use case as by default all contacts would not have $consent, then if you tick the box on our side, we’d give them $consent, then if you untick the box we’d want to remove that - instead of keeping them with consent but excluding them; when you untick the box on our side and we send the exclusion, for now, I have to disable the tickbox unless the manual exclusion is removed in Klaviyo then we sync all exclusions overnight.
  • We are not concerned at this point with specific lists or segments, just the overall consent state of the contact
  • When I test sending various values to identify, I get a “1” back and can see that the timestamp shown in the profile consent block does update, but the consent state itself does not change
    This topic has been closed for replies.
    doanthanAnswer
    Contributor I
    Dec 3, 2022 11:54 AM UTC

    Hey Gareth,

     

    You can use the new v3 API endpoints to add and remove the green tick from profiles (instead of using the old v2 API endpoints).

     

    Simply create a list (you can call it ‘all subscribers’) and set it to single opt-in in the settings.

    Then POST to the v3 API endpoint Subscribe Profiles to add email profiles to the list (and have a green tick for consent on the profile).

    Sample Payload:

    {
    "data": {
    "type": "profile-subscription-bulk-create-job",
    "attributes": {
    "list_id": "listID",
    "subscriptions": [
    {
    "email": "test@gmail.com"
    }
    ]
    }
    }
    }

    If they unsubscribe, then POST to the v3 API endpoint Unsubscribe Profiles to remove email profiles from the list (and have a cross for consent on the profile).

    Sample Payload:

    {
    "data": {
    "type": "profile-unsubscription-bulk-create-job",
    "attributes": {
    "list_id": "listId",
    "emails": [
    "test@gmail.com"
    ]
    }
    }
    }

    I hope this helps…

    D

    15 replies

    Problem Solver III
    Sep 12, 2022 7:49 AM UTC

    Can confirm that having thought that this issue was solved I have gone back and run my unit tests: they are now failing, so consent is no longer being set via the method recommended in one of the linked posts.

    This is very important to my integration too and would appreciate a mod escalating this to support.

    Problem Solver I
    Oct 3, 2022 5:23 PM UTC

    following

    Problem Solver I
    Oct 13, 2022 5:00 PM UTC

    Same problem.

    Please share the solution to fix the consent email problem

    Thanks in advance

    doanthanAnswer
    Contributor I
    Dec 3, 2022 11:54 AM UTC

    Hey Gareth,

     

    You can use the new v3 API endpoints to add and remove the green tick from profiles (instead of using the old v2 API endpoints).

     

    Simply create a list (you can call it ‘all subscribers’) and set it to single opt-in in the settings.

    Then POST to the v3 API endpoint Subscribe Profiles to add email profiles to the list (and have a green tick for consent on the profile).

    Sample Payload:

    {
    "data": {
    "type": "profile-subscription-bulk-create-job",
    "attributes": {
    "list_id": "listID",
    "subscriptions": [
    {
    "email": "test@gmail.com"
    }
    ]
    }
    }
    }

    If they unsubscribe, then POST to the v3 API endpoint Unsubscribe Profiles to remove email profiles from the list (and have a cross for consent on the profile).

    Sample Payload:

    {
    "data": {
    "type": "profile-unsubscription-bulk-create-job",
    "attributes": {
    "list_id": "listId",
    "emails": [
    "test@gmail.com"
    ]
    }
    }
    }

    I hope this helps…

    D

    Contributor I
    Dec 3, 2022 7:05 PM UTC

    Also to add, if you want to check consent status server side, you can do it in one call using the new v3 Get Profiles query; you can query by email in one call.

    eg.

    GET

    https://a.klaviyo.com/api/profiles/?filter=equals(email,"test%40gmail.com")

     

    Will return a profile object (and $consent status) of test@gmail.com from your Klaviyo account. 

    D

    Problem Solver III
    Dec 8, 2022 4:19 PM UTC

    This is fantastic news, thank you!

     

    G

    Hey Gareth,

     

    You can use the new v3 API endpoints to add and remove the green tick from profiles (instead of using the old v2 API endpoints).

     

    Simply create a list (you can call it ‘all subscribers’) and set it to single opt-in in the settings.

    Then POST to the v3 API endpoint Subscribe Profiles to add email profiles to the list (and have a green tick for consent on the profile).

    Sample Payload:

    {
    "data": {
    "type": "profile-subscription-bulk-create-job",
    "attributes": {
    "list_id": "listID",
    "subscriptions": [
    {
    "email": "test@gmail.com"
    }
    ]
    }
    }
    }

    If they unsubscribe, then POST to the v3 API endpoint Unsubscribe Profiles to remove email profiles from the list (and have a cross for consent on the profile).

    Sample Payload:

    {
    "data": {
    "type": "profile-unsubscription-bulk-create-job",
    "attributes": {
    "list_id": "listId",
    "emails": [
    "test@gmail.com"
    ]
    }
    }
    }

    I hope this helps…

    D

     

    agrathAuthor
    Problem Solver II
    Oct 13, 2022 8:39 PM UTC

    Who can we loop in to get some assistance on this?

    Problem Solver I
    Oct 14, 2022 2:47 AM UTC

    Im using https://a.klaviyo.com/api/identify  

    I tried  "$consent": "false" is not working. Could any one help

    Thanks

    Problem Solver I
    Oct 14, 2022 2:49 AM UTC

    looping @stephen.trumble for support

    stephen.trumble
    Klaviyo Alum
    Oct 14, 2022 8:43 PM UTC

    Hey @agrath , @dartacus , @Stef  & @Aaron 

    First, I am so sorry that this post got lost in the frey, but hopefully I have the answer for you.

    In order to suppress a profile via API, you would need to use the API call found here to add them to the exclusions list (suppressions) in your account: https://developers.klaviyo.com/en/reference/exclude-globally.  This will still store all the profile's data in your account, but they will be suppressed and unable to receive emails going forward.

    Hope this helps!

    -Stephen