{"openapi":"3.0.3","info":{"version":"1.3.0","title":"Abacws Data Visualiser","description":"API for the storage and query of IoT data for the Cardiff University Comptuer Science building (Abacws).\n","license":{"name":"MIT"}},"tags":[{"name":"Advanced Query","description":"Advanced query endpoints for querying the entire dataset\n"},{"name":"Devices","description":"Endpoints relating to device info\n"},{"name":"Device Data","description":"Endpoints relating to device data entry\n"},{"name":"Device History","description":"Endpoints relating to device historical data\n"}],"servers":[{"url":"./","description":"Relative url\n"},{"url":"https://abacws.ggrainger.uk/api","description":"Production deployment\n"},{"url":"http://localhost:5000/api","description":"Local development server.\n"}],"paths":{"/devices":{"summary":"Device listing endpoint","get":{"summary":"Get a list of all devices","description":"# Device listing endpoint\n  Returns a list of all devices.\n","tags":["Devices"],"responses":{"200":{"description":"##### OK\n  List of all devices returned\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/devices"}}}},"503":{"$ref":"#/components/responses/databaseFailure"}}}},"/devices/{deviceName}":{"summary":"Get information about device","parameters":[{"$ref":"#/components/parameters/deviceName"}],"get":{"summary":"Get basic info on a device","description":"# Get information about device\n  Returns the basic information about a device.\n","tags":["Devices"],"responses":{"200":{"description":"##### OK\n  Device details returned\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/device"}}}}}}},"/devices/{deviceName}/data":{"summary":"Data interaction endpoint","parameters":[{"$ref":"#/components/parameters/deviceName"}],"get":{"summary":"Get current data for a device","description":"# Data interaction endpoint\n  Get the last data entry for the given device\n","tags":["Device Data"],"responses":{"200":{"description":"##### OK\n  Device data returned\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/timestampedData"}}}},"404":{"$ref":"#/components/responses/deviceNotFound"},"503":{"$ref":"#/components/responses/databaseFailure"}}},"put":{"summary":"Add data to the given device","description":"# Data interaction endpoint\n  Adds data to the given device.\n  Data should be provided in JSON format using a PUT request.\n\n  A timestamp is added to the data automatically and is not required.\n\n  Units can optionally be provided by providing an object with a `value` and `units` field instead of just a value:\n\n## Without units\n    {\n      temperature: 20\n    }\n\n## With units\n    {\n      temperature: {\n        value: 20,\n        units: \"C\"\n      }\n    }\n","tags":["Device Data"],"security":[{"apiKeyAuth":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/data"},"example":{"temperature":{"value":21,"units":"°C"}}}}},"responses":{"202":{"description":"##### OK\n  Data added\n"},"404":{"$ref":"#/components/responses/deviceNotFound"},"503":{"$ref":"#/components/responses/databaseFailure"},"403":{"$ref":"#/components/responses/authFailure"}}}},"/devices/{deviceName}/history":{"summary":"Historical data endpoint","parameters":[{"$ref":"#/components/parameters/deviceName"},{"$ref":"#/components/parameters/fromTime"},{"$ref":"#/components/parameters/toTime"}],"get":{"summary":"Get historical data","description":"# Historical data endpoint\n  Get historical data for the specified device.\n  \n  Optionally, can provide a \"from\" or \"to\" parameter to constrain the timeframe for the request.\n","tags":["Device History"],"responses":{"200":{"description":"##### OK\n  Historical data returned\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/history"}}}},"404":{"$ref":"#/components/responses/deviceNotFound"},"503":{"$ref":"#/components/responses/databaseFailure"}}},"delete":{"summary":"Clear historical data","description":"# Clear historical data\n  Deletes all data for the given device\n","tags":["Device History"],"security":[{"apiKeyAuth":[]}],"responses":{"200":{"description":"##### OK\n  Data was clearned\n"},"404":{"$ref":"#/components/responses/deviceNotFound"},"503":{"$ref":"#/components/responses/databaseFailure"},"403":{"$ref":"#/components/responses/authFailure"}}}},"/query":{"summary":"Advanced query endpoint","parameters":[{"$ref":"#/components/parameters/aQueryDeviceNames"},{"$ref":"#/components/parameters/aQueryDeviceTypes"},{"$ref":"#/components/parameters/aQueryDeviceFloors"}],"get":{"summary":"Advanced query endpoint for device info","description":"# Advanced query endpoint\n  Get a filtered list of devices based on provided parameters\n","tags":["Devices","Advanced Query"],"responses":{"200":{"$ref":"#components/responses/aQueryOK"},"503":{"$ref":"#/components/responses/databaseFailure"}}}},"/query/data":{"summary":"Advanced query endpoint","parameters":[{"$ref":"#/components/parameters/aQueryDeviceNames"},{"$ref":"#/components/parameters/aQueryDeviceTypes"},{"$ref":"#/components/parameters/aQueryDeviceFloors"},{"$ref":"#/components/parameters/aQueryDeviceHasFields"}],"get":{"summary":"Advanced query endpoint for device data","description":"# Advanced query endpoint\n  Get a filtered list of devices and their last data entry based on provided parameters.\n\n  NOTE: Devices with no data matching the query will not be returned.\n","tags":["Device Data","Advanced Query"],"responses":{"200":{"$ref":"#components/responses/aQueryOK"},"503":{"$ref":"#/components/responses/databaseFailure"}}}},"/query/history":{"summary":"Advanced query endpoint","parameters":[{"$ref":"#/components/parameters/aQueryDeviceNames"},{"$ref":"#/components/parameters/aQueryDeviceTypes"},{"$ref":"#/components/parameters/aQueryDeviceFloors"},{"$ref":"#/components/parameters/aQueryDeviceHasFields"},{"$ref":"#/components/parameters/fromTime"},{"$ref":"#/components/parameters/toTime"}],"get":{"summary":"Advanced query endpoint for device history","description":"# Advanced query endpoint\n  Get a filtered list of devices and associated historical data based on the provided parameters\n\n  NOTE: Devices with no data matching the query will not be returned.\n","tags":["Device History","Advanced Query"],"responses":{"200":{"$ref":"#components/responses/aQueryOK"},"503":{"$ref":"#/components/responses/databaseFailure"}}}}},"components":{"responses":{"deviceNotFound":{"description":"##### Device not found\n  The requested device does not exist in the database.\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/error"},"example":{"error":"Device does not exist"}}}},"databaseFailure":{"description":"##### Unable to access database\n  The API was unable to read/write from the database.\n  This may mean that the database is unreachable or that the api lacks the permissions to read/write from/to it.\n  Check your logs for more information.\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/error"},"example":{"error":"Unable to access database"}}}},"authFailure":{"description":"##### Auth failure\n  The authorisation provided was insufficient for this endpoint.\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/error"},"example":{"error":"You do not have permission to access this resource"}}}},"aQueryOK":{"description":"##### OK\n  A list of the devices matching the provided parameters was returned.\n","content":{"application/json":{"schema":{"$ref":"#/components/schemas/devices"}}}}},"parameters":{"deviceName":{"in":"path","name":"deviceName","required":true,"description":"Name of the the device you wish to query\n","schema":{"type":"string","example":"Room-0.01"}},"fromTime":{"in":"query","name":"from","required":false,"description":"Defines the start of a date range for history requests.\n  - If specified will only allow data points with a time larger than the provided value.\n  - Should be formatted in UNIX time.\n","schema":{"type":"number"}},"toTime":{"in":"query","name":"to","required":false,"description":"Defines the end of a date range for history requests.\n  - If specified will only allow data points with a time smaller than the provided value.\n  - Should be formatted in UNIX time.\n","schema":{"type":"number"}},"aQueryDeviceNames":{"name":"name","in":"query","required":false,"description":"The names of the devices we wish to query.\n  - Can be a single value, or a list of comma-delimited values\n","schema":{"type":"string","examples":["room1","room1,room2,room3"]}},"aQueryDeviceTypes":{"name":"type","in":"query","required":false,"description":"Types of devices we wish to query.\n  - Can be a single value, or a list of comma-delimited values\n","schema":{"type":"string","examples":["lecture","lecture,office,meeting"]}},"aQueryDeviceFloors":{"name":"floor","in":"query","required":false,"description":"Floors on which the devices we wish to query are\n  - Can be a single value, or a list of comma-delimited values\n","schema":{"type":"string","examples":[1,"1,2,3"]}},"aQueryDeviceHasFields":{"name":"has","in":"query","required":false,"description":"The fields we want the returned data to contain.\n  - Devices and data not containing these fields will not be returned.\n  - Can be a single value, or a list of comma-delimited values\n","schema":{"type":"string","examples":["temperature","temperature,humidity,light level"]}}},"schemas":{"device":{"type":"object","description":"A device represents a real world IoT device with:\n    A known location\n    A unique name which can be used to identify it.\n","required":["name","type","position"],"properties":{"name":{"type":"string","description":"Unique name of the device\n","examples":["Room-0.01"]},"type":{"type":"string","description":"The type of device\n","examples":["lecture","office"]},"position":{"$ref":"#/components/schemas/position"},"data":{"$ref":"#/components/schemas/timestampedData"},"history":{"$ref":"#/components/schemas/history"}}},"devices":{"description":"A list of devices\n","type":"array","items":{"$ref":"#/components/schemas/device"}},"position":{"type":"object","description":"The absolute position of a device in the world\n","properties":{"x":{"type":"number"},"y":{"type":"number"},"z":{"type":"number"}}},"timestamp":{"type":"integer","description":"UNIX timestamp","examples":[1647527656]},"data":{"type":"object","description":"Datapoint provided by a device, can have any number of fields. For example, a device could provide a temperature value.\n","examples":[{"temperature":{"value":20,"units":"°C"},"boolean value":{"value":true}}]},"timestampedData":{"type":"object","description":"Datapoint provided by a device, can have any number of fields. Will always include a timestamp field indiciating when this data was provided in UNIX time.\n","allOf":[{"$ref":"#/components/schemas/data"},{"type":"object","properties":{"timestamp":{"$ref":"#/components/schemas/timestamp"}},"examples":[{"timestamp":1647527656,"temperature":{"value":20,"units":"°C"},"boolean value":{"value":true}}]}]},"history":{"type":"array","minItems":0,"description":"Array of historical, timestamped data.\n","items":{"$ref":"#/components/schemas/timestampedData"}},"error":{"type":"object","description":"An error of some description was encountered by the API. A summary of this error will be provided as part of the error field.\n","properties":{"error":{"type":"string","examples":["Not Found","Could not read/write from database"]}}}},"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"x-api-key"}}}}