Skip to main content
All CollectionsConsent Management SolutionConsent Management Solution Installation Guides
How to block cookies set on the backend using the consent API
How to block cookies set on the backend using the consent API
Updated over a week ago

If your website sets cookies from the backend, you will need to use the Event API and Consent API to retrieve the cookie whitelist that your visitors have consented to and selectively deliver those cookies or not.

The guide below presents how to complete this process:

Step 1: Retrieve the visitor’s UUID from the frontend

use the Event API to retrieve visitor’s unique user identity (UUID) from the frontend.

Event API

Termly.on('consent', (data) => {...})

When is this called?
This callback method is triggered whenever a change in consent is detected.

How do I use this?

You can store the whitelist (data.cookies) in your frontend code, and use it to adjust cookie delivery logic for your website visitors.

Store the visitor’s UUID (data.uuid) in order to call the Termly RESTful API for a specific visitor.

Step 2: Get the visitor’s cookie preferences via API from the backend

After retrieving the UUID from the Event API, use the cookie_whitelist endpoint to get a specific visitor’s consent preferences:

GET cookie_whitelist

https://app.termly.io/api/v1/cookie_whitelist


This endpoint allows you to retrieve cookies that your visitor has consented to. This will also retrieve cookies in the Essential category.

Sample Code:

curl -H 'Accept: application/json' -H "Authorization: ${API_KEY}"
https://termly.io/api/v1/cookie_whitelist?uuid={UUID}
{ 
 cookies:
 [
 { 'name': 'cookie_name', 'provider': 'termly.io', 'type': 'http_cookie' },
 { 'name': 'cookie_name', 'provider': 'termly.io', 'type': 'http_cookie' }
 ] 
 categories: ['essential'],
 uuid: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
}
Did this answer your question?