> ## Documentation Index
> Fetch the complete documentation index at: https://docs.activeviam.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Load data through REST

> How to add or change limit structures and limits in a running Atoti Limits server through its REST endpoints, by uploading CSV files or sending JSON.

The Atoti Limits REST endpoints create and update limit structures and limits while the server is running. This page covers the endpoints to call, the order to load data in, the permissions the caller needs, and what happens when the data is invalid.

## When is data loaded through REST?

The [initial data load](https://docs.activeviam.com/atoti-intelligence/workflows/limits/6.2/dev/install/load-data/initial-data-load.md) reads CSV files or a database once, when Atoti Limits starts and connects to the Atoti Server instance. REST covers data that changes while the server is up. For example:

* An upstream system sends new or changed limit structures and limits.
* A program generates limits from cube data and sends the limits to the JSON endpoints. For example, a new counterparty appears in the cube and a default limit is created for it.

Incidents cannot be loaded through REST: incidents come from evaluation.

## In what order is data loaded?

Limit structures are loaded before limits, because creating a limit requires information from its limit structure. The as-of date can be set at any point. For more information, see [Date roll](https://docs.activeviam.com/atoti-intelligence/workflows/limits/6.2/dev/install/load-data/date-roll.md).

## How is a CSV file uploaded?

The upload is a `POST` request with a `multipart/form-data` body that contains the CSV file in a part named `file`:

| Endpoint | File format |
| - | - |
| `/limits/rest/v2/limitDefinition/uploadStructures` | [Limit structures](https://docs.activeviam.com/atoti-intelligence/workflows/limits/6.2/reference/input-files/limit_structures.md) |
| `/limits/rest/v2/limitDefinition/uploadLimits` | [Limits](https://docs.activeviam.com/atoti-intelligence/workflows/limits/6.2/reference/input-files/limits_approve.md) |

For example, to upload a limit structures file:

```bash theme={"languages":{"custom":["/engine/python-sdk/6.2/languages/pycon.tmLanguage.json"]}}
curl -X POST "http://<host>:<port>/limits/rest/v2/limitDefinition/uploadStructures" \
  <authentication options> \
  -F "file=@limit_structures.csv"
```

These endpoints do what the Upload button of the **Inventory** does. For the user interface, see [Upload a limit structure file](https://docs.activeviam.com/atoti-intelligence/workflows/limits/6.2/user-guide/upload-limit-structures.md) and [Upload a limit file](https://docs.activeviam.com/atoti-intelligence/workflows/limits/6.2/user-guide/upload-limits.md).

## How are limit structures and limits sent as JSON?

The objects go in a JSON body, with the `Content-Type` header set to `application/json`. All endpoints start with `/limits/rest/v2/limitDefinition`.

| Endpoint | Method | Purpose |
| - | - | - |
| `/structure/create` | `POST` | Creates a limit structure. Fails if the limit structure already exists. |
| `/structure/update` | `PUT` | Updates an existing limit structure. |
| `/structure/save` | `POST` | Creates the limit structure if it has no ID. Otherwise, updates it. |
| `/limits/save` | `POST` | Takes a list of limits. If any limit has no ID, Atoti Limits creates every limit in the list. Otherwise, Atoti Limits updates every limit in the list. |

The `create` and `update` endpoints suit callers that know which operation is needed: a mistake then fails instead of silently doing the other operation. The `save` endpoints suit data that does not show whether the object exists.

For the request bodies, see [REST APIs](https://docs.activeviam.com/atoti-intelligence/workflows/limits/6.2/reference/rest-apis.md).

## What permissions does the caller need?

The caller needs the same roles as a user of the UI:

| Operation | Role |
| - | - |
| Create limit structures | `ROLE_CREATE_STRUCTURE` |
| Update limit structures | `ROLE_UPDATE_STRUCTURE` |
| Create limits | `ROLE_CREATE_STRUCTURE_LIMIT` or `ROLE_CREATE_ANY_LIMIT` |
| Update limits | `ROLE_UPDATE_LIMIT` |

The `save` endpoints need the create role, the update role, or both, depending on whether each object is created or updated.

For what each role allows, see [Set up and start](https://docs.activeviam.com/atoti-intelligence/workflows/limits/6.2/user-guide/set-up-and-start.md).

The Atoti Limits server authenticates REST requests with its own security configuration, as it does for the UI. The caller authenticates as a user who holds the roles above.

## What happens when the data is invalid?

Atoti Limits validates the whole request before creating anything: if any row or item fails validation, the request is rejected and nothing is created. For the validation checks, see [Add custom validation](../../extend/custom-validation).

When validation fails, the response has the HTTP status `400` and a problem detail body. Its `action` property suggests how to fix the request, and its `validationErrors` property lists each error. For the error format, see [Add custom validation error handling](https://docs.activeviam.com/atoti-intelligence/workflows/limits/6.2/dev/extend/custom-validation/custom-validation-error-handling.md).

The default validation also rejects duplicates:

* A new limit structure with the same name as an existing one.
* A new limit that overlaps a live limit with the same structure, limit type, and scope, if the date ranges share at least one day. For the rule, see [Limit overlapping date validation](../../extend/custom-validation#limit-overlapping-date-validation).

To change an existing limit structure or limit, use the update or save endpoints, not create or upload.
