# Public Methods

Public methods are SDK methods that are made available to facilitate your interactions with our SDK, including getting information from the widget configuration and from the current user consent state.

* [DidomiWidgets.getContainerById(widgetId)](#didomiwidgets.getcontainerbyid-widgetid)
* [DidomiWidgets.updateToken(token)](#didomiwidgets.updatetoken-token)
* [container.getEntities()](#container.getentities)
* [container.isConsentPurposeEnabled(purposeId)](#container.isconsentpurposeenabled-purposeid)
* [container.getPreferenceValueById({ purposeId, preferenceId })](#container.getpreferencevaluebyid-purposeid-preferenceid)
* [container.getEntityContentById({ entityType, entityId, entityProperty, withComponentContent })](#container.getentitycontentbyid-entitytype-entityid-entityproperty-withcomponentcontent)
* [container.getComponentContentById({ componentId, componentProperty })](#container.getcomponentcontentbyid-componentid-componentproperty)

#### DidomiWidgets.getContainerById(widgetId)

The SDK allows you to get the configuration object of a published widget using the `getContainerbyId` method.

```javascript
const container = await DidomiWidgets.getContainerById("widgetId");
```

We recommend getting the widget's configuration once the SDK is ready. You can refer to the example [here](/api-and-platform/widgets/privacy-widgets/headless-widgets.md#load-the-headless-widget-and-its-entities-when-the-sdk-is-ready).

#### DidomiWidgets.updateToken(token)

The SDK allows you to set the user token asynchronously.

```javascript
const container = await DidomiWidgets.updateToken(YOUR_TOKEN);
```

#### container.getEntities()

The SDK provides a method called getEntities that enables you to retrieve entities from your Configuration Tree that are enabled in your widget. From there, you will be able to display purpose and preference choices on your page using our [Custom Elements](/api-and-platform/widgets/privacy-widgets/headless-widgets.md#custom-elements).

```javascript
  const entities = await container.getEntities();
```

You will receive the following data. We recommend getting the widget's configuration once the SDK is ready. You can refer to the example [here](/api-and-platform/widgets/privacy-widgets/headless-widgets.md#load-the-headless-widget-and-its-entities-when-the-sdk-is-ready).

#### container.isConsentPurposeEnabled(purposeId)

The SDK provides a method for checking whether a purpose is enabled or not.

The method, `isConsentPurposeEnabled(purposeId)` takes the purpose ID as a parameter and returns `true` or `false`.

```javascript
const isPurposeEnabled = container.isConsentPurposeEnabled(purposeId)
```

#### container.getPreferenceValueById({ purposeId, preferenceId })

The SDK provides a method for fetching choices selected from a preference.

The method `getPreferenceValueById` takes the purpose ID and preference ID as parameters and returns a string of IDs separated by commas (`,`) containing the enabled values.

```javascript
const enabledValuesAsString = container.getPreferenceValueById({ purposeId, preferenceId });a
```

#### container.getEntityContentById({ entityType, entityId, entityProperty, withComponentContent })

The SDK offers a method for displaying the translated content of your entities if you are unable to use our custom elements.

The method `getEntityContentById` takes the entityType, entityId, entityProperty and withComponentContent as parameters and returns a string with the content requested.

| Parameter              | Description                                                                                                                                                                                  |
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `entityType`           | This property determines which content of the entity object should be displayed. It can be `name` or `description`.                                                                          |
| `entityId`             | ID of the selected purpose, selected preference or preference value. You can easily find them in the Configuration Tree section on the Console.                                              |
| `entityProperty`       | Specify the type of property. It can be either `purpose`, `preference` or `preference-value`.                                                                                                |
| `withComponentContent` | This property is used to determine whether to override the entity content with the layout component one set a widget level, if any (`true`), or to display the entity content (`undefined`). |

#### container.getComponentContentById({ componentId, componentProperty })

The SDK offers a method for displaying the translated content of your component if you are unable to use our custom elements.

The method `getComponentContentById` takes the containerId, componentId and componentCategory as parameters and returns a string with the content requested.

| Parameter         | Description                                                                                                                                                                                                |
| ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| componentId       | ID of the layout-component                                                                                                                                                                                 |
| componentProperty | Property of the layout-component. For example `saveButton.text.content` (if it has been edited at the layout-component level) or `bannerImage.src` to get the URL of the header banner image for instance. |


---

# 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/widgets/privacy-widgets/headless-widgets/public-methods.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.
