# cbrdata API

### Public Access Endpoints

The endpoints below are intended  to provide data to clients and external developers.  Please sign up via the Arboretum [dashboard ](https://cbrdata.com) or Queanbeyan [dashboard ](https://qprc.cbrdata.com)as a Developer to generate API keys. \
\
Please use the subdomain ***qprcapi*** instead of ***api*** to access data from the **Queanbeyan-Palerang City Council Project.**  *e.g. qprcapi.cbrdata.com*

#### API V1

Public endpoints for soil moisture data management.&#x20;

## Sensor Data V1

<mark style="color:blue;">`GET`</mark> `https://api.cbrdata.com/api/nodedata/:from/:to`

This endpoint allows authorised users to request **soil moisture data** records from available soil moisture nodes. \
\
Returns a JSON object.

#### Path Parameters

| Name | Type    | Description                                                                                                              |
| ---- | ------- | ------------------------------------------------------------------------------------------------------------------------ |
| from | integer | <p>The lower date threshold as a Unix timestamp.<br><br>Can be overridden by the <code>days</code> query parameter. </p> |
| to   | integer | The upper date threshold as a Unix timestamp.                                                                            |

#### Query Parameters

| Name     | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| -------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| nodeNum  | string  | <p>Node/device number (as a string). <br><br>A human-readable number assigned to a node. The number is usually determined based the order of deployment. <br><br>Can be customized via the Management Portal. </p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| forestId | string  | <p>Forest number (as a three character string) which uniquely identifies a forest/location. <br><br>E.g. 008, 100 etc. <br><br>Overrides the <code>forest</code> parameter. <br><br>For the National Arboretum Canberra, the forest number is that of the actual forest based on the data provided by the arboretum. For other clients, an arbitrary number is used to specify a location. </p>                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| days     | number  | <p>Specifies the number of days from the upper date threshold  to return the data for.   <br><br>Overrides the lower date threshold if required. <br><br>E.g <code>days=3</code> will return data for the last three days if the upper date threshold is the current time. <br><br>Note:  A hard limit of 6000 records is in place for external requests. </p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| limit    | integer | <p>Number used to specify or limit the number of requests/records returned.<br><br>This parameter is overridden if the <code>days</code> parameter is present in the request.   </p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| org      | string  | <p>The full name of client/organisation who owns or produces the requested data. E.g <code>National Arboretum Canberra</code> or <br><code>Queanbeyan City Council</code>. </p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| token    | string  | <p>API key used to authorize the request. <br><br>Can be generated from the dashboard under the <strong>API Settings</strong> tab within the <strong>Account</strong> menu.  <br><br><br>Please Note that API keys cannot be generated unless your account has been approved by an admin and once generated, will have API permissions based on your account's approved access level i.e. Developer, Client, Admin  etc.  For general API functionalities Developer level is sufficient. <br><br>Network management functions require elevated accounts. Changes to your account's access level can be requested from the dashboard under the <strong>Account Setting</strong> tab within the <strong>Account</strong> menu. </p>                                                                                                                |
| userId   | string  | <p><strong>(Dashboard USE ONLY)</strong><br><br>The requesting user's unique id generated during account registration to authorize the request. <br><br>The id is used to reference the requesting user and their API permission. <br><br>While not enforced, this parameter is reserved for dashboard use only. Users do not have access to their unique user id. <br><br>Use the <em><strong><code>token</code></strong></em> parameter general requests. <br><br></p>                                                                                                                                                                                                                                                                                                                                                                         |
| forest   | string  | <p>The full identifier for the forest/location, where the sensor node is located such as <em>'F008 Japanese Flowering Dogwood' or 'L010 Queen Elizabeth II Park' or 'Water Module (Queel El II Park)'</em> . <br><br>The full forest identifier for soil nodes consist of values from the following the metadata fields in the given order:<br><code>forsest\_num+" "+" "+forest\_name</code><br><br><br><br><br>Can  be used instead of the <em><strong>node</strong></em> parameter. <br><br>Can be customized via the Management Portal<br><br><em>Keep in mind that  this value is subject to modification by the client or administrator via the network management portal. If it is modified, it will be displayed as such in the data dashboard. It is recommended that you update your existing requests accordingly.</em>  <br><br></p> |
| node     | string  | <p>The unique node/device identifier.<br><br>Used to query data collected by a particular sensor node irrespective of its previous or current location. <br><br>Overrides all other identifying parameters i.e. <code>forest, forestId and  nodeNum</code><br>.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |

{% tabs %}
{% tab title="200 Example sensor node data.Data successfully retrieved." %}

```javascript

{
    "count": 2,
    "meta": {
        "some_unique_id": {
            "lat_lng": [-24.1231,-123.1231],
            "node_num": "10",
            "vwc30_low": 10.3,
            "vwc30_mid": 12.72,
            "vwc60_low": 16.5,
            "vwc60_mid": 17.63,
            "forest_num": "023",
            "vwc30_high": 14.7,
            "vwc60_high": 31.1,
            "forest_name": "Parana Pine",
            "active_since": 1531058469,
            "forest_boundry": "149.0739895728598,-35.28893879348822,0 149.0738328578673,-35.28884416443776,0 149.0736053770746,-35.28870680430924,0 149.0726928059028,-35.2897227739313,0 149.0743438571936,-35.29071972141189,0 149.0746213189179,-35.29088725507324,0 149.0748392088915,-35.29062109274278,0 149.0748904042846,-35.29056743748038,0 149.0749700598445,-35.29049332968688,0 149.0750717764896,-35.29041198285805,0 149.0754312056607,-35.29024035572771,0 149.0755987350303,-35.29020417880017,0 149.0757612472829,-35.29017462477777,0 149.0759911252785,-35.29014735147081,0 149.0739895728598,-35.28893879348822,0"
        }
    },
    "data": {
        "some_unique_id": [
            {
                "full_node_id": "some_unique_id",
                "temperature": 26.9,
                "vwc30": 0.136,
                "vwc60": 0.218,
                "battery_voltage": 1.01,
                "upload_timestamp": 1547465303,
                "count": "4"
            }, 
            {
                "full_node_id": "some_unique_id",
                "temperature": 27.1,
                "vwc30": 0.136,
                "vwc60": 0.219,
                "battery_voltage": 1.01,
                "upload_timestamp": 1547463502,
                "count": "4"
            }
        ]
    }
}
```

{% endtab %}

{% tab title="400 Badly formatted request..." %}

```javascript
{message:"Bad Request",  status:400}
```

{% endtab %}

{% tab title="401 Bad credentials" %}

```javascript
{message:"Unauthorised",  status:400}
```

{% endtab %}

{% tab title="403 Access is forbidden.." %}

```javascript
{message:"Forbidden",  status:403}
```

{% endtab %}

{% tab title="404 Path not found..." %}

```
Not Found
```

{% endtab %}

{% tab title="500 " %}

```javascript
{message:"Internal Server Error",  status:500}
```

{% endtab %}
{% endtabs %}

## Node/Device Information

<mark style="color:blue;">`GET`</mark> `https://api.cbrdata.com/api/nodeinfo`

Retrieves all available metadata on registered nodes/device.  Data is grouped by the node's unique identifier.  Retrieved metadata can be utilized to make requests on **/nodedata**\
\
Returns a JSON object.&#x20;

#### Query Parameters

| Name   | Type   | Description                                                                                                                                                                     |
| ------ | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| userId | string | <p><strong>(Dashboard USE ONLY)</strong><br><br>The requesting user's unique id. </p>                                                                                           |
| token  | string | API key used to authorize the request.                                                                                                                                          |
| org    | string | <p>The full name of client/organisation who owns or produces the requested data. E.g <code>National Arboretum Canberra</code> or <br><code>Queanbeyan City Council</code>. </p> |

{% tabs %}
{% tab title="200 Example metadata..." %}

```javascript
{
    "some_node_1": {
        "lat_lng": [-12.4434, 12312.11],
        "node_num": 8,
        "vwc30_low": 23.3,
        "vwc30_mid": 24.36,
        "vwc60_low": 28.6,
        "vwc60_mid": 30.22,
        "forest_num": "008",
        "vwc30_high": 25.3,
        "vwc60_high": 31.5,
        "forest_name": "Japanese Flowering Dogwood",
        "active_since": 1531058469,
        "forest_boundry": "149.0796113799227,-35.2871284150761,0 149.0795475112163,-35.28708983324432,0 149.0794324700909,-35.28702033913545,0 149.0785198261107,-35.28803653708137,0 149.0791913745544,-35.28844199868593,0 149.079206347198,-35.28845103881466,0 149.0793754680926,-35.28836306143108,0 149.0795047261577,-35.28829605000612,0 149.0797281012334,-35.28817594458858,0 149.07990002243,-35.28808156382936,0 149.0800539797064,-35.28797152928961,0 149.0802079365661,-35.28786149446437,0 149.0802723414693,-35.28780969879308,0 149.0803196081066,-35.28777168619416,0 149.0804312794008,-35.28768187763872,0 149.0804512211684,-35.28765216490685,0 149.0804626491778,-35.28764260453301,0 149.0803378520016,-35.28756725743101,0 149.0796113799227,-35.2871284150761,"
    },
    "some_node_2": {
        "lat_lng": [-13.4434, 123112.11],
        "node_num": "10",
        "vwc30_low": 10.3,
        "vwc30_mid": 12.72,
        "vwc60_low": 16.5,
        "vwc60_mid": 17.63,
        "forest_num": "023",
        "vwc30_high": 14.7,
        "vwc60_high": 31.1,
        "forest_name": "Parana Pine",
        "active_since": 1531058469,
        "forest_boundry": "149.0739895728598,-35.28893879348822,0 149.0738328578673,-35.28884416443776,0 149.0736053770746,-35.28870680430924,0 149.0726928059028,-35.2897227739313,0 149.0743438571936,-35.29071972141189,0 149.0746213189179,-35.29088725507324,0 149.0748392088915,-35.29062109274278,0 149.0748904042846,-35.29056743748038,0 149.0749700598445,-35.29049332968688,0 149.0750717764896,-35.29041198285805,0 149.0754312056607,-35.29024035572771,0 149.0755987350303,-35.29020417880017,0 149.0757612472829,-35.29017462477777,0 149.0759911252785,-35.29014735147081,0 149.0739895728598,-35.28893879348822,0"
    }
}
```

{% endtab %}

{% tab title="401 " %}

```javascript
{message:"Unauthorised",  status:401}
```

{% endtab %}

{% tab title="500 " %}

```javascript
{message:"Internal Server Error",  status:500}
```

{% endtab %}
{% endtabs %}

#### API V2

API endpoints for environmental data management.&#x20;

## Sensor Data V2

<mark style="color:blue;">`GET`</mark> `https://qprcapi.cbrdata.com/api/v2/nodedata/:from/:to`

This endpoint allows authorised users to request **environmental data** records from available environmental monitoring nodes.  Please refer to Sensor Data V1 for more details on query parameters if required. \
\
Returns a JSON object.

#### Path Parameters

| Name | Type    | Description                                 |
| ---- | ------- | ------------------------------------------- |
| from | integer | The lower date threshold as Unix timestamp. |
| to   | integer | The upper date threshold as Unix timestamp. |

#### Query Parameters

| Name   | Type    | Description                                                                                                                                                                                                                                                                                                                                 |
| ------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| days   | number  | <p>Specified the  number of data from the upper threshold to return the data for. <br><br>Overrides the lower data threshold if required.<br><br>E.g. days=3 will return data from the last three days if the upper threshold is the current time. <br><br><br>Note: A hard limit of 6000 record is in place for external records. <br></p> |
| limit  | integer | <p>Number used to specify or limit the number of requests/records returned. <br><br>THis parameter is overridden if the <code>days</code> parameter is present in the request. </p>                                                                                                                                                         |
| userId | string  | <p><strong>(Dashboard USE ONLY)</strong><br><br>The requesting user's unique id. </p>                                                                                                                                                                                                                                                       |
| token  | string  | API key used to authorize the request.                                                                                                                                                                                                                                                                                                      |
| node   | string  | <p>The unique node/device identifier. <br><br>Used to query the data collected by a particular sensor node. <br><br></p>                                                                                                                                                                                                                    |

{% tabs %}
{% tab title="200 Successful response. " %}

```javascript
{
    "meta": {
        "node_id": "some_unique_id_1"
    },
    "data": [{
        "noise": 64.52,
        "tc": 31.54,
        "hum": 38.1,
        "pres": 94177.66,
        "co2": 344.517,
        "bat": 52,
        "upload_timestamp": 1545268386
    },{
        "noise": 56.5,
        "tc": 22.42,
        "hum": 48.8,
        "pres": 94231.7,
        "co2": 602.077,
        "bat": null,
        "upload_timestamp": 1545005381
    }, {
        "noise": 0,
        "tc": 22.43,
        "hum": 48.9,
        "pres": 94240.89,
        "co2": 641.537,
        "bat": null,
        "upload_timestamp": 1545005225
    }],
    "count": 3
}
```

{% endtab %}

{% tab title="400 " %}

```javascript
{message:"Bad Request",  status:400}
```

{% endtab %}

{% tab title="401 " %}

```javascript
{message:"Unauthorised",  status:401}
```

{% endtab %}

{% tab title="500 " %}

```javascript
{message:"Internal Server Error",  status:500}
```

{% endtab %}
{% endtabs %}

####

```
```
