# User choices import

Use this feature to UPSERT or DELETE [user\_choices](https://developer.mediarithmics.io/advanced-usages/data-privacy-compliance/user-choices) in your datamart.&#x20;

## How-to

Use the [bulk import ](https://developer.mediarithmics.io/data-streams/data-ingestion/bulk-processing)endpoints to create a [document import](https://developer.mediarithmics.io/data-streams/data-ingestion/bulk-processing/..#document-import) with the`USER_CHOICE`document type and `APPLICATION_X_NDJSON` mime type. Only `ndjson` data is supported for user choices.

Then, create an[ execution ](https://developer.mediarithmics.io/data-streams/data-ingestion/bulk-processing/..#create-an-execution)with your user choice import commands formatted in `ndjson` .

### User choice import command

Each line in the uploaded file can have the following properties:

| field             | type                   | description                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ----------------- | ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| operation         | Enum                   | Either `UPSERT` or `DELETE`                                                                                                                                                                                                                                                                                                                                                                                                               |
| compartment\_id   | String (Optional)      | The Compartment ID, acting as a user [identifier ](https://developer.mediarithmics.io/user-points#user-identifiers)in correlation with `user_account_id`                                                                                                                                                                                                                                                                                  |
| user\_account\_id | String (Optional)      | The User Account ID, acting as an [identifier](https://developer.mediarithmics.io/user-points/user-profiles#user-profile-object) in correlation with `compartment_id`                                                                                                                                                                                                                                                                     |
| email\_hash       | String (Optional)      | The Email Hash, acting as an [identifier](https://developer.mediarithmics.io/user-points#user-identifiers)                                                                                                                                                                                                                                                                                                                                |
| user\_agent\_id   | String (Optional)      | The User Agent ID, acting as an [identifier](https://developer.mediarithmics.io/user-points#user-identifiers)                                                                                                                                                                                                                                                                                                                             |
| force\_replace    | Boolean (Optional)     | <p>Mandatory when the operation is <code>UPSERT</code>.<br><br>If true, then the User Choice will be completely replaced by the object passed in the <code>user\_choice</code> field.</p><p><br>If false, the object passed in the <code>user\_choice</code> field will be merged with the existing User Choice of the UserPoint.</p>                                                                                                     |
| user\_choice      | JSON Object (Optional) | <p>Mandatory when operation is UPSERT. </p><p></p><p>This is a JSON Object representing the User Choice. </p><p>Please refer to the <a href="../../../../advanced-usages/data-privacy-compliance/user-choices">User choices page</a> for more </p><p>information.</p><p></p><p>Note that the <code>$processing\_id</code> field is always mandatory, and <code>$choice\_ts</code> is mandatory when operation is <code>UPSERT</code>.</p> |

### Example

```bash
# Create the document import
curl -X POST \
  https://api.mediarithmics.com/v1/datamarts/<DATAMART_ID>/document_imports \
  -H 'Authorization: <YOUR_API_TOKEN>' \
  -H 'Content-Type: application/json' \
  -d '{
	"document_type": "USER_CHOICE",
	"mime_type": "APPLICATION_X_NDJSON",
	"encoding": "utf-8",
	"name": "<YOUR_DOCUMENT_IMPORT_NAME>"
}'
```

```bash
# Create the execution
curl -X POST \
  https://api.mediarithmics.com/v1/datamarts/1162/document_imports/<DOCUMENT_IMPORT_ID>/executions \
  -H 'Authorization: <API_TOKEN>' \
  -H 'Content-Type: application/x-ndjson' \
  -d '{ 
        "operation": "UPSERT",
        "compartment_id": "<COMPARTMENT_ID>", 
        "user_account_id": "<USER_ACCOUNT_ID>",
        "force_replace": true,
        "user_choice": {
              "$processing_id": "<PROCESSING_ID>",
              "$choice_ts": "<CHOICE_TS>"
        }
      }'
```

{% hint style="success" %}
You can, of course, upload multiple user choices at once. Note the uploaded data is in `ndjson` format and not `json`. That means the different choices are not separated by commas, but by a line separator `\n`
{% endhint %}

{% hint style="warning" %}
When importing choices with identifiers, only one identifier is allowed per line. For example, you shouldn't specify the user agent ID if the Email Hash is already used in a line.&#x20;
{% endhint %}
