# Acoustic parameters

> After you install the Acoustic Content integration, new parameter types are available.

Source: https://docs.uniform.app/docs/integrations/content/acoustic-content/acoustic-parameters

After you install the Acoustic Content integration, the following
parameter types are available. You can use these to incorporate
content from Acoustic Content into your components and compositions.

| Parameter type | Description |
| --- | --- |
| [Acoustic Content Item](#acoustic-content-item) | Select a single item from Acoustic Content. |
| [Acoustic Multi Content Item](#acoustic-multi-content-item) | Select multiple items from Acoustic Content. |

## Acoustic Content Item

This parameter type allows a Uniform user to select a single
Acoustic Content item.

### Add parameter to component

To allow a user to select an item from Acoustic Content,
you must add a parameter to a component. The parameter is used
to store the identifier to the selected item when the user
selects an item.

1. In Uniform, navigate to your component.
2. Add a new parameter using the parameter type **Acoustic Content Item**.
3. The following values can be specified:

   | Name | Description |
   | --- | --- |
   | Select Linked Source | Specifies which Acoustic Content subscription is the source for the item that can be selected. |
   | Allowed content types | Specifies which content types will be available to select from when the parameter value is edited. You can select multiple content types to allow the user to select from a larger set of items. |
   | Required | Indicates whether the value is required when the component is used. |

   ![Acoustic Content Item parameter with a single content type selected.](https://docs.uniform.app/images/integrations/content/acoustic/use-parameters/acoustic-content-item/parameter-config.png)

### Edit parameter value

When you use a component with an Acoustic Content Item parameter,
by default no items will be selected. You are prompted to
select an item.

1. Click **Select**.

   ![](https://docs.uniform.app/images/integrations/content/acoustic/use-parameters/acoustic-content-item/edit-value-default.png)
2. Click the item you want to select.

   > **About this step:**
   >
   > A couple of filters are available. The dropdown allows you to filter by content type. The text box allows you to filter by item content.
3. Click **Accept** to save your selection.

   ![](https://docs.uniform.app/images/integrations/content/acoustic/use-parameters/acoustic-content-item/edit-value-selected.png)
4. You will see details about the item you selected, including the title and some metadata.

   ![](https://docs.uniform.app/images/integrations/content/acoustic/use-parameters/acoustic-content-item/edit-value-saved.png)

   > **About this step:**
   >
   > After your selection is saved, you are presented with the following options:
   >
   > - If you want to edit the selected item in Acoustic Content, click **Edit**.
   > - If you want to deselect the item, click **Unlink**.

### Configure an enhancer

When an item is selected, Uniform only stores the identifier
for the item. Your front-end application must retrieve the
details for the item. Uniform provides an enhancer to
simplify this process.

> **Tip:**
>
> Using the enhancer provided by Uniform saves you from having
> to write logic to interact directly with Acoustic Content.

#### How Uniform stores the selected item

The following is an example of what Uniform
stores for the parameter.

```json
{
  "type": "acousticContentItem",
  "value": {
    "contentItemId": "######################",
    "source": "default"
  }
}
```

There are two identifiers in this value:

1. The item that was selected.
2. The source key for the linked content source.

#### Add the enhancer

Uniform provides an enhancer so you don't need to write the API
calls to Acoustic Content to retrieve data for item.

1. Add the following npm packages to your front-end application:

   ```
   @uniformdev/canvas-acoustic
   ```
2. In a text editor, open the file where you retrieve the
   composition definition from Uniform.

   > **About this step:**
   >
   > You are looking for the code calls the async function
   > `getComposition`. The code below assumes the
   > object returned is set in a variable `composition`.
3. Add the following import statements:

   ```javascript
   import {
     AcousticClientList,
     CANVAS_ACOUSTIC_CONTENT_ITEM_PARAMETER_TYPES,
     createAcousticClient,
     createAcousticContentItemEnhancer,
   } from '@uniformdev/canvas-acoustic';
   ```
4. Add the following code:

   ```javascript
   const client = createAcousticClient({
     apiUrl: '!!! YOUR ACOUSTIC CONTENT API URL !!!',
   });
   const previewClient = createAcousticClient({
     apiUrl: '!!! YOUR ACOUSTIC CONTENT PREVIEW API URL !!!',
     auth: {
       apiKey: '!!! YOUR ACOUSTIC CONTENT API KEY !!!'
     },
   });
   ```

   > **About the preview API URL:**
   >
   > To determine the appropriate value for the preview API URL,
   > see the [preview content](https://developer.goacoustic.com/acoustic-content/docs/preview-content)
   > section in the Acoustic Content documentation.

   > **About this step:**
   >
   > Uniform recommends you moving the Acoustic Content credentials to
   > environment variables rather than hard-coding them in the
   > front-end app.
5. Add the following code:

   ```javascript
   const clients = new AcousticClientList({ 
     client,
     previewClient
   });
   const acousticEnchancer = createAcousticContentItemEnhancer({ clients });
   ```
6. Add the following code:

   ```javascript
   await enhance({
     composition,
     enhancers: new EnhancerBuilder().parameterType(
       CANVAS_ACOUSTIC_CONTENT_ITEM_PARAMETER_TYPES, 
       acousticEnchancer,
     ),
     context: {},
   });
   ```

   > **About this step:**
   >
   > This registers the enhancer to be used for any occurrence
   > of the Acoustic Content Item parameter.

> **Next steps:**
>
> Now, the parameter value in the composition is mutated to
> include the field values for the selected Acoustic Content item
> (instead of just being an identifier).

## Acoustic Multi Content Item

This parameter type is [added](#add-parameter-to-component) and
[edited](#edit-parameter-value) the same way as [Acoustic Content Item](#acoustic-content-item).
When editing the parameter value, you can select additional items
by clicking the button **Select new**.

![Example of the editing interface for an Acoustic Multi Content Item parameter on a component.](https://docs.uniform.app/images/integrations/content/acoustic/use-parameters/acoustic-content-multi-item/item-selected.png)

### Configure an enhancer

When items are selected, Uniform only stores the identifiers
for the items. Your front-end application must retrieve the
details for the items. Uniform provides an enhancer to
simplify this process.

> **Tip:**
>
> Using the enhancer provided by Uniform saves you from having
> to write logic to interact directly with Acoustic Content.

#### How Uniform stores the selected items

The following is an example of what Uniform
stores for the parameter.

```json
{
  "type": "acousticMultiContentItem",
  "value": {
    "source": "default",
    "contentItemIds": [
      "######################",
      "######################"
    ]
  }
}
```

There are two identifiers in this value:

1. The items that were selected.
2. The source key for the linked content source.

#### Add the enhancer

Uniform provides an enhancer so you don't need to write the API
calls to Acoustic Content to retrieve data for items.

1. Add the following npm packages to your front-end application:

   ```
   @uniformdev/canvas-acoustic
   ```
2. In a text editor, open the file where you retrieve the
   composition definition from Uniform.

   > **About this step:**
   >
   > You are looking for the code calls the async function
   > `getComposition`. The code below assumes the
   > object returned is set in a variable `composition`.
3. Add the following import statements:

   ```javascript
   import {
     AcousticClientList,
     CANVAS_ACOUSTIC_MULTI_CONTENT_ITEM_PARAMETER_TYPES,
     createAcousticClient,
     createAcousticContentItemEnhancer,
   } from '@uniformdev/canvas-acoustic';
   ```
4. Add the following code:

   ```javascript
   const client = createAcousticClient({
     apiUrl: '!!! YOUR ACOUSTIC CONTENT API URL !!!',
   });
   const previewClient = createAcousticClient({
     apiUrl: '!!! YOUR ACOUSTIC CONTENT PREVIEW API URL !!!',
     auth: {
       apiKey: '!!! YOUR ACOUSTIC CONTENT API KEY !!!'
     },
   });
   ```

> **About the preview API URL:**
>
> To determine the appropriate value for the preview API URL,
> see the [preview content](https://developer.goacoustic.com/acoustic-content/docs/preview-content)
> section in the Acoustic Content documentation.

> **About this step:**
>
> We recommend you moving the Acoustic Content credentials to
> environment variables rather than hard-coding them in the
> front-end app.

1. Add the following code:

   ```javascript
   const clients = new AcousticClientList({ 
     client,
     previewClient
   });
   const acousticEnchancer = createAcousticContentItemEnhancer({ clients });
   ```
2. Add the following code:

   ```javascript
   await enhance({
     composition,
     enhancers: new EnhancerBuilder().parameterType(
       CANVAS_ACOUSTIC_MULTI_CONTENT_ITEM_PARAMETER_TYPES, 
       acousticEnchancer,
     ),
     context: {},
   });
   ```

> **About this step:**
>
> This registers the enhancer to be used for any occurrence
> of the Acoustic Content Multi Item parameter.

> **Next steps:**
>
> Now, the parameter value in the composition is mutated to
> include the field values for the selected Acoustic Content items
> (instead of just being identifiers).
