You can sort the output of Oneflow API calls in a particular order by providing the sort=attribute-name as a query parameter with your request.

📘

Note:

The sort parameter is optional. If not specified, the system will return the result without any sorting.

Endpoints that support sorting

Currently, the following listing endpoints support sorting:

🚧

Note

Sorting is not currently supported for the Helpers endpoint.

To sort by multiple attributes, pass the attributes as a comma-separated list. In this case, the entities in the response will be sorted sequentially by each attribute in the list. See the example in the table below for the contracts/{contract-id}/files endpoint and the code example further in this chapter.

To sort in descending order, pass the attribute whose value you want to sort, with a hyphen in front of it. See the example in the table below for the contracts/{contract-id}/events endpoint and the code example further in this chapter.

EndpointValid sort attributesExamples
contractsname, state_updated_time, state, published_time?sort=state
workspacesname?sort=name
templatesname?sort=name
templates_typesname?sort=name
contracts/{contract-id}/filesname, type, id, extension?sort=extension,id,type
contracts/{contract-id}/eventscreated_time, id, type?sort=-id

📘

Note

If the attribute value is an empty string, the attribute will be placed at the top of the sorted list. For attributes whose values ​​are null, the attributes will be placed at the end of the sorted list.

Examples

Sort contract files by type

Request example

Below is an example that sorts contract files by type:

curl --location --request GET 'https://api.oneflow.com/v1/contracts/10015/files?sort=type&offset=2&limit2' \
--header 'content-type: application/json' \
--header 'x-oneflow-api-token: API_TOKEN' \
--header 'x-oneflow-user-email: USER_EMAIL'

Expected response

Below is an example of a response to sorting contract files by type:

{
  "_links": {
    "next": {
      "href": null
    },
    "previous": {
      "href": "https://api.oneflow.com/v1/contracts/10015/files?sort=type&offset=0&limit2"
    },
    "self": {
      "href": "https://api.oneflow.com/v1/contracts/10015/files?sort=type&offset=2&limit2"
    }
  },
  "count": 4,
  "data": [
    {
      "extension": "pdf",
      "id": 140256,
      "name": "test",
      "type": "attachment"
    },
    {
      "extension": "png",
      "id": 140257,
      "name": "public-api-contract-get",
      "type": "attachment"
    },
    {
      "extension": "pdf",
      "id": 1,
      "name": "Contract",
      "type": "contract"
    },
    {
      "extension": "pdf",
      "id": 140255,
      "name": "Meetingnotes",
      "type": "pdf"
    }
  ]
}

Sort contract files by multiple attributes

Request example

Below is an example that sorts contract files by type and name:

curl --location --request GET 'https://api.oneflow.com/v1/contracts/10015/files?sort=type,name&offset=2&limit2' \
--header 'content-type: application/json' \
--header 'x-oneflow-api-token: API_TOKEN' \
--header 'x-oneflow-user-email: USER_EMAIL'

Expected response

Below is an example of a response to sorting contract files by type and name:

{
  "_links": {
    "next": {
      "href": null
    },
    "previous": {
      "href": "https://api.oneflow.com/v1/contracts/10015/files?sort=type,name&offset=0&limit2"
    },
    "self": {
      "href": "https://api.oneflow.com/v1/contracts/10015/files?sort=type,name&offset=2&limit2"
    }
  },
  "count": 4,
  "data": [
    {
      "extension": "png",
      "id": 140257,
      "name": "public-api-contract-get",
      "type": "attachment"
    },
    {
      "extension": "pdf",
      "id": 140256,
      "name": "test",
      "type": "attachment"
    },
    {
      "extension": "pdf",
      "id": 1,
      "name": "Contract",
      "type": "contract"
    },
    {
      "extension": "pdf",
      "id": 140255,
      "name": "Meetingnotes",
      "type": "pdf"
    }
  ]
}

Sort contract files in descending order

Request example

Below is an example that sorts contract files by id in descending order:

curl --location --request GET 'https://api.oneflow.com/v1/contracts/10015/files?sort=-id&offset=2&limit2' \
--header 'content-type: application/json' \
--header 'x-oneflow-api-token: API_TOKEN' \
--header 'x-oneflow-user-email: USER_EMAIL'

Expected response

Below is an example of a response to sorting contract files by id in descending order:

{
  "_links": {
    "next": {
      "href": null
    },
    "previous": {
      "href": "https://api.oneflow.com/v1/contracts/10015/files?sort=type,name&offset=0&limit2"
    },
    "self": {
      "href": "https://api.oneflow.com/v1/contracts/10015/files?sort=type,name&offset=2&limit2"
    }
  },
  "count": 4,
  "data": [
    {
      "extension": "png",
      "id": 140257,
      "name": "public-api-contract-get",
      "type": "attachment"
    },
    {
      "extension": "pdf",
      "id": 140256,
      "name": "test",
      "type": "attachment"
    },
    {
      "extension": "pdf",
      "id": 140255,
      "name": "Meetingnotes",
      "type": "pdf"
    },
    {
      "extension": "pdf",
      "id": 1,
      "name": "Contract",
      "type": "contract"
    }
  ]
}