Collect and operate data
PMP widgets, for instance, are able to collect end-users’ consents and preferences thanks to Didomi Consents API. When an end-user saves changes made on a widget, SDK will be sending a POST request to https://api.privacy-center.org/consents/events, creating a new consent event in consents table.
You don't have to necessarily use the widgets and you can build your own forms to collect consents and/or preferences from your end-users by using Didomi API.
Follow this documentation to understand how to operate collected data in your website by fetching our Consents API and display relevant sections to your end-users with their choices. A mention will be made at the end of this guide about how to update an end-user consent state from your website.
Authentication
Fetch and collect user data
Authentication
Authenticate the organization (backend) (1)
First, you need to authenticate your back-end in order to receive a token and make requests to the Consents API. You can find more information regarding Private API Keys in our developers documentation.
This access_token will grant you access to Didomi APIs and you will be able to create a Consents token on the user’s behalf.
Be careful to never share your key, secret as well as the generated session tokens to anyone.
Generate an end-user token (backend) (2)
Now that we have our organization token, we will use it to generate an end-user token (Consents token) and send it back to our application.
We recommend getting a Didomi token at authentication time and send it back to your frontend so your widget can log your user in and retrieve their consents.
Payload should include:
organization_idcan be retrieved in Didomi Console URL (required)organization_user_idis the unique ID of the end user. It can be an ID, an email address... This is what will allow you to link consent to a user in your DB and needs to be unique. (required)
lifetimeis a token lifetime in seconds (optional)
In your authentication controller, send a POST request to /consents/tokens endpoint.
The Didomi API will respond with the created token in the id_token field.
This id_token is what we call a Consents token. This token belongs to one of your users and allows them to change their consent and preferences.
Add the token retrieved to your authentication endpoint response so your frontend can consume it and call the Consents API.
Fetch and collect user data
Fetch user's choices (3)
As a customer of Didomi (Consents API needs to be activated), you can retrieve your user consents and use them to display relevant section on your website for example.
You need to query consent users that belong to your organization (organization_id), and filter by user ID or organization user ID (organization_user_id).
This code snippet shows you how to query user’s consents. You need to pass organization_id and organization_user_id as options.
Check if consent has been given for a purpose (4)
Purposes are stored in consents object and come in an array.
For each consent, enabled property allows you to know if the user has given his consent to this specific purpose.
true: the end user has given his consentfalse: the end-user has not given his consentnull: the end-user has not answered to this purpose
This code snippet shows you how to check if your user has given his consent for a given purpose (purposeId).
Check if consent has been given for a preference (5)
Preference values are stored in values object of a purpose.
For each preference with at least one value selected, you have a:
selectedPreferenceId(as key)object with values (
valueId(s) in astringseparated by comas (,) invalueproperty)
This code snippet shows you how to check if your user has selected an option (valueId) of a given preference (preferenceId).
Update user consent state (6)
Update end-user consent state from API standpoint (or basically collect data from end-user) means creating a consent event to register the new user choices by calling the POST /consents/events endpoint.
To update state of a purpose, you can set
enabledproperty totrueif the user has given his consent andfalseif has not given his consent.To update state of a preference, you can add in
valueproperty all choices selected by the end-user by filling in the relatedvalueId.
This code snippet shows you how to update your user consent state. To create an consent event, you need to pass the ID of your organization (organizationId), the unique ID of your user (organizationUserId) and new consents (consents).
Last updated