From PhotoVoltaic Logger new generation
An application programming interface (API) is a protocol intended to be used as an interface by software components to communicate with each other. Wikipedia:API
The API is implemented as a RESTful API, so it uses HTTP requests to store and read data. Thus, REST uses HTTP for all four CRUD (Create / Read / Update / Delete) operations.
You can query the actual API version with http://your.domain.here/api/version
Make sure you request latest API version with http://your.domain.here/api/latest/... (from PVLng 2.12.0 and PVLng-scripts 1.6.0 onward)
(see API r* pages for supported API versions)
PVLng supports these request types:
|PUT||Create data set|
|GET||Read data set(s)|
|POST||Update data set|
|DELETE||Delete data set|
For data storage we have two possibilities:
- Web frontend for the master data, like channels and their relationships
- HTTP REST API for the operational channel data with HTTP PUT requests like this example
The storage API accepts only one parameter data and routes it to the requested channel.
By default (load live data) system date and time will be used.
The model behind the channel represents the interface to the database.
This section describes only the readout of measuring data via API, see the detailed API help for more supported actions.
The data readout from the system must be done with HTTP GET requests.
The readout API analyzes the requests, identifies the channel and returns the extracted data.
The model behind the channel provides a defined interface to query data.
The returned content type is detected by the requested file extension
|.json||JSON (default, if no extension is set)||application/json|
|.csv||Semicolon separated values||application/csv|
|.tsv||TAB separated values||application/tsv|
|.txt|| Space separated values
(proposed for single attribute requests)
All parameters are optional.
|start||Start timestamp for readout||string||00:00|
|end||End timestamp for readout||string||24:00|
|attributes||Return channel attributes as 1st data set||bool||0||yes|
|full||Return all data, not only timestamp and value||bool||0||X|
|short|| JSON: Return data as numeric indexed array,
not as object with named keys
- needs the location defined in in config/config.php
- returns the last reading for selected start-end range, can be empty, if no data in range, also relevant for meter channels
- returns the last reading, ignores start-end range
- returns all readings, ignores start-end range, useful for full backup
- All of (1|x|yes|on|true) are interpreted case-insensitive as TRUE.
- datetime, timestamp, data, min, max, count, timediff, consumption
If parameter attributes=1 is set, the 1st data set will contain the channel attributes and further rows the following fields. This is required e.g. in Web frontends charts module AJAX calls which need the channel attributes for drawing and so only one call is required to fetch attributes and data. Data are not rounded at all, they are delivered as stored or calculated.
By default, only the timestamp and data values will be returned. If you set the request parameter full=1, all the following data are returned.
|datetime||A readable timestamp; mostly used for debugging|
|timestamp||UTC Timestamp, good for direct use in graphing|
|data||Reading value for this timestamp|
|min||Minimal value of consolidated data|
|max||Maximal value of consolidated data|
|count||Count of consolidated data sets for returned row|
|timediff||Time range of the consolidation in seconds|
|consumption||For meter channels the difference during time period (last datas et to this data set)|
The status code will be doubled into the response header and the response body. This offers the possibility to analyze either the header or the body to check for success or errors. For every request the response body will contain further information, especially in case of an error. The following subset of HTTP status codes are used by the API.
200 - OK
The request has succeeded
- Read of data was successful
- Data was error free, but not saved
- Insert data within 5 seconds interval will be ignored (adjustable in database table pvlng_config -> DoubleRead)
- Not changed Switcher states will be ignored
201 - Created
The request has been fulfilled and resulted in a new resource being created
- Data was successful saved
- On batch loads the response body contains the count of inserted data sets.
204 - No Response
The server has fulfilled the request but does not need to return an entity-body
- Response for a DELETE request
400 - Bad Request
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.
- There was mostly a problem during data readout
- See response body for details
The request requires user authentication
- Missing or wrong API key for PUT requests
- Missing or wrong API key for GET requests for private channels, they are only accessible with API key.
405 - Method Not Allowed
The method specified in the Request-Line is not allowed for the resource identified by the Request-URI
- Only PUT / GET / POST / DELETE are allowed
500 - Internal Server Error
The server encountered an unexpected condition which prevented it from fulfilling the request.
- See response body for details