Skip to main content
Problem Solver II
September 11, 2022
Solved

Controlling $consent via API

  • September 11, 2022
  • 15 replies
  • 1728 views

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.
    Best answer by doanthan

    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

    doanthanAnswer
    Contributor I
    December 3, 2022

    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
    December 3, 2022

    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

    Contributor I
    December 5, 2022

    Does anybody know if there are equivalent calls that can be made using the client side object?

     

    I can set the initial $consent using the identity call, but I can’t find a way to remove it using just the client side javascript.

     

    Thanks

    Problem Solver III
    December 8, 2022

    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

     

    Contributor I
    February 13, 2023

    I understand I can use remove the green consent using the method from @doanthan however that requires your private key which shouldn’t be revealed client side.

    Like the request from @TTook is there a way to remove consent client side?