The vast majority of attributes are Strings that's why the Ubidots API provides some powerful filters for Strings.
Field Type: Text
Filters Available: exact (=
) (case sensitive), iexact
(case insensitive), contains
, icontains
(case insensitive), startswith
, istartswith
(case sensitive), endswith
, iendswith
(case insensitive), in
(case sensitive), isnull
exact / iexact
Filters for an exact match of of the String.
GET https://industrial.api.ubidots.com/api/v2.0/variables/?name=Productive%20Plants
//Returns Array 'results' with Variable name exactly matching "Productive Plants"
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"name": "Productive Plants",
...
}
]
}
//Case Insensitive
GET https://industrial.api.ubidots.com/api/v2.0/variables/?name__iexact=Productive%20plants
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"name": "Productive Plants",
...
]
}
Case Sensitivity
Please note that case insensitivity (A = a) can be used for filtering by simply adding the letter "i" in front of the following filters:
exact
,contains
,startswith
,endswith
.
contains / icontains
Filters for a substring.
GET https://industrial.api.ubidots.com/api/v2.0/variables/?name__contains=plants
//Returns en empty 'results' Array because it's case sensitive
{
"count": 0,
"next": null,
"previous": null,
"results": []
}
GET https://industrial.api.ubidots.com/api/v2.0/variables/?name__icontains=plants
//Returns Array 'results' with matching Variables because of case INsensitivity
{
"count": 2,
"next": null,
"previous": null,
"results": [
{
"name": "Medium Plants",
...
},
{
"name": "Productive Plants",
...
]
}
startswith / istartswith
Filters for strings starting with the provided string.
GET https://industrial.api.ubidots.com/api/v2.0/variables/?name__startswith=prod
//Returns empty Array because prod != Prod
{
"count": 0,
"next": null,
"previous": null,
"results": []
}
GET https://industrial.api.ubidots.com/api/v2.0/variables/?name__istartswith=prod
//Returns Array 'results' with matching Variable because of case INsensitivity (prod = Prod)
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"name": "Productive Plants",
...
}
]
}
The same logic applies analogically to __endswith
and __iendswith
which filter for strings ending with a certain substring.
The __in
has the same logic as described in the Id section.
The __isnull
filter can be applied to a Text as described in the Boolean section.