Sorting

Sorting is a useful tool to obtain items from the Ubidots API in the correct order.

In order to sort the result set simply add the query parameter sort_by=parameter

Sorting can be applied on the following attributes:

Parameter

Default Order

Description

label

Alphabetically

Label of entity

name

Alphabetically

Name of entity

username

Alphabetically

Username

created_at

Oldest first

Date entity was created

📘

Inverse Order

All parameters have a default sort order which can be inverted by prefixing a hyphen, e.g. -created_at or -label.

GET https://industrial.api.ubidots.com/api/v2.0/devices/?sort_by=label&fields=label

//Returns Array 'results' with all devices sorted alphabetically
{
    "count": 5,
    "next": null,
    "previous": null,
    "results": [
        {
            "label": "a_device"
        },
        {
            "label": "b_device"
        },
        {
            "label": "c_device"
        },
        {
            "label": "d_device"
        },
        {
            "label": "e_device"
        }
    ]
}

//Inversing the order
GET https://industrial.api.ubidots.com/api/v2.0/devices/?sort_by=-label&fields=label

//Returns Array 'results' with all devices sorted alphabetically
{
    "count": 5,
    "next": null,
    "previous": null,
    "results": [
        {
            "label": "e_device"
        },
        {
            "label": "d_device"
        },
        {
            "label": "c_device"
        },
        {
            "label": "b_device"
        },
        {
            "label": "a_device"
        }
    ]
}