# Workflow

## Method & Permission

| API             | GET           | POST  | PUT | PATCH | DELETE |
| --------------- | ------------- | ----- | --- | ----- | ------ |
| Workflow List   | Admin, Member | Admin | -   | -     | -      |
| Workflow Detail | Admin, Member | -     | -   | Admin | Admin  |

## Workflow List

<mark style="color:blue;">`GET`</mark> `/tables/workflow/list/{level}/{sid}/{serializer}/`

This endpoint allows you to get a list of workflows.

#### Path Parameters

| Name       | Type   | Description        |
| ---------- | ------ | ------------------ |
| level      | string | organization       |
| sid        | string | organization sid   |
| serializer | string | name, list, detail |

#### Query Parameters

| Name         | Type    | Description                                                                                    |
| ------------ | ------- | ---------------------------------------------------------------------------------------------- |
| table\_\_sid | boolean | The workflow is table specific, provide table\_\_sid to query the workflow specific to a table |

#### Headers

| Name  | Type   | Description          |
| ----- | ------ | -------------------- |
| token | string | Authentication token |

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

```yaml
# serializer = name
{
    "page_size": 10,
    "page_number": 1,
    "page_count": 1,
    "count": 3,
    "next": null,
    "previous": null,
    "add_permission": true,
    "results": [
        {
            "sid": "xxx",
            "name": "Plan an experiment"
        },
        ...
    ]
}
# serializer = list
{
    "page_size": 10,
    "page_number": 1,
    "page_count": 1,
    "count": 3,
    "next": null,
    "previous": null,
    "add_permission": true,
    "results": [
        {
            "sid": "xxx",
            "name": "Plan an experiment",
            "parent": null,
            "number_of_steps": 5,
            "is_archived": false,
            "table": {
                "sid": "xxx",
                "name": "experiments"
            },
            "change_permission": true
        },
        ...
    ]
}
# serializer = detail
{
    "page_size": 10,
    "page_number": 1,
    "page_count": 1,
    "count": 3,
    "next": null,
    "previous": null,
    "add_permission": true,
    "results": [
        {
            "sid": "xxx",
            "table": {
                "sid": "xxx",
                "name": "experiments"
            },
            "parent": null,
            "name": "Plan an experiment",
            "description": "This workflow describes what you need to do before start an experiment.",
            "number_of_steps": 5,
            "is_archived": false,
            "updated_by": "xxx",
            "date_updated": "2020-02-10T03:02:27.172051Z",
            "date_created": "2020-02-10T03:02:27.171200Z",
            "change_permission": true
        },
        ...
    ]
}
```

{% endtab %}
{% endtabs %}

## Workflow List

<mark style="color:green;">`POST`</mark> `/tables/workflow/list/{level}/{sid}/{serializer}/`

This endpoint allows you to create a list of workflows

#### Path Parameters

| Name       | Type   | Description      |
| ---------- | ------ | ---------------- |
| level      | string | organization     |
| sid        | string | organization sid |
| serializer | string | detail           |

#### Query Parameters

| Name         | Type   | Description |
| ------------ | ------ | ----------- |
| table\_\_sid | string |             |

#### Headers

| Name  | Type   | Description          |
| ----- | ------ | -------------------- |
| token | string | Authentication token |

#### Request Body

| Name        | Type   | Description |
| ----------- | ------ | ----------- |
| parent      | number |             |
| name        | string |             |
| description | string |             |

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

```yaml
{
    "sid": "xxx",
    "table": {
        "sid": "xxx",
        "name": "experiments"
    },
    "parent": null,
    "name": "Plan an experiment",
    "description": "This workflow describes what you need to do before start an experiment.",
    "number_of_steps": 5,
    "is_archived": false,
    "updated_by": "xxx",
    "date_updated": "2020-02-10T03:02:27.172051Z",
    "date_created": "2020-02-10T03:02:27.171200Z",
    "change_permission": true
}
```

{% endtab %}

{% tab title="406 " %}

```
Missing table__sid in get parameters
```

{% endtab %}
{% endtabs %}

## Workflow Detail

<mark style="color:blue;">`GET`</mark> `/tables/workflow/detail/{sid}/`

#### Path Parameters

| Name | Type   | Description |
| ---- | ------ | ----------- |
| sid  | string |             |

#### Headers

| Name  | Type   | Description |
| ----- | ------ | ----------- |
| token | string |             |

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

```yaml
{
    "sid": "xxx",
    "table": {
        "name": "xxx",
        "sid": "xxx"
    },
    "parent": null,
    "name": "xxx",
    "description": "xxx",
    "number_of_steps": 4,
    "is_archived": false,
    "updated_by": "xxx",
    "date_updated": "2019-07-03T06:15:01.667876Z",
    "date_created": "2019-06-29T07:31:31.706125Z",
    "change_permission": true
}
```

{% endtab %}
{% endtabs %}

## Workflow Detail

<mark style="color:purple;">`PATCH`</mark> `/tables/workflow/detail/{sid}/`

Operation level: **Admin**

#### Path Parameters

| Name | Type   | Description |
| ---- | ------ | ----------- |
| sid  | string |             |

#### Query Parameters

| Name           | Type   | Description                                                                             |
| -------------- | ------ | --------------------------------------------------------------------------------------- |
| trigger\_\_sid | string | pass trigger\_\_sid in query as the row sid to trigger the workflow and update variable |
| event          | string | pass event in query to update execution log, work together with trigger\_\_sid          |

#### Headers

| Name  | Type   | Description |
| ----- | ------ | ----------- |
| token | string |             |

#### Request Body

| Name           | Type    | Description                                                                       |
| -------------- | ------- | --------------------------------------------------------------------------------- |
| parent         | number  |                                                                                   |
| name           | string  |                                                                                   |
| description    | string  |                                                                                   |
| is\_archived   | boolean |                                                                                   |
| workflow\_data | object  | additional data to update the execution, work together with trigger\_\_sid        |
| variables      | object  | additional variable to parse the workflow data, work together with trigger\_\_sid |

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

```yaml
{
    "sid": "xxx",
    "table": {
        "name": "xxx",
        "sid": "xxx"
    },
    "parent": null,
    "name": "xxx",
    "description": "xxx",
    "number_of_steps": 4,
    "is_archived": false,
    "updated_by": "xxx",
    "date_updated": "2019-07-03T06:15:01.667876Z",
    "date_created": "2019-06-29T07:31:31.706125Z",
    "change_permission": true
}
```

{% endtab %}
{% endtabs %}

## Workflow Detail

<mark style="color:red;">`DELETE`</mark> `/tables/workflow/detail/{sid}/`

#### Path Parameters

| Name | Type   | Description |
| ---- | ------ | ----------- |
| sid  | string |             |

#### Headers

| Name  | Type   | Description |
| ----- | ------ | ----------- |
| token | string |             |

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

```
{}
```

{% endtab %}
{% endtabs %}
