Create Variable

This endpoint creates a new Variable.

Request

To create a new Variable please make a POST request to the following URL:

HTTP MethodURL
POSThttps://industrial.api.ubidots.com/api/v2.0/variables/

To create a new Variable of a Device please make a POST request to the following URL:

HTTP MethodURL
POSThttps://industrial.api.ubidots.com/api/v2.0/devices/<device_key>/variables/

Query Parameters

ParameterTypeUseDescription
tokenStringAuthenticationAuthentication Token can optionally be sent as a query parameter.

Body Parameters

ParameterTypeRequired?Default ValueDescription
labelStringYesN/A (required)API label of Variable
nameStringNoSame as labelName of Variable
descriptionStringNo""Description of Variable
device<device_key>YesN/A (required)Key of Device (id or label)
tagsString ArrayNo[]Variable tags
propertiesObjectNo{}Variable properties. Allowed attributes: _icon, _color, minimum_value, maximum_value, isLocationVariable, _position, _scale, _offset
typeStringNorawVariable type. Allowed values raw (default) and synthetic
unitStringNo""Variable unit
syntheticExpressionStringNo""Synthetic Expression of Variable

👍

Properties Attributes Explained

_icon: Icon of Variable (FontAwesome)
_color: HEX, RGB and RGBA
minimum_value: Lowest value allowed (Dots posted with a value below the minimum_value will not be saved)
maximum_value: Highest value allowed (Dots posted with a value above the maximum_value will not be saved)
isLocationVariable: Boolean value if the Variable should be taken as location Variable (device location mode: specified)
_scale: All incoming values will be multiplied with this value
_offset: All incoming values will be summed with this value

Header

ParameterTypeDescription
X-Auth-TokenStringAuthentication Token of account
Content-TypeString (application/json)Content type of body
curl -X POST 'https://industrial.api.ubidots.com/api/v2.0/variables/' \
 -H 'Content-Type: application/json' \
 -H 'X-Auth-Token: oaXBo6ODhIjPsusNRPUGIK4d72bc73' \
 -d '{
    "label": "second-variable",
    "name": "Second Variable",
    "description": "my second variable",
    "device": "~first-device",
    "tags": ["blue", "yellow"],
    "properties": {},
    "icon": "pencil",
    "unit": "meters"   
}'
{
    "createdAt": "2019-12-18T14:38:38.354415Z",
    "syntheticExpression": "",
    "description": "my second variable",
    "device": {
        "id": "6e309da44fc8455a9cceb5aa",
        "label": "first-device",
        "name": "First Device",
        "url": "https://industrial.api.ubidots.com/api/v2.0/devices/6e309da44fc8455a9cceb5aa"
    },
    "icon": "pencil",
    "id": "5dfa39ee1a9ca53020c69391",
    "label": "var0",
    "lastActivity": null,
    "lastValue": {},
    "name": "var0",
    "properties": {},
    "tags": ["blue", "yellow"],
    "type": "raw",
    "unit": "meters",
    "url": "https://industrial.api.ubidots.com/api/v2.0/variables/5dfa39ee1a9ca53020c69391",
    "valuesUrl": "https://industrial.api.ubidots.com/api/v1.6/variables/5dfa39ee1a9ca53020c69391/values"
}
{
    "code": 400001,
    "message": "Validation Error.",
    "detail": {
        ....
    }
}
{
    "code": 401001,
    "message": "Authentication credentials were not provided.",
    "detail": "Authentication credentials were not provided."
}

Response

Returns a Variable object of the Variable created.