Create and publish a consent notice
This tutorial will walk you through the steps necessary to create a notice, modify its configuration, and publish it.
Create a consent notice
To create a consent notice, send a POST /widgets/notices request with the name of the notice to create and the ID of the organization that the notice belongs to:
const bent = require("bent");
const organizationId = "<organizationId>";
const token = "<token>"; // Get a token by authenticating in the API (https://developers.didomi.io/api/introduction/authentication)
const client = {
post: bent(
"POST",
"https://api.didomi.io/v1",
"json",
{
Authorization: `Bearer ${token}`,
},
201
),
};
(async () => {
console.log(
`Creating a notice for organization ${organizationId} ...`
);
const notice = await client.post("/widgets/notices", {
organization_id: organizationId,
name: "My consent notice",
});
console.log(`Notice with ID ${notice.id} created!`);
})();The API will return a response similar to:
Modify the notice configuration
The API automatically created a draft configuration when a notice was created. To update the notice configuration, you must first get the ID of the draft configuration and then modify that draft configuration.
Get the ID of the draft configuration
To get the ID of the draft configuration, get the list of all configurations:
The configuration is called "draft" because its deployed_at field is null which indicates that this configuration has not been published before and can be modified.
As we are working with a newly created notice in this tutorial, we can assume that it has a single associated configuration and that it is a draft. If you are working with an existing notice that might have been published before and would have multiple configurations, read our documentation to find the current draft documentation.
Modify the draft configuration
To modify the draft configuration, send a PATCH request with the updated configuration:
Publish the notice
Now that our notice is configured as we want it to be, we need to publish it so that our modified configuration appears in the actual notice on the website or app.
To publish a notice, we need to create a new deployment for that notice:
The production_config_id should be the ID of the draft config you are publishing. message is a text field that can be used to indicate information on what changes are included in your deployment.
The API responds with the status of your deployment:
What's next?
The Didomi API allows managing all aspects of consent notices and their configurations. Read more about the entities to learn how to do more complex operations.
Last updated