# Cases

**Cases** represent instances of your process templates. For example, if you have a process template called **Purchase Order Approval**, a case would be a specific purchase order that needs to be approved.

In Seliom's API, cases also receive the name of **Process Instances.**

{% hint style="danger" %}
Dont forget to include the **Authorization** and **X-Organization** headers in every request. They have been omitted from these endpoints for brevity.&#x20;
{% endhint %}

## Index

<mark style="color:blue;">`GET`</mark> `https://api.seliom.com/process_monitor/process_instances`

This endpoint retrieves all the cases that the user has permissions to see.

#### Query Parameters

| Name            | Type   | Description                                                                 |
| --------------- | ------ | --------------------------------------------------------------------------- |
| sort\_by        | string | Sort the resulting cases by: status, newest, oldest.                        |
| created\_before | string | Date in ISO 8601 to filter by.                                              |
| created\_after  | string | Date in ISO 8601 to filter by.                                              |
| status          | array  | Array of statuses to filter by: running, error, stopped, completed, paused. |
| process\_type   | array  | Array of UUIDs of the process templates to filter by                        |
| cursor          | string | Cursor used for pagination                                                  |

{% tabs %}
{% tab title="200 Process instances successfully retrieved." %}

```
{
    "processes": [
        "name": "My first time-off request",
        "created_at": "2021-02-22 18:37:25 UTC",
        "uuid": "23d6ff0b-717c-4712-b988-ab3e5c9732f3",
        "completed_date": null,
        "status": "running",
        "sequential_id": 1,
        "process_template": {
            "name": "Time-off Requests",
            "uuid": "5c7549b6-3f7b-4c96-8346-141326da5cf0",
            "launchable": true,
            "resource_type": "process",
            "automated": true
        }, 
        "launcher" : {
            "first_name": "Clark",
            "last_name": "Kent",
            "uuid": "3cd4ca21-fa4d-4bed-9217-fb495c748d0c"
        }
    ],
    "next_cursor": null,
    "prev_cursor": null, 
    "total": 1,
    "limit": 15,
    "page": 1
}

```

{% endtab %}
{% endtabs %}

## Show Case

<mark style="color:blue;">`GET`</mark> `https://api.seliom.com/process_monitor/process_instances/:process_instance_uuid`

This endpoint retrieves a specific case and the permissions your user has for it.

#### Path Parameters

| Name                    | Type   | Description                  |
| ----------------------- | ------ | ---------------------------- |
| process\_instance\_uuid | string | UUID of the process instance |

{% tabs %}
{% tab title="200 Process instance successfully retrieved." %}

```
{
    "process_instance": {
        "name": "My first time-off request",
        "created_at": "2021-02-22 18:37:25 UTC",
        "uuid": "23d6ff0b-717c-4712-b988-ab3e5c9732f3",
        "completed_date": null,
        "status": "running",
        "sequential_id": 1,
        "process_template": {
            "name": "Time-off Requests",
            "uuid": "5c7549b6-3f7b-4c96-8346-141326da5cf0",
            "launchable": true,
            "resource_type": "process",
            "automated": true
        }, 
        "launcher" : {
            "first_name": "Clark",
            "last_name": "Kent",
            "uuid": "3cd4ca21-fa4d-4bed-9217-fb495c748d0c"
        }
    },
    "permissions": [
        "Edit tasks",
        "Perform actions",
        "Delete instance",
        "Edit comments",
        "View process instance",
        "Manage case permissions",
        "Rollback case"
    ]
}
```

{% endtab %}

{% tab title="403 Not allowed to see the process instance requested." %}

```
{
    "message": "You do not have permissions to view this process instance"
}
```

{% endtab %}

{% tab title="404 Process instance not found" %}

```
{
    "message": "Process instance not found"
}
```

{% endtab %}
{% endtabs %}

## List Case Documents

<mark style="color:blue;">`GET`</mark> `https://api.seliom.com/process_monitor/process_instances/:process_instance_uuid/documents`

This endpoint retrieves all task submissions associated to a case that contain documents.

#### Path Parameters

| Name                    | Type   | Description                  |
| ----------------------- | ------ | ---------------------------- |
| process\_instance\_uuid | string | UUID of the process instance |

{% tabs %}
{% tab title="200 Process instance documents successfully retrieved." %}

```
{
    "docs": [
        {
            "id": "a340197d-7eab-49d5-9880-1da29fefaa35",
            "status": "completed",
            "assignee_type": "member",
            "member": {
                "first_name": "Clark",
                "last_name": "Kent",
                "uuid": "23d6ff0b-717c-4712-b988-ab3e5c9732f3"
            },
            "task_definition": {
                 "id": "cade268a-443e-44d8-9c71-667079bb7ac5",
                 "name": "Upload customer documentation",
                 "task_type": "task"
            },
            "documents_info": [
                "field_name": "Customer documents",
                "content": {
                   "type": "attachment",
                   "files": [
                       {
                           "originalName": "mydocs.pdf",
                           "storageName": "cade268a-443e-44d8-9c71-667079bb7ac5/1572657277933_mydocs.pdf"
                       }
                   ]
                }
            ]
        }
    ]
}
```

{% endtab %}
{% endtabs %}

## Create New Case

<mark style="color:green;">`POST`</mark> `https://api.seliom.com/process_instances`

This endpoint creates a new case based on a given process template.

#### Request Body

| Name                    | Type   | Description                                                                            |
| ----------------------- | ------ | -------------------------------------------------------------------------------------- |
| label                   | string | Label for the new case. Required if it has not been automated in the process template. |
| submission\_elements    | object | Form elements required to create a case for the given process template                 |
| process\_template\_uuid | string | UUID of the process template                                                           |

{% tabs %}
{% tab title="200 Case created successfully." %}

```
{
    "message": "Process launched successfully!",
    "process_instance_uuid": "972a4cb0-8f4e-43b3-9e54-99c952f8531e"
}
```

{% endtab %}

{% tab title="400 Label is required for the process template" %}

```
{
    "message": "Please provide a label"
}
```

{% endtab %}

{% tab title="401 User does not have necessary permissions" %}

```
{
    "message": "You do not have permissions to launch this process"
}
```

{% endtab %}
{% endtabs %}

## Pause Case

<mark style="color:orange;">`PUT`</mark> `https://api.seliom.com/process_monitor/process_instances/:process_instance_uuid/pause`

This endpoint pauses a process instance that is currently running.

{% tabs %}
{% tab title="200 " %}

```
{
    "message": "Your process instance has been paused"
}
```

{% endtab %}
{% endtabs %}

## Stop Case

<mark style="color:orange;">`PUT`</mark> `https://api.seliom.com/process_monitor/process_instances/:process_instance_uuid/stop`

This endpoint stops a process instance that is currently running.

{% tabs %}
{% tab title="200 " %}

```
{
    "message": "Your process instance has been stopped"
}
```

{% endtab %}
{% endtabs %}

## Resume Case

<mark style="color:orange;">`PUT`</mark> `https://api.seliom.com/process_monitor/process_instances/:process_instance_uuid/resume`

This endpoint resumes a process instance that was previously stopped or paused.

{% tabs %}
{% tab title="200 " %}

```
{
    "message": "Your process instance has been resumed"
}
```

{% endtab %}
{% endtabs %}

## Delete Case

<mark style="color:red;">`DELETE`</mark> `https://api.seliom.com/process_monitor/process_instances/:process_instance_uuid`

This endpoint permanently deletes a process instance.

{% tabs %}
{% tab title="200 " %}

```
{
    "message": "Your process instance has been deleted"
}
```

{% endtab %}
{% endtabs %}
