This tutorial will walk you through the steps necessary to create a notice, modify its configuration, and publish it.
Note: If you're looking to create a multi-regulation configuration please see here instead.
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:
constbent=require("bent");constorganizationId="<organizationId>";consttoken="<token>"; // Get a token by authenticating in the API (https://developers.didomi.io/api/introduction/authentication)constclient= { post:bent("POST","https://api.didomi.io/v1","json", { Authorization:`Bearer ${token}`, },201 ),};(async () => {console.log(`Creating a notice for organization ${organizationId} ...` );constnotice=awaitclient.post("/widgets/notices", { organization_id: organizationId, name:"My consent notice", });console.log(`Notice with ID ${notice.id} created!`);})();
POST https://api.didomi.io/v1/widgets/noticesBODY{"organization_id": "didomi","name": "My consent notice"}
The API will return a response similar to:
{"name": "My consent notice","archived_at": null,"organization_id": "didomi","id": "7wmRYUH6","created_at": "2021-03-27T08:38:10.831Z","updated_at": "2021-03-27T08:38:10.831Z","version": 0}
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:
constbent=require("bent");constorganizationId="<organizationId>";constnoticeId="<noticeId>";consttoken="<token>"; // Get a token by authenticating in the API (https://developers.didomi.io/api/introduction/authentication)constclient= { get:bent("GET","https://api.didomi.io/v1","json", { Authorization:`Bearer ${token}`, }), patch:bent("PATCH","https://api.didomi.io/v1","json", { Authorization:`Bearer ${token}`, }), post:bent("POST","https://api.didomi.io/v1","json", { Authorization:`Bearer ${token}`, },201 ),};(async () => {console.log(`Querying the organization: ${organizationId} and the notice: ${noticeId}` );// Get the notice configs for the organization and noticeconsole.log("Getting the latest draft config ...");constrequest=awaitclient.get(`/widgets/notices/configs?organization_id=${organizationId}¬ice_id=${noticeId}` );constnoticeConfigs=request.data;// Filter the notice configs to get the draft config.constdraftConfig=noticeConfigs.filter((e) =>e.deployed_at ===null).pop();constdraftConfigId=draftConfig.id;})();
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:
constbent=require("bent");const { merge } =require("lodash");constorganizationId="<organizationId>";constnoticeId="<noticeId>";consttoken="<token>"; // Get a token by authenticating in the API (https://developers.didomi.io/api/introduction/authentication)constclient= { get:bent("GET","https://api.didomi.io/v1","json", { Authorization:`Bearer ${token}`, }), patch:bent("PATCH","https://api.didomi.io/v1","json", { Authorization:`Bearer ${token}`, }), post:bent("POST","https://api.didomi.io/v1","json", { Authorization:`Bearer ${token}`, },201 ),};(async () => {console.log(`Querying the organization: ${organizationId} and the notice: ${noticeId}` );// Get the notice configs for the organization and noticeconsole.log("Getting the latest draft config ...");constrequest=awaitclient.get(`/widgets/notices/configs?organization_id=${organizationId}¬ice_id=${noticeId}` );constnoticeConfigs=request.data;// Filter the notice configs to get the draft config.constdraftConfig=noticeConfigs.filter((e) =>e.deployed_at ===null).pop();constdraftConfigId=draftConfig.id;// Modify the notice configurationconsole.log("Updating the latest draft config ...");awaitclient.patch(`/widgets/notices/configs/${draftConfigId}`,merge(draftConfig, { consent_duration:6,// Change the consent duration for the notice consent_duration_unit:"months", }) );})();
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:
constbent=require("bent");const { merge } =require("lodash");constorganizationId="<organizationId>";constnoticeId="<noticeId>";consttoken="<token>"; // Get a token by authenticating in the API (https://developers.didomi.io/api/introduction/authentication)constclient= { get:bent("GET","https://api.didomi.io/v1","json", { Authorization:`Bearer ${token}`, }), patch:bent("PATCH","https://api.didomi.io/v1","json", { Authorization:`Bearer ${token}`, }), post:bent("POST","https://api.didomi.io/v1","json", { Authorization:`Bearer ${token}`, },201 ),};(async () => {console.log(`Querying the organization: ${organizationId} and the notice: ${noticeId}` );// Get the notice configs for the organization and noticeconsole.log("Getting the latest draft config ...");constrequest=awaitclient.get(`/widgets/notices/configs?organization_id=${organizationId}¬ice_id=${noticeId}` );constnoticeConfigs=request.data;// Filter the notice configs to get the draft config.constdraftConfig=noticeConfigs.filter((e) =>e.deployed_at ===null).pop();constdraftConfigId=draftConfig.id;// Modify the notice configurationconsole.log("Updating the latest draft config ...");awaitclient.patch(`/widgets/notices/configs/${draftConfigId}`,merge(draftConfig, { consent_duration:6,// Change the consent duration for the notice consent_duration_unit:"months", }) );// Publish the notice configurationconsole.log("Publishing the draft config ...");constresponse=awaitclient.post(`/widgets/notices/deployments`, { notice_id: noticeId, organization_id: organizationId, production_config_id: draftConfigId, message:"Message describing the content of the update to the notice", });console.log(`Your deployment is a ${response.status}!`);})();
POST https://api.didomi.io/v1/widgets/notices/deploymentsBODY{"notice_id": "7wmRYUH6","organization_id": "didomi","production_config_id": "7bKP4CRr","message": "Description of changes included in my deployment"}
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:
{"message": "Description of changes included in my deployment","notice_id": "7wmRYUH6","production_config_id": "7bKP4CRr","organization_id": "didomi","status": "success","status_message": null,"id": "itBtwnxM","created_at": "2021-03-27T08:53:07.467Z","updated_at": "2021-03-27T08:53:07.467Z","version": 0}