-
Notifications
You must be signed in to change notification settings - Fork 0
API
Syntax | Data Type | Description |
---|---|---|
Username | String | Username |
Password | String | Password |
url/api/v1/auth
GET: url/api/v1/auth
with a bearer token header
'Authorization': 'Bearer ' + token
Will return 403 if token is bad
Login to get a token
curl -X POST url/api/v1/auth -H 'Content-type:application/json' -d '{"username": "foo", "password": "bar"}'
Will return a bearer token
token: yJhbGciOiJIUzI1N.....
Syntax | Data Type | Description |
---|---|---|
ID | Long | Primary Key |
Name | String | Name of building |
Links | Object | links to self and children |
GET: url/api/v1/buildings
[
{
"id": 0,
"name": "MVB",
"links": {
"self": "http://foo/api/v1/buildings/0",
"children": "http://foo/api/v1/buildings/0/rooms"
}
},
{
"id": 1,
"name": "Queens",
"links": {
"self": "http://foo/api/v1/buildings/1",
"children": "http://foo/api/v1/buildings/1/rooms"
}
}
]
GET: url/api/v1/buildings/:id
{
"id": 1,
"links": {
"self": "http://foo/api/v1/buildings/1",
"child": "http://foo/api/v1/buildings/1/rooms"
},
"name": "MVB"
}
/?kids=true
will return the whole tree for the building including readings
Add a building
curl -X POST url/api/v1/buildings -H 'Content-type:application/json' -d '{"name": "foo"}'
returns the newly created building
{"id":3,"links":{"self":"","child":""},"name":"foo"}
Edit a building
$ curl -X PUT url/api/v1/buildings/3 -H 'Content-type:application/json' -d '{"name": "bar"}'
returns the edited building
{"id":3,"links":{"child":"","self":""},"name":"bar"}
Delete a building
curl -X DELETE url/api/v1/buildings/1
Syntax | Data Type | Description |
---|---|---|
ID | Int | Primary Key |
Name | String | Name of room |
Links | Object | links to self and children |
url/api/v1/rooms/:id
or
url/api/v1/buildings/:id/rooms/:id
NOTE, which url you query with will change the links to that format!
GET: url/api/v1/buildings/:id/rooms
if you have the building id it will only show rooms within the building otherwise it will list all rooms
[
{
"id": 0,
"name": "1.1",
"links": {
"self": "http://foo/api/v1/buildings/:id/rooms/0",
"children": "http://foo/api/v1/buildings/:id/rooms/0/sensors"
}
},
{
"id": 1,
"name": "2.3",
"links": {
"self": "http://foo/api/v1/buildings/:id/rooms/1",
"children": "http://foo/api/v1/buildings/:id/rooms/1/sensors"
}
}
]
GET: url/api/v1/rooms/:id
or
GET: url/api/v1/buildings/:id/rooms/:id
{
"id": 1,
"links": {
"child": "http://foo/api/v1/buildings/1/rooms/1/sensors",
"self": "http://foo/api/v1/buildings/1/rooms/1"
},
"name": "1.1"
}
/?kids=true
will return the whole tree for the room including readings
Add a room
curl -X POST url/api/v1/buildings/1/rooms -H 'Content-type:application/json' -d '{"name": "foo"}'
Note if you use the other syntax for querying, you have to add the building id to the json like
curl -X POST url/api/v1/rooms -H 'Content-type:application/json' -d '{"name": "foo", "building":{"id: 1}}'
returns the newly created rrom
{"id":3,"links":{"self":"","child":""},"name":"foo"}
Edit a room
$ curl -X PUT url/api/v1/buildings/1/rooms/3 -H 'Content-type:application/json' -d '{"name": "bar"}'
returns the edited room
{"id":3,"links":{"child":"","self":""},"name":"bar"}
Delete a room
curl -X DELETE url/api/v1/buildings/1/rooms/3
Syntax | Data Type | Description |
---|---|---|
ID | Int | Primary Key |
Description | String | Description of device |
Links | Object | links to self and children |
url/api/v1/sensors/:id
or
url/api/v1/buildings/:id/rooms/:id/sensors/:id
NOTE, which url you query with will change the links to that format!
GET: url/api/v1/buildings/:id/rooms/sensors
if you have the room id it will only show sensors within the room otherwise it will list all sensors
[
{
"id": 12600,
"description": "Back of room a",
"links": {
"self": "http://foo/api/v1/buildings/:id/rooms/:id/sensors/10",
"children": "http://foo/api/v1/buildings/:id/rooms/:id/sensors/10/data"
}
},
{
"id": 9858,
"description": "Front of room b",
"links": {
"self": "http://foo/api/v1/buildings/:id/rooms/:id/sensors/10",
"children": "http://foo/api/v1/buildings/:id/rooms/:id/sensors/10/data"
}
}
]
url/api/v1/buildings/:id/rooms/:id/sensors/:id
Add a sensor
curl -X POST url/api/v1/buildings/1/rooms/1/sensors -H 'Content-type:application/json' -d '{"id": 10358, "name": "foo"}'
returns the newly created sensor
{"id":10358,"links":{"self":"","child":""},"name":"foo"}
Edit a sensor
$ curl -X PUT url/api/v1/buildings/1/rooms/1/sensors/10358 -H 'Content-type:application/json' -d '{"name": "bar"}'
returns the edited sensor
{"id":10358,"links":{"child":"","self":""},"name":"bar"}
Delete a sensor
curl -X DELETE url/api/v1/sensors/10358
Syntax | Data Type | Description |
---|---|---|
ID | Int | Primary Key |
Date | Date | Date and time of reading |
CO2 | Float | Amount of CO2 |
url/api/v1/reading/:id
or
url/api/v1/buildings/:id/rooms/:id/sensors/:id/readings/:id
GET: url/api/v1/buildings/:id/rooms/:id/sensors/:id/readings/list
GET: url/api/v1/:id/readings
[
{
"id": 1,
"date": "2021-04-22T17:05:34Z",
"co2": 1603
},
{
"id": 2,
"date": "2021-04-22T17:06:34Z",
"co2": 1556
}
]
GET: url/api/v1/buildings/:id/rooms/:id/sensors/:id/readings/latest
GET: url/api/v1/:id/readings/latest
[
{
"id": 45,
"date": "2021-04-22T17:49:36Z",
"co2": 1742
}
]
GET: url/api/v1/buildings/:id/rooms/:id/sensors/:id/readings/latest?amt=x
GET: url/api/v1/:id/readings/latest?amt=x
[
{
"id": 45,
"date": "2021-04-22T17:49:36Z",
"co2": 1742
},
{
"id": 44,
"date": "2021-04-22T17:48:36Z",
"co2": 1748
}
]
Delete a reading
curl -X DELETE url/api/v1/reading/:id