Solved

Controlling $consent via API

  • 11 September 2022
  • 15 replies
  • 1178 views

Userlevel 1
Badge +2

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
icon

Best answer by doanthan 3 December 2022, 12:54

View original

15 replies

Userlevel 2
Badge +5

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.

Userlevel 1
Badge +2

following

Badge +1

Same problem.

Please share the solution to fix the consent email problem

Thanks in advance

Userlevel 1
Badge +2

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

Badge +1

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

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

Thanks

Badge +1

looping @stephen.trumble for support

Userlevel 7
Badge +60

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!

Badge +1

 Hello @stephen.trumble  

Yup I’m able to do execute and see the results as (consent status - x symbol).

However, if again want back the same email address to opt in to email consent. I’m not able to do it.

we have the below use case in our site,
In our website we have checkbox in edit form where user can change the email consent status to send or if unchecked not sent. Can we have solution for this use case?

Thanks

cc: @Stef, @dartacus @agrath 

Userlevel 1
Badge +2

Thanks for the reply @stephen.trumble 

Like, @Aaron mentioned in the last comment, I’ve got a similar issue as mentioned in my initial post. 

As I could not find a way to remove the consent once it was added, I have currently used the exclusions API so that when the consent/opt-in tickbox is unticked on my side/in my other system, this is sent as an exclusion to Klaviyo, but could not find an API to remove that exclusion again. 

So, my solution for that (which is not a good user experience) was that I had to disable the checkbox on my side if it had been previously checked but then unchecked and show the Klaviyo exclusion reason in a label/badge, forcing the user of my application to manually go to Klaviyo to remove it if required. And additionally do an overnight sync of the exclusions to ensure we avoid race conditions as best as we can (there appeared to be no way to get a webhook sent for changes in consent state, or exclusion state - outside of a flow)

To give context as to why we need to be able to remove consent instead of just add to the exclusion list, we have an initial state of contacts from a 3rd party system and some are active subscription product customers (so can be explictly opt-in), some are leads collected from other sources and have varying levels of opt-in (some would be explict opt in, others may be indeterminate) and some would be explictly opt-out from our current supression list behaviour in the migration.

I beleive it is different to have a contact on the exclusion list to just not having declared consent. Am I wrong?

I need to initialise all the state correctly during migration to Klaviyo and provide my customer a way to control what state the contact is in from our 3rd party system. 

As I understand consent in Klaviyo, there are several states;

  • Indeterminate (no consent specifically issued)
  • Consent issued (green tick/explicit opt-in)
  • Excluded (red tick/explicit opt-out)

Then these are per type (email, sms etc)

Can you please explain the difference between indeterminate (no explicit opt-in has been sent) and added to the exclusion list?

  • Is there a charge for contacts on the exclusion list?
  • Is there a charge for contacts that are not explictly opt-in, what i’m calling the indeterminate state?
  • Can you send transactional emails (flows that have been explcitly marked as transactional by support) to a contact that’s in the exclusion list?
  • For a contact that’s indeterminate, what can you/can’t you do? My understanding is you should look to obtain explict opt-in so this might mean sending them a welcome or do you want to be on our list email to ask them to explcitly subscribe.

From my perspective, it would be ideal to express the tri-state consent state (for email only) with three radio buttons in our other system, but there seems to be no way to remove consent once granted, and no way to remove an exclusion once added which makes this non-viable.

Thanks for your time,

Gareth

Badge +1

@Team any updates!! we are going Live coming week., so it would be great if we fix this.

I would also suggest to use same below API for both on and off.,

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


like for email consent we are able to send ($consent : “email”) through the above API

and for off (email consent) why can’t we use the same API.?? Please consider the recommendation if it’s possible. Ideally it will save time to call different API call 

@stephen.trumble @Stef 

Thanks

Badge

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

Badge

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

Badge +1

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

Userlevel 2
Badge +5

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

 

Badge +2

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?

Reply