> For the complete documentation index, see [llms.txt](https://developer.mediarithmics.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.mediarithmics.io/data-ingestion/bulk-processing/imports/segments.md).

# Segments import

Use this feature to add or remove [UserPoint](/user-points.md) from [segments](/user-points/segments.md).

## How-to

1. Use the [bulk import ](/data-ingestion/bulk-processing.md)endpoints to create a [document import](/data-ingestion/bulk-processing.md#document-import) with the`USER_SEGMENT`document type and `APPLICATION_X_NDJSON` or `TEXT_CSV` mime type.
2. &#x20;Create an[ execution ](/data-ingestion/bulk-processing.md#create-an-execution)with your user segment commands formatted in `ndjson` or `csv` depending on the mime type you chose.

### User segment command

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

| operation                 | Enum (Mandatory)               | Either `UPDATE` or `DELETE`                                                                                                                                     |
| ------------------------- | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| compartment\_id           | String (Optional)              | The Compartment ID acting as a [user identifier](/user-points.md#user-identifiers) in correlation with the user account ID                                      |
| user\_account\_id         | String (Optional)              | The User Account ID acting as a [user identifier](/user-points.md#user-identifiers) in correlation with the user account ID.                                    |
| email\_hash               | String (Optional)              | The Email Hash acting as a [user identifier](/user-points.md#user-identifiers).                                                                                 |
| user\_agent\_id           | String (Optional)              | The User Agent ID acting as a [user identifier](/user-points.md#user-identifiers).                                                                              |
| segment\_id               | String (Optional)              | The Id of the segment in which the User is inserted/deleted.                                                                                                    |
| segment\_ids              | List of strings (Optional)     | <p>The list of ids of segments in which the User is inserted/deleted. For instance<br><code>\["segment\_id\_1","segment\_id\_2"]</code></p>                     |
| segment\_technical\_name  | String (Optional)              | The technical name of the segment in which the User is inserted/deleted.                                                                                        |
| segment\_technical\_names | List of strings (Optional)     | <p>The list of technical names of segments in which the User is inserted/deleted. For instance<br><code>\["technical\_name\_1","technical\_name\_2"]</code></p> |
| expiration\_duration      | Integer (Mandatory)            | The number of minutes before the user will be removed from the segment. 0 means that the User will never leave the segment                                      |
| expiration\_ts            | Number (Optional)              | The timestamp of the expiration date of the User in the segment. A value of 0 means that the user will never leave the segment                                  |
| data\_bag                 | Escaped JSON String (Optional) | The data bag associated with the user/segment relationship                                                                                                      |

### 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_SEGMENT",
	"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/<DATAMART_ID>/document_imports/<DOCUMENT_IMPORT_ID>/executions \
  -H 'Authorization: <API_TOKEN>' \
  -H 'Content-Type: application/x-ndjson' \
  -d '{ 
        "operation": "UPDATE",
        "expiration_duration": <INTEGER>,
        "compartment_id": "<COMPARTMENT_ID>", 
        "user_account_id": "<USER_ACCOUNT_ID>",
        "segment_id": "<SEGMENT_ID>"
      }'
```

{% hint style="success" %}
You can have UPDATE and DELETE operations in the same file upload.

Please note, if not using `csv`, that the uploaded data is in `ndjson` and not `json`. That means the different profiles are not separated by commas, but by a line separator `\n`
{% endhint %}

{% hint style="success" %}
Use segment\_ids or segment\_technical\_names if you need to handle multiple segments for a single user.&#x20;
{% 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 dynamically by asking a question.

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

```
GET https://developer.mediarithmics.io/data-ingestion/bulk-processing/imports/segments.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
