> For the complete documentation index, see [llms.txt](https://developers.didomi.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.didomi.io/api-and-platform/widgets/privacy-widgets/edit-a-widget/purposes-and-preferences.md).

# Purposes & preferences

{% hint style="info" %}
This section relates to [Preferences widgets](https://gitlab.com/didomi/developers-documentation/-/tree/main/docs/api-and-platform/widgets/privacy-widgets/edit-a-widget/broken-reference/README.md) only.
{% endhint %}

A widget is built with **entities**.

You can choose a widget type when creating a widget, allowing you to select one or all selected purposes and preferences from the Configuration Tree. For every element selected including its children (purpose, preference and preference value), an entity is created.

They are needed for either [enabling / disabling](#hide-display-an-entity) or [reordering](#reorder-entities-within-a-widget) certains part of the tree within a widget.

### **Get a list of entities**

To retrieve a list of entities, send a **GET** request on `/widgets/preferences-centers/layout-entities`.

To retrieve an entity of a specific widget, add `widget_id` query to following **GET** request with `id` of your widget.

```json
GET https://api.didomi.io/widgets/preferences-centers/layout-entities?organization_id=YOUR_ORG_ID&widget_id=YOUR_WIDGET_ID

[
    {
        "id": "String",
        "created_at": "Date",
        "updated_at": "Date",
        "parent_id": null,
        "selected_purpose_id": "String" || null,
        "selected_preference_id": "String" || null,
        "preference_value_id": "String" || null,
        "layout_component_id": "String",
        "enabled": false,
        "organization_id": "String",
        "widget_id": "String",
        "order": 0
    }
]
```

### Hide / Display an entity

To hide or display an entity, send a **PATCH** request on `/widgets/preferences-centers/layout-entities/{id}`.

```json
PATCH https://api.didomi.io/widgets/preferences-centers/layout-entities/{id}?organization_id=YOUR_ORG_ID

{
    /**
    * true: entity is displayed
    * false: entity is hidden
    */
    "enabled": true || false
}
```

### Hide / Display multiple entities

To hide or display multiple entities, send a **PATCH** request on `/widgets/preferences-centers/layout-entities`.

```json
PATCH https://api.didomi.io/widgets/preferences-centers/layout-entities?organization_id=YOUR_ORG_ID
[
    {
        "id": "layoutEntityID",
        /**
        * true: entity is displayed
        * false: entity is hidden
        */
        "enabled": true || false
    }
]
```

### Reorder entities within a widget

First of all, keep in mind you can reorder entities that belong to the same level of nesting within your widget. When reordering one entity, you need to reorder its direct siblings (with the same `parent_id`) in order to avoid having siblings with the same order.

To reorder entities, send a **PATCH** request on `/widgets/preferences-centers/layout-entities`.

```json
PATCH https://api.didomi.io/widgets/preferences-centers/layout-entities?organization_id=YOUR_ORG_ID
[
    {
        "id": "layoutEntityID",
        "order": 0
    },
    {
        "id": "layoutEntityID",
        "order": 1
    },
    ...
]
```

{% hint style="warning" %}
`preference_value_id` are not unique. What makes a preference value unique is the couple `selected_preference_id` and `preference_value_id` (Mind checking this [section](/api-and-platform/data-manager/configuration-tree.md#entities-vs-selected-entities) to fully understand how relation between preferences and selected preferences works)

When reordering preference values, make sure to target the right `parent_id` (aka the layout entity linked to the parent preference)
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developers.didomi.io/api-and-platform/widgets/privacy-widgets/edit-a-widget/purposes-and-preferences.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
