# Preferences Library

A preferences library is a set of re-usable preferences.

Each preference created in the preferences library can be used several times in the configuration tree allowing a more granular choice to be offered to the user for given purposes.

A collection of preferences facilitates analysis of user's choices made on your widgets.

#### Preferences

A Preference is an opportunity to collect information about user's intentions, motivations and interests.

Each preference has several choices (values) and can be added to one or multiple purpose(s) to offer a more granular choice to the user.

Preferences should match with different marketing use cases. Some examples:

* Topic and content choices
* Frequency options
* Custom customer data questions
* Privacy policies, programmes and certifications
* Access to privacy rights information

#### Values

A value is a string and is always linked to a preference. When you create a preference, you create a list of values from where the user will be able to choose from.

You can see the preference as the question and the value as one of the answer to that question.

## Create a preference

To add a preference in your Preferences Library, send a **POST** request on `/preferences`.

```json
POST https://api.didomi.io/preferences?organization_id=YOUR_ORG_ID

{
  "name": {
    "en": "String",
    "fr": "String"
  },
  "description": {
    "en": "String",
    "fr": "String"
  },
  "metadata": {},
  /**
  * single: users will be able to make only one choice for this preference
  * multi: users will be able to make multiple choices for this preference  
  */
  "type": "single || multi",
  "values": [
    {
      "name": {
        "en": "String",
        "fr": "String"
      },
      "metadata": {},      
    },
    {
      "name": {
        "en": "String",
        "fr": "String"
      },
      "metadata": {},
    }    
  ]
}
```

{% hint style="info" %}
Didomi supports translations. Add your translated content by using available keys detailed [here](/api-and-platform/introduction/translations.md).
{% endhint %}

## Get all preferences

To retrieve the list of all your preferences, send a **GET** request on `/preferences`.

```json
GET https://api.didomi.io/preferences?organization_id=YOUR_ORG_ID

{
  "total": 0,
  "limit": 0,
  "skip": 0,
  "data": [
    {
      "id": "string",
      "created_at": "Date",
      "updated_at": "Date",
      "name": {
        "en": "String",
        "fr": "String"
      },
      "description": {
        "en": "String",
        "fr": "String"
      },
      "metadata": {},      
      "organization_id": "string",
      "type": "single",
      "values": [
        {
          "id": "string",
          "created_at": "Date",
          "updated_at": "Date",
          "name": {
            "en": "String",
            "fr": "String"
          },
          "metadata": {},
          "order": 0
        },
        {
          "id": "string",
          "created_at": "Date",
          "updated_at": "Date",
          "name": {
            "en": "String",
            "fr": "String"
          },
          "metadata": {},          
          "order": 1
        }
      ]
    }
  ]
}
```

## Get a preference

To retrieve a preference from your Preferences Library, send a **GET** request on `/preferences/{id}`.

```json
GET https://api.didomi.io/preferences/{id}?organization_id=YOUR_ORG_ID

{
  "id": "string",
  "created_at": "Date",
  "updated_at": "Date",
  "name": {
    "en": "String",
    "fr": "String"
  },
  "description": {
    "en": "String",
    "fr": "String"
  },
  "metadata": {},  
  "organization_id": "string",
  "type": "single",
  "values": [
    {
      "id": "string",
      "created_at": "Date",
      "updated_at": "Date",
      "name": {
        "en": "String",
        "fr": "String"
      },
      "metadata": {},      
      "order": 0
    }
  ]
}
```

## Edit a preference

To edit a preference in your Preferences Library, send a **PATCH** request on `/preferences/{id}`.

```json
PATCH https://api.didomi.io/preferences/{id}?organization_id=YOUR_ORG_ID

{
  "name": {
    "en": "String",
    "fr": "String"
  },
  "description": {
    "en": "String",
    "fr": "String"
  },
  "metadata": {},
  "type": "single",
  "values": [
    {
      "id": "string",
      "name": {
        "en": "String",
        "fr": "String"
      },
      "metadata": {},
    }
  ]
}
```

*Note that values order edition is not supported.*

{% hint style="danger" %}
When you are editing a preference, all existing values in `values` array need to be included in your PATCH request so they are not deleted.
{% endhint %}

## Delete a preference

To delete a preference from your Preferences Library, send a **DELETE** request on `/preferences/{id}`.

```json
DELETE https://api.didomi.io/preferences/{id}?organization_id=YOUR_ORG_ID
```


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.didomi.io/api-and-platform/data-manager/preferences-library.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
