GET /api/v3/metrics
List all metrics

Returns a list of all metrics belonging to a thing template as per the specified criteria. This API is paginated and returns 20 metrics by default. An metric is uniquely identified by an 'metric_key'. This key should be used in all the other API referencing a particular metric.

Params

Param name Description
thing_template_key
optional

Key of thing template for which metrics to be fetched. This field is required


Value: Must be a String
page
optional

Page number of results to be fetched, Default 1


Value: Must be Integer.
per
optional

Number of metrics to be returned in one page, Default 20


Value: Must be Integer.
order_by
optional

Field on which metrics should be sorted


Value: Must be a String
order
optional

Order, “asc” or “desc”, in which results should be sorted


Value: Must be a String
search
optional

Keywords based on which metrics should be searched. Currently you can search metrics on - metric_key, name, tags or user_defined_properties


Value: Must be a String
scope
optional

Matching condition if multiple keywords are specified for search. Valid values are “all” or “any”. Default is “all”


Value: Must be a String
timestamp_format
optional

Format, “str” or “int”, in which timestamps should be returned, Default “int”


Value: Must be a String
pretty
optional

Return a pretty formatted response if true, Default is false


Value: Must be a Boolean
field_list
optional

List of fields required in the result.


Value: Must be an array of any type
is_oem
optional

Returns metrics of child accounts if is_oem flag is true.


Value: Must be one of: <code>true</code>, <code>false</code>, <code>true</code>, <code>false</code>.

Examples

Request - listing all metrics belonging to a thing template without any criteria
  curl -X GET -H "Content-Type:application/json" -H "X-Auth-Token:olezAZXGQn9MutnfNerKDQ" -d '{"thing_template_key":"af31ae5fb2"}' https://api.datonis.io/api/v3/metrics

Response (returns first 20 records)
{
  "total_count": 4,
  "page": 1,
  "metrics": [
    {
      "abbreviation": "capacity",
      "created_at": 1448364456,
      "data_type": 0,
      "description": "Metric for thing template Washing Machine",
      "metric_key": "4f9b9764t7",
      "name": "capacity",
      "unit_of_measure": "kilogram",
      "updated_at": 1448364456,
      "treatments": [

      ],
      "thing_template_key": "af31ae5fb2"
    },
    {
      "abbreviation": "speed",
      "created_at": 1448364456,
      "data_type": 0,
      "description": "Metric for thing template Washing Machine",
      "metric_key": "4tb363cc88",
      "name": "maximum_rotational_speed",
      "unit_of_measure": "RPM",
      "updated_at": 1448364456,
      "treatments": [

      ],...
Request - listing metrics belonging to a thing template by specifying number of metrics to be returned at a time (page size) and specific set to be returned (page)
  curl -X GET -H "Content-Type:application/json" -H "X-Auth-Token:olezAZXGQn9MutnfNerKDQ" -d '{"thing_template_key":"af31ae5fb2","per":"2","page":"2"}' https://api.datonis.io/api/v3/metrics

Response (returns page 2 with 2 metrics per page)
{
  "total_count": 4,
  "page": "2",
  "metrics": [
    {
      "abbreviation": "noise",
      "created_at": 1448364456,
      "data_type": 0,
      "description": "Metric for thing template Washing Machine",
      "metric_key": "278t29123d",
      "name": "noise_level",
      "unit_of_measure": "dB",
      "updated_at": 1448364456,
      "treatments": [

      ],
      "thing_template_key": "af31ae5fb2"
    },
    {
      "abbreviation": "voltage",
      "created_at": 1448364457,
      "data_type": 0,
      "description": "Metric for thing template Washing Machine",
      "metric_key": "492c52bf56",
      "name": "voltage",
      "unit_of_measure": "volt",
      "updated_at": 1448364457,
      "treatments": [

      ],
     ...
Request - listing metrics belonging to a thing template ordered by a field with string formatted timestamps
  curl -X GET -H "Content-Type:application/json" -H "X-Auth-Token:olezAZXGQn9MutnfNerKDQ" -d '{"thing_template_key":"af31ae5fb2","timestamp_format":"str","order_by":"name","order":"desc"}' https://api.datonis.io/api/v3/metrics

Response (returns metrics in the reverse order of their name and timestamps in string format)
{
  "total_count": 4,
  "page": 1,
  "metrics": [
    {
      "abbreviation": "voltage",
      "created_at": "2015/11/24 11:27:37",
      "data_type": 0,
      "description": "Metric for thing template Washing Machine",
      "metric_key": "492c52bf56",
      "name": "voltage",
      "unit_of_measure": "volt",
      "updated_at": "2015/11/24 11:27:37",
      "treatments": [

      ],
      "thing_template_key": "af31ae5fb2"
    },
    {
      "abbreviation": "noise",
      "created_at": "2015/11/24 11:27:36",
      "data_type": 0,
      "description": "Metric for thing template Washing Machine",
      "metric_key": "278t29123d",
      "name": "noise_level",
      "unit_of_measure": "dB",
      "updated_at": "2015/11/24 11:27:36",
     ...
Request - listing metrics belonging to a thing template based on some search criteria with all keywords matching
  curl -X GET -H "Content-Type:application/json" -H "X-Auth-Token:olezAZXGQn9MutnfNerKDQ" -d '{"thing_template_key":"af31ae5fb2","search":"capacity level"}' https://api.datonis.io/api/v3/metrics

Response (returns metrics containing both keywords 'capacity' as well as 'level')
{
  "total_count": 0,
  "page": 1,
  "metrics": [

  ]
}
Request - listing metrics belonging to a thing template based on some search criteria with any of the keywords matching
  curl -X GET -H "Content-Type:application/json" -H "X-Auth-Token:olezAZXGQn9MutnfNerKDQ" -d '{"thing_template_key":"af31ae5fb2","search":"capacity level","scope":"any"}' https://api.datonis.io/api/v3/metrics

Response (returns metrics containing either of the keywords 'capacity' or 'level')
{
  "total_count": 2,
  "page": 1,
  "metrics": [
    {
      "abbreviation": "capacity",
      "created_at": 1448364456,
      "data_type": 0,
      "description": "Metric for thing template Washing Machine",
      "metric_key": "4f9b9764t7",
      "name": "capacity",
      "unit_of_measure": "kilogram",
      "updated_at": 1448364456,
      "treatments": [

      ],
      "thing_template_key": "af31ae5fb2"
    },
    {
      "abbreviation": "noise",
      "created_at": 1448364456,
      "data_type": 0,
      "description": "Metric for thing template Washing Machine",
      "metric_key": "278t29123d",
      "name": "noise_level",
      "unit_of_measure": "dB",
      "updated_at": 1448364456,
      "treatments": [

      ],
      "thing_template_key": "af31ae5fb2"
    }
  ]
}

POST /api/v3/metrics
Create an metric

Creates an metric with given parameters

Params

Param name Description
metric
required

Map containing details of the metric to be created, This map must contain thing_template_key


Value: Must be a Hash
pretty
optional

Return a pretty formatted response if true, Default is false


Value: Must be a Boolean
is_oem
optional

Create metric in child account by oem user if is_oem flag is true.


Value: Must be a Boolean
child_organisation_key
optional

Organisation key of child account where oem user wants to create metric. Required field if is_oem is present.


Value: Must be a String

Examples

Request
  curl -X POST -H "Content-Type:application/json" -H "X-Auth-Token:olezAZXGQn9MutnfNerKDQ"  -d '{"metric":{"name":"capacity","abbreviation":"capacity","description":"Metric for thing template Washing Machine","data_type":0,"unit_of_measure":"kilogram","thing_template_key":"af31ae5fb2"}}' https://api.datonis.io/api/v3/metrics

Response (containing details of the metric created)
{
  "metric": {
    "abbreviation": "capacity",
    "created_at": 1448364456,
    "data_type": 0,
    "description": "Metric for thing template Washing Machine",
    "metric_key": "4f9b9764t7",
    "name": "capacity",
    "unit_of_measure": "kilogram",
    "updated_at": 1448364456,
    "treatments": [

    ],
    "thing_template_key": "af31ae5fb2"
  }
}

GET /api/v3/metrics/:metric_key
Fetch an metric

Get details of an metric

Params

Param name Description
pretty
optional

Return a pretty formatted response if true, Default is false


Value: Must be a Boolean
is_oem
optional

Show metric of child account if is_oem flag is true.


Value: Must be one of: <code>true</code>, <code>false</code>, <code>true</code>, <code>false</code>.

Examples

Request
  curl -X GET -H "Content-Type:application/json" -H "X-Auth-Token:olezAZXGQn9MutnfNerKDQ"  https://api.datonis.io/api/v3/metrics/4f9b9764t7

Response (containing details of the metric)
{
  "metric": {
    "abbreviation": "capacity",
    "created_at": 1448364456,
    "data_type": 0,
    "description": "Metric for thing template Washing Machine",
    "metric_key": "4f9b9764t7",
    "name": "capacity",
    "unit_of_measure": "kilogram",
    "updated_at": 1448364456,
    "treatments": [

    ],
    "thing_template_key": "af31ae5fb2"
  }
}

PUT /api/v3/metrics/:metric_key
Update an metric

Updates an metric with given parameters

Params

Param name Description
metric
required

Map containing details of the metric to be updated


Value: Must be a Hash
pretty
optional

Return a pretty formatted response if true, Default is false


Value: Must be a Boolean
is_oem
optional

Update metric in child account by oem user if is_oem flag is true.


Value: Must be a Boolean
child_organisation_key
optional

Organisation key of child account where oem user wants to update metric. Required field if is_oem is present.


Value: Must be a String

Examples

Request
  curl -X PUT -H "Content-Type:application/json" -H "X-Auth-Token:olezAZXGQn9MutnfNerKDQ"  -d '{"metric":{"unit_of_measure":"kg"}}' https://api.datonis.io/api/v3/metrics/4f9b9764t7

Response (containing details of the metric updated)
{
  "metric": {
    "abbreviation": "capacity",
    "created_at": 1448364456,
    "data_type": 0,
    "description": "Metric for thing template Washing Machine",
    "metric_key": "4f9b9764t7",
    "name": "capacity",
    "unit_of_measure": "kg",
    "updated_at": 1448428909,
    "treatments": [

    ],
    "thing_template_key": "af31ae5fb2"
  }
}

DELETE /api/v3/metrics/:metric_key
Delete an metric

Deletes an metric from the system

Params

Param name Description
pretty
optional

Return a pretty formatted response if true, Default is false


Value: Must be a Boolean
is_oem
optional

Delete metric in child account by oem user if is_oem flag is true.


Value: Must be a Boolean

Examples

Request
  curl -X DELETE -H "Content-Type:application/json" -H "X-Auth-Token:olezAZXGQn9MutnfNerKDQ"  https://api.datonis.io/api/v3/metrics/4f9b9764t7

Response
{
}

POST /api/v3/metrics/:metric_key/add_treatments
Add treatments to metric

Creates treatments with given parameters

Params

Param name Description
treatments
required

Map containing details of the treatments to be created


Value: Must be a Hash
pretty
optional

Return a pretty formatted response if true, Default is false


Value: Must be a Boolean
is_oem
optional

Add treatment in child account by oem user if is_oem flag is true.


Value: Must be a Boolean

Examples

Request
  curl -X POST -H "Content-Type:application/json" -H "X-Auth-Token:olezAZXGQn9MutnfNerKDQ"  -d '{"treatments":{"RangeTreatment":{"_type":"Range","min":2,"max":10,"off_limit_treatment":0},"DerivedTreatment":{"_type":"DerivedTreatment","expression":"$event.data.metric_name * 3"}}}' https://api.datonis.io/api/v3/metrics/4f9b9764t7/add_treatments

Response (containing details of the metric added treatment)
{
  "metric": {
    "abbreviation": "capacity",
    "created_at": 1448364456,
    "data_type": 0,
    "description": "Metric for thing template Washing Machine",
    "metric_key": "4f9b9764t7",
    "name": "capacity",
    "unit_of_measure": "kilogram",
    "updated_at": 1448364456,
    "treatments": {
      "{\"RangeTreatment\"=>{\"_type\"=>\"Range\", \"min\"=>2, \"max\"=>10, \"off_limit_treatment\"=>0}, \"DerivedTreatment\"=>{\"_type\"=>\"DerivedTreatment\", \"expression\"=>\"$event.data.metric_name * 3\"}}": null
    },
    "thing_template_key": "af31ae5fb2"
  }
}

PUT /api/v3/metrics/:metric_key/update_treatments
Update treatments

Updates treatments belonging to this given metric with given parameters

Params

Param name Description
treatments
required

Map containing details of the treatments to be updated


Value: Must be a Hash
pretty
optional

Return a pretty formatted response if true, Default is false


Value: Must be a Boolean
is_oem
optional

Update treatment in child account by oem user if is_oem flag is true.


Value: Must be a Boolean
child_organisation_key
optional

Organisation key of child account where oem user wants to update treatment. Required field if is_oem is present.


Value: Must be a String

Examples

Request
  curl -X PUT -H "Content-Type:application/json" -H "X-Auth-Token:olezAZXGQn9MutnfNerKDQ"  -d '{"treatments":{"RangeTreatment":{"_type":"Range","min":2,"max":10,"off_limit_treatment":0},"DerivedTreatment":{"_type":"DerivedTreatment","expression":"$event.data.metric_name * 3"}}}' https://api.datonis.io/api/v3/metrics/4f9b9764t7/update_treatments

Response (containing details of the metric updated)
{
  "metric": {
    "abbreviation": "capacity",
    "created_at": 1448364456,
    "data_type": 0,
    "description": "Metric for thing template Washing Machine",
    "metric_key": "4f9b9764t7",
    "name": "capacity",
    "unit_of_measure": "kg",
    "updated_at": 1448428909,
    "treatments": "{\"treatments\":{ \"RangeTreatment\" : {\"_type\" : \"Range\", \"min\" : 2, \"max\" : 10, \"off_limit_treatment\" : 0}, \"DerivedTreatment\" : {\"_type\" : \"DerivedTreatment\", \"expression\" : \"$event.data.metric_name * 3\"}}}",
    "thing_template_key": "af31ae5fb2"
  }
}

DELETE /api/v3/metrics/:metric_key/delete_treatments
Delete treatments

Deletes treatments belonging to given metric from the system

Params

Param name Description
pretty
optional

Return a pretty formatted response if true, Default is false


Value: Must be a Boolean
treatment_keys
required

Array containing treatment keys to be deleted


Value: Must be an array of any type
is_oem
optional

Delete treatments in child account by oem user if is_oem flag is true.


Value: Must be a Boolean

Examples

Request
  curl -X DELETE -H "Content-Type:application/json" -H "X-Auth-Token:olezAZXGQn9MutnfNerKDQ" -d '{"treatment_keys":["123456","125896"]}' https://api.datonis.io/api/v3/metrics/4f9b9764t7/delete_treatments

Response
{
}