> ## 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.

# REST services

> REST API reference for Atoti Limits, covering the Swagger UI, CRUD endpoints for limits and limit structures, file upload, workflow approval and expiry, and process-instance audit history

Atoti Limits provides several REST services for developers to utilize in the Atoti UI and Atoti Server instance communication and to customize the business logics.

## Swagger UI

The [Swagger](https://swagger.io/) UI is the easiest way to execute REST requests for Atoti Limits. All Atoti Limits endpoints are available on this UI, which is located at `{base-url/swagger-ui/index.html}`.

<Note>
  Swagger is **disabled** by default but you can enable it by starting Atoti Limits with the property `springdoc.swagger-ui.enabled=true`. This property is also configurable in [application.yml](../user-ref/properties/property-files/application-yml).
</Note>

Here’s what the Swagger UI looks like:

<Frame>
  <img src="https://mintcdn.com/activeviam/xdqxmncf8zYRCehD/atoti-intelligence/workflows/limits/6.1/images/swagger-ui.png?fit=max&auto=format&n=xdqxmncf8zYRCehD&q=85&s=6d6c7a12dc1576459f4b4a9c0b681830" alt="Swagger UI" width="1575" height="876" data-path="atoti-intelligence/workflows/limits/6.1/images/swagger-ui.png" />
</Frame>

Let’s say you want to execute a request on the evaluate endpoint. You can use the “Try it out” button to do so:

<Frame>
  <img src="https://mintcdn.com/activeviam/xdqxmncf8zYRCehD/atoti-intelligence/workflows/limits/6.1/images/swagger-ui-evaluate-endpoint.png?fit=max&auto=format&n=xdqxmncf8zYRCehD&q=85&s=d94787e68addb8b7847abceb19b8cd9e" alt="Swagger Evaluate" width="1543" height="849" data-path="atoti-intelligence/workflows/limits/6.1/images/swagger-ui-evaluate-endpoint.png" />
</Frame>

## Limit breach and warning evaluation

For details, see the [On-demand limit evaluation](./evaluation-tasks#rest) section.

## Create/update new/existing limit structures

* REST endpoint: `/limits/rest/v2/limitDefinition/structure/save`
* Method: POST
* Example Endpoint: `http://localhost:3090/limits/rest/v2/limitDefinition/structure/save`
* Example body:

```json theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
[
  {
    "serverName": "FRTB",
    "comment": "Limit Comment",
    "group": "Limit Group",
    "referenceId": "id_1234",
    "name": "Limit Name",
    "cubeName": "StandardisedApproachCube",
    "exceptionWorkflow": "Exception",
    "limitChangesWorkflow": "FourEyes",
    "exceptionWorkflowParameters": {
      "Examiners": "USER_ROLES",
      "Approvers": "ROLE_MANAGERS"
    },
    "limitChangesWorkflowParameters": {
      "Examiners": "USER_ROLES",
      "Approvers": "ROLE_MANAGERS"
    },
    "measureName": "FX Risk Charge",
    "pollingFrequency": "EOD",
    "kpiType": "Less than...",
    "warningThreshold": 0.0,
    "scopeKeys": [
        "Book@Books@Booking"
        ]
  }
]
```

<Note>
  This endpoint serves as a convenience endpoint for creating or updating limit structures. If you want to explicitly create or update one, then you can do so by using the:

  * POST Create endpoint: `/limits/rest/v2/limitDefinition/structure/create`
  * PUT Update endpoint: `/limits/rest/v2/limitDefinition/structure/update`

  with the same JSON body as the `save` endpoint.
</Note>

## Create new or update existingfrom no limits

* REST endpoint: `/limits/rest/v2/limitDefinition/limits/save`
* Method: POST
* Example Endpoint: `http://localhost:3090/limits/rest/v2/limitDefinition/limits/save`
* Example body:

```json theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
[
  {
    "limitStructureId": 12345,
    "limitStructureReferenceId": "id_1234",
    "referenceId": "limit_1",
    "startDate": "2018-09-26",
    "limitType": "OFFICIAL",
    "scope": "Book@Books@Booking=Book 4",
    "limitValue": 4444.0
  }
]
```

## Upload a file of new limit structures

* REST endpoint: `/limits/rest/v2/limitDefinition/uploadStructures`
* Method: POST
* Example Endpoint: `http://localhost:3090/limits/rest/v2/limitDefinition/uploadStructures`
* Example body (text representation of binary file):

```
------WebKitFormBoundary0116TUm8HlznSV7v
Content-Disposition: form-data; name="file"; filename="<insert file name>.csv"
Content-Type: text/csv

------WebKitFormBoundary0116TUm8HlznSV7v--
```

## Upload a file of new limits

* REST endpoint: `/limits/rest/v2/limitDefinition/uploadLimits`
* Method: POST
* Example Endpoint: `http://localhost:3090/limits/rest/v2/limitDefinition/uploadLimits`
* Example body (text representation of binary file):

```
------WebKitFormBoundary0116TUm8HlznSV7v
Content-Disposition: form-data; name="file"; filename="<insert file name>.csv"
Content-Type: text/csv

------WebKitFormBoundary0116TUm8HlznSV7v--
```

* REST endpoint: `/limits/rest/v2/limitDefinition/export`
* Method: POST
* Example Endpoint: `http://localhost:3090/limits/rest/v2/limitDefinition/export`
* Example body:

```json theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
{
   "orderName":"current_limits_table"
}
```

## Check if the logged-in user can start the workflow

* Endpoint: `/limits/rest/v2/limitDefinition/canStart`
* Method: GET
* Example Endpoint: `http://localhost:3090/limits/rest/v2/limitDefinition/canStart`

## Expire the workflow

* Endpoint: `/limits/rest/v2/limitDefinition/expire`
* Method: POST
* Example Endpoint: `http://localhost:3090/limits/rest/v2/limitDefinition/expire`
* Example body:

```json theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
{
  "limitIds": [
    -2061128317,
    -52040286,
    1317705186
  ],
  "asOfDate": "2018-09-28"
}
```

## Approve the workflow

* Endpoint: `/limits/rest/v2/limit-process-instance/approve`
* Method: PUT
* Example Endpoint: `http://localhost:3090/limits/rest/v2/limit-process-instance/approve`
* Example body:

```json theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
{
    "definitionName": "GIRR Risk Charge Demo",
    "exportStatusDetails": null,
    "comment": null,
    "serverName": "FRTB",
    "asOfDate": [
        2018,
        9,
        28
    ]
}
```

## Workflow audit history

### Breach management history

* Endpoint: `/limits/rest/v2/limit-process-instance/process-instance-history/{key}::EXCEPTION`
* Method: GET
* Example Endpoint: `/limits/rest/v2/limit-process-instance/process-instance-history/-1749471693::EXCEPTION`
* Example body:

```json theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
{
[
  {
    "type": "com.activeviam.limits.workflow.model.instance.dto.LimitsProcessInstance",
    "object": {
      "workflowType": null,
      "workflowParameters": null,
      "category": null,
      "asOfDate": "2018-09-28",
      "definitionName": "-1749471693",
      "status": null,
      "user": null,
      "comment": null,
      "limitDefinitionDto": {
        "group": "Operational Limits",
        "id": "p.1.2 of RAF",
        "name": "Equity Vega Limits",
        "comment": "Structuring",
        "validFrom": "2018-09-26",
        "validTo": null,
        "frequencyType": "OFFICIAL",
        "pollingFrequency": "INTRADAY",
        "currency": "USD",
        "kpiType": "Greater Than",
        "limitValue": 200000.0,
        "absoluteValueInd": true,
        "warningThreshold": 80,
        "measureName": "Equity Vega Sensitivities",
        "precedence": 0,
        "scope": {
          "Risk Measure@Risk Measures@Risk": [
            "Vega"
          ],
          "Equity Market Cap Category@Equity Market Cap Category@Market Data": [
            "Small"
          ],
          "Risk Factor@Risk Factors@Risk": [
            "*"
          ],
          "Desk@Desks@Booking": [
            "Structuring"
          ]
        },
        "scopeArray": null,
        "limitStatus": "APPROVED",
        "exceptionWorkflow": "Exception",
        "limitChangesWorkflow": "StraightThrough",
        "limitChangesWorkflowParameters": null,
        "cubeName": "StandardisedApproachCube",
        "serverName": "FRTB",
        "systemState": "N/A",
        "timeStamp": [
          2022,
          10,
          5,
          15,
          17,
          22,
          261541000
        ],
        "exceptionStatus": "N/A",
        "exceptionComment": "N/A",
        "exceptionCategory": "N/A",
        "hashKey": -1749471693,
        "draftLimitStatus": "N/A"
      },
      "exceptionCategory": null,
      "exceptionComment": null,
      "type": "EXCEPTION",
      "limitsKey": -1749471693
    },
    "key": "-1749471693::EXCEPTION",
    "timestamp": 1664997493.325000000,
    "status": "BREACHED",
    "user": "admin",
    "comment": "",
    "processDefinitionName": "limit-process-instance.exception",
    "action": "EVALUATE"
  },
  {
    "type": "com.activeviam.limits.workflow.model.instance.dto.LimitsProcessInstance",
    "object": {
      "workflowType": "Exception",
      "workflowParameters": null,
      "category": null,
      "asOfDate": "2018-09-28",
      "definitionName": "-1749471693",
      "status": null,
      "user": null,
      "comment": null,
      "limitDefinitionDto": {
        "group": "Operational Limits",
        "id": "p.1.2 of RAF",
        "name": "Equity Vega Limits",
        "comment": "Structuring",
        "validFrom": "2018-09-26",
        "validTo": null,
        "frequencyType": "OFFICIAL",
        "pollingFrequency": "INTRADAY",
        "currency": "USD",
        "kpiType": "Greater Than",
        "limitValue": 200000.0,
        "absoluteValueInd": true,
        "warningThreshold": 80,
        "measureName": "Equity Vega Sensitivities",
        "precedence": 0,
        "scope": {
          "Risk Measure@Risk Measures@Risk": [
            "Vega"
          ],
          "Equity Market Cap Category@Equity Market Cap Category@Market Data": [
            "Small"
          ],
          "Risk Factor@Risk Factors@Risk": [
            "*"
          ],
          "Desk@Desks@Booking": [
            "Structuring"
          ]
        },
        "scopeArray": null,
        "limitStatus": "APPROVED",
        "exceptionWorkflow": "Exception",
        "limitChangesWorkflow": "StraightThrough",
        "limitChangesWorkflowParameters": null,
        "cubeName": "StandardisedApproachCube",
        "serverName": "FRTB",
        "systemState": "N/A",
        "timeStamp": [
          2022,
          10,
          5,
          15,
          17,
          22,
          261541000
        ],
        "exceptionStatus": "BREACHED",
        "exceptionComment": "N/A",
        "exceptionCategory": "N/A",
        "hashKey": -1749471693,
        "draftLimitStatus": "N/A"
      },
      "exceptionCategory": null,
      "exceptionComment": null,
      "type": "EXCEPTION",
      "limitsKey": -1749471693
    },
    "key": "-1749471693::EXCEPTION",
    "timestamp": 1664997544.953981000,
    "status": "BREACHED",
    "user": "admin",
    "comment": "",
    "taskName": "BREACHED",
    "action": "EVALUATE"
  },
]

}
```

### Limit management history

* Endpoint: `/limits/rest/v2/limit-process-instance/process-instance-history/{key}::CREATION`
* Method: GET
* Example Endpoint: `/limits/rest/v2/limit-process-instance/process-instance-history/-174947169::CREATION`
* Example body:

```json theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
{
[
  {
    "type": "com.activeviam.limits.workflow.model.instance.dto.LimitsProcessInstance",
    "object": {
      "workflowType": "StraightThrough",
      "workflowParameters": {},
      "category": null,
      "asOfDate": "2018-09-28",
      "definitionName": "-1749471693",
      "status": "APPROVED",
      "user": null,
      "comment": null,
      "limitDefinitionDto": {
        "group": "Operational Limits",
        "id": "p.1.2 of RAF",
        "name": "Equity Vega Limits",
        "comment": "Structuring",
        "validFrom": "2018-09-26",
        "validTo": null,
        "frequencyType": "OFFICIAL",
        "pollingFrequency": "INTRADAY",
        "currency": "USD",
        "kpiType": "Greater Than",
        "limitValue": 200000.0,
        "absoluteValueInd": true,
        "warningThreshold": 80,
        "measureName": "Equity Vega Sensitivities",
        "precedence": 0,
        "scope": {
          "Risk Measure@Risk Measures@Risk": [
            "Vega"
          ],
          "Equity Market Cap Category@Equity Market Cap Category@Market Data": [
            "Small"
          ],
          "Risk Factor@Risk Factors@Risk": [
            "*"
          ],
          "Desk@Desks@Booking": [
            "Structuring"
          ]
        },
        "scopeArray": null,
        "limitStatus": "APPROVED",
        "exceptionWorkflow": "Exception",
        "limitChangesWorkflow": "StraightThrough",
        "limitChangesWorkflowParameters": null,
        "cubeName": "StandardisedApproachCube",
        "serverName": "FRTB",
        "systemState": "N/A",
        "timeStamp": [
          2022,
          10,
          5,
          15,
          17,
          22,
          261541000
        ],
        "exceptionStatus": "N/A",
        "exceptionComment": "N/A",
        "exceptionCategory": "N/A",
        "hashKey": -1749471693,
        "draftLimitStatus": "N/A"
      },
      "exceptionCategory": null,
      "exceptionComment": null,
      "type": "CREATION",
      "limitsKey": -1749471693
    },
    "key": "-1749471693::CREATION",
    "timestamp": 1664997446.178000000,
    "status": "APPROVED",
    "user": "admin",
    "comment": null,
    "processDefinitionName": "limit-process-instance.straight-through",
    "action": "UPLOAD"
  }
]

}
```

## Display decision buttons for a given limit’s status

* Endpoint: `/limits/rest/v2/limit-process-instance/getWorkflowUIActions`
* Method: GET
* Example Endpoint: `http://localhost:3090/limits/rest/v2/limit-process-instance/getWorkflowUIActions?limitId=<limit's ID>`

## Execute workflow from decision button

* Endpoint: `/limits/rest/v2/limit-process-instance/executeWorkflow`
* Method: PUT
* Example Endpoint: `http://localhost:3090/limits/rest/v2/limit-process-instance/executeWorkflow`
* Example body:

```json theme={"languages":{"custom":["/engine/python-sdk/0.9/languages/pycon.tmLanguage.json"]}}
{
    "workflowKey": "APPROVED",
    "limitKey": -284478855
}
```
