# Counters

Find information on how to get counters data [here](https://navixy.com/docs/navixy-api/user-api/backend-api/guides/data-retrieval/sensor-data).

## Resource specific actions

Actions with counter entities:

* [/tracker/counter/read](#read)
* [/tracker/counter/update](#update)

Actions with counter values:

* [/tracker/get\_counters](#get_counters)
* [/tracker/counter/value/get](#valueget)
* [/tracker/counter/value/list](#valuelist)
* [/tracker/counter/value/set](#valueset)
* [/tracker/counter/data/read](#dataread)

### read

Reads counter of passed `type`.

#### Parameters

| name        | description                                                                                      | type                                                                          | format     |
| ----------- | ------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------- | ---------- |
| tracker\_id | ID of the tracker (aka "object\_id"). Tracker must belong to authorized user and not be blocked. | int                                                                           | 123456     |
| type        | Counter type. One of `["odometer", "engine_hours"]`.                                             | [enum](https://navixy.com/docs/navixy-api/user-api/backend-api/..#data-types) | "odometer" |

#### Examples

{% tabs %}
{% tab title="cURL" %}
{% code overflow="wrap" %}

```sh
curl -X POST 'https://api.eu.navixy.com/v2/tracker/counter/read' \
    -H 'Content-Type: application/json' \
    -d '{"hash": "22eac1c27af4be7b9d04da2ce1af111b", "tracker_id": 123456, "type": "odometer"}'
```

{% endcode %}
{% endtab %}

{% tab title="HTTP GET" %}
{% code overflow="wrap" %}

```http
https://api.eu.navixy.com/v2/tracker/counter/read?hash=a6aa75587e5c59c32d347da438505fc3&tracker_id=123456&type=odometer
```

{% endcode %}
{% endtab %}
{% endtabs %}

#### Response

```json
{
  "success": true,
  "value": {
    "id": 111,
    "type": "odometer",
    "multiplier": 1.0
  }
}
```

#### Errors

* 204 - Entity not found – if there is no tracker with such ID belonging to authorized user.
* 208 - Device blocked – if tracker exists but was blocked due to tariff restrictions or some other reason.
* 219 - Not allowed for clones of the device – if specified tracker is a clone.

### update

Updates counter of passed `type`.

**required sub-user rights:** `tracker_update`.

#### Parameters

| name        | description                                                                                                                                                                    | type                                                                          | format     |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------- | ---------- |
| tracker\_id | ID of the tracker (aka "object\_id"). Tracker must belong to authorized user and not be blocked.                                                                               | int                                                                           | 123456     |
| type        | Counter type. One of `["odometer", "engine_hours"]`.                                                                                                                           | [enum](https://navixy.com/docs/navixy-api/user-api/backend-api/..#data-types) | "odometer" |
| multiplier  | A new value of counter multiplier.                                                                                                                                             | float                                                                         | 1.34       |
| sensor\_id  | ID of the sensor, which must be used as the source of odometer data (in case when parameter "type" equals "odometer"). If "type" is not "odometer", "sensor\_id" must be null. | int                                                                           | 123        |

#### Examples

{% tabs %}
{% tab title="cURL" %}
{% code overflow="wrap" %}

```sh
curl -X POST 'https://api.eu.navixy.com/v2/tracker/counter/update' \
    -H 'Content-Type: application/json' \
    -d '{"hash": "22eac1c27af4be7b9d04da2ce1af111b", "tracker_id": 123456, "type": "odometer", "multiplier": 3.14, "sensor_id": 1234}'
```

{% endcode %}
{% endtab %}

{% tab title="HTTP GET" %}
{% code overflow="wrap" %}

```http
https://api.eu.navixy.com/v2/tracker/counter/update?hash=a6aa75587e5c59c32d347da438505fc3&tracker_id=123456&type=odometer&multiplier=3.14&sensor_id=1234
```

{% endcode %}
{% endtab %}
{% endtabs %}

#### Response

```json
{
  "success": true
}
```

#### Errors

* 8 - Queue service error, try again later – cannot set counter value, try later.
* 204 - Entity not found – if there is no tracker with such ID belonging to authorized user.
* 208 - Device blocked – if tracker exists but was blocked due to tariff restrictions, or some other reason.
* 219 - Not allowed for clones of the device – if specified tracker is a clone.
* 7 - Invalid parameters –
  * if type is not "odometer" and `sensor_id` is not null.
  * if sensor with specified `sensor_id` is not a metering sensor.
  * if sensor with specified `sensor_id` belongs to another tracker.
  * if `sensor_id` is negative.
  * if sensor with such a `sensor_id` is not exists.
  * if type value is not one of list above.

### get\_counters

Gets last values of the tracker's counters.

#### Parameters

| name        | description                    | type | format |
| ----------- | ------------------------------ | ---- | ------ |
| tracker\_id | Tracker ID (aka "object\_id"). | int  | 999119 |

#### Examples

{% tabs %}
{% tab title="cURL" %}

```sh
curl -X POST 'https://api.eu.navixy.com/v2/tracker/get_counters' \
    -H 'Content-Type: application/json' \
    -d '{"hash": "a6aa75587e5c59c32d347da438505fc3", "tracker_id": 265489}'
```

{% endtab %}

{% tab title="HTTP GET" %}
{% code overflow="wrap" %}

```http
https://api.eu.navixy.com/v2/tracker/get_counters?hash=a6aa75587e5c59c32d347da438505fc3&tracker_id=265489
```

{% endcode %}
{% endtab %}
{% endtabs %}

#### Response

```json
{
  "success": true,
  "user_time": "2014-07-09 07:50:58",
  "list": [
    {
      "type": "odometer",
      "value": 100500.1,
      "update_time": "2014-03-06 13:57:00"
    }
  ]
}
```

* `user_time` - date/time. Current time in user's timezone.
* `list` - array of counter value objects.
  * `type` - enum. One of predefined semantic counter types (see below).
  * `value` - double. Counter value.
  * `update_time` - date/time. Date and time when the data updated.

List of counter types:

* `odometer` - odometer.
* `engine_hours` - engine hours.

#### Errors

* 204 – Entity not found - if there is no tracker with such ID belonging to authorized user.
* 208 – Device blocked - if tracker exists but was blocked due to tariff restrictions or some other reason.

### value/get

Gets actual value of specified `type` of sensor.

#### Parameters

| name        | description                                                                                      | type                                                                          | format     |
| ----------- | ------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------- | ---------- |
| tracker\_id | ID of the tracker (aka "object\_id"). Tracker must belong to authorized user and not be blocked. | int                                                                           | 123456     |
| type        | Counter type. One of `["odometer", "engine_hours"]`.                                             | [enum](https://navixy.com/docs/navixy-api/user-api/backend-api/..#data-types) | "odometer" |

#### Examples

{% tabs %}
{% tab title="cURL" %}
{% code overflow="wrap" %}

```sh
curl -X POST 'https://api.eu.navixy.com/v2/tracker/counter/value/get' \
    -H 'Content-Type: application/json' \
    -d '{"hash": "22eac1c27af4be7b9d04da2ce1af111b", "tracker_id": 123456, "type": "odometer"}'
```

{% endcode %}
{% endtab %}

{% tab title="HTTP GET" %}
{% code overflow="wrap" %}

```http
https://api.eu.navixy.com/v2/tracker/counter/value/get?hash=a6aa75587e5c59c32d347da438505fc3&tracker_id=123456&type=odometer
```

{% endcode %}
{% endtab %}
{% endtabs %}

#### Response

```json
{
  "success": true,
  "value": 18.9
}
```

* `value` - float. The last valuer of counter.

#### Errors

* 204 - Entity not found – if there is no tracker with such ID belonging to authorized user, counter does not exist or\
  there are no values yet. use /tracker/counter/set to create new counter (if not exist) and save some value.
* 208 - Device blocked – if tracker exists but was blocked due to tariff restrictions or some other reason.

### value/list

Get actual values for counters of passed `type` and `trackers`.

#### Parameters

| name     | description                                            | type                                                                          | format             |
| -------- | ------------------------------------------------------ | ----------------------------------------------------------------------------- | ------------------ |
| trackers | List of the tracker's ID belonging to authorized user. | int array                                                                     | `[123456, 234567]` |
| type     | Counter type. One of `["odometer", "engine_hours"]`.   | [enum](https://navixy.com/docs/navixy-api/user-api/backend-api/..#data-types) | "odometer"         |

#### Example

cURL

{% code overflow="wrap" %}

```sh
curl -X POST 'https://api.eu.navixy.com/v2/tracker/counter/value/list' \
    -H 'Content-Type: application/json' \
    -d '{"hash": "22eac1c27af4be7b9d04da2ce1af111b", "trackers": [123456, 234567], "type": "odometer"}'
```

{% endcode %}

#### Response

```json
{
  "success": true,
  "value": {
    "14": 18.9
  }
}
```

* `value` - a map with tracker's IDs as keys.

#### Errors

* 204 - Entity not found – if one of the specified counter does not exist or there are no values yet. Use[`/tracker/counter/set`](#valueset) to create new counter (if not exist) and save some value.
* 217 - List contains nonexistent entities – if one of the specified trackers does not exist or is blocked.

### value/set

Creates new counter of passed `type` (if not) and update its `value`.

#### Parameters

| name        | description                                                                                      | type                                                                          | format     |
| ----------- | ------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------- | ---------- |
| tracker\_id | ID of the tracker (aka "object\_id"). Tracker must belong to authorized user and not be blocked. | int                                                                           | 123456     |
| type        | Counter type. One of `["odometer", "engine_hours"]`.                                             | [enum](https://navixy.com/docs/navixy-api/user-api/backend-api/..#data-types) | "odometer" |
| value       | A new value of counter.                                                                          | float                                                                         | 233.21     |

#### Example

cURL

{% code overflow="wrap" %}

```sh
curl -X POST 'https://api.eu.navixy.com/v2/tracker/counter/value/set' \
    -H 'Content-Type: application/json' \
    -d '{"hash": "22eac1c27af4be7b9d04da2ce1af111b", "tracker_id": 123456, "type": "odometer", "value": 233.21}'
```

{% endcode %}

#### Response

```json
{
  "success": true
}
```

#### Errors

* 8 - Queue service error, try again later - can't set counter value, try later.
* 204 - Entity not found – if there is no tracker with such ID belonging to authorized user.
* 208 - Device blocked – if tracker exists but was blocked due to tariff restrictions or some other reason.
* 219 - Not allowed for clones of the device – if specified tracker is a clone.

### data/read

Returns counter values for a period.

#### Parameters

| name        | description                                          | type                                                                          | format                  |
| ----------- | ---------------------------------------------------- | ----------------------------------------------------------------------------- | ----------------------- |
| tracker\_id | Tracker ID (aka "object\_id").                       | int                                                                           | 123456                  |
| type        | Counter type. One of `["odometer", "engine_hours"]`. | [enum](https://navixy.com/docs/navixy-api/user-api/backend-api/..#data-types) | "odometer"              |
| from        | Requested period start.                              | date/time                                                                     | `"2021-02-25 12:21:17"` |
| to          | Requested period end.                                | date/time                                                                     | `"2021-03-25 12:21:17"` |

#### Example

cURL

{% code overflow="wrap" %}

```sh
curl -X POST 'https://api.eu.navixy.com/v2/tracker/counter/data/read' \
    -H 'Content-Type: application/json' \
    -d '{"hash": "22eac1c27af4be7b9d04da2ce1af111b", "tracker_id": 123456, "type": "odometer", "from": "2021-02-01 00:00:00", "to": "2021-02-01 03:00:00"}'
```

{% endcode %}

#### Response

```json
{
  "success": true,
  "list": [
    {
      "value": 3835.52,
      "update_time": "2021-02-01 02:52:55"
    }, {
      "value": 3835.7,
      "update_time": "2021-02-01 02:57:18"
    }
  ]
}
```

#### Errors

* 204 - Entity not found – if there is no tracker or counter belonging to authorized user.
* 211 - Requested time span is too big – if interval between "from" and "to" is too big (maximum value specified in API config)
* 208 - Device blocked – if tracker exists but was blocked due to tariff restrictions or some other reason.
* 7 - Invalid parameters –
  * if `from` is after `to`;
  * if between `from` and `to` more than 31 days.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://navixy.com/docs/navixy-api/user-api/backend-api/resources/tracking/tracker/counter.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
