flexmeasures.api.v3_0.assets
Functions
Classes
- class flexmeasures.api.v3_0.assets.AssetAPI
This API view exposes generic assets.
- asset_sensors(id: int, asset: GenericAsset | None, page: int | None = None, per_page: int | None = None, filter: list[str] | None = None, sort_by: str | None = None, sort_dir: str | None = None)
List all sensors under an asset.
This endpoint returns all sensors under an asset.
The endpoint supports pagination of the asset list using the page and per_page query parameters.
If the page parameter is not provided, all sensors are returned, without pagination information. The result will be a list of sensors.
If a page parameter is provided, the response will be paginated, showing a specific number of assets per page as defined by per_page (default is 10).
The response schema for pagination is inspired by https://datatables.net/manual/server-side#Returned-data
Example response
An example of one asset being returned in a paginated response:
{ "data" : [ { "id": 1, "name": "Test battery", "latitude": 10, "longitude": 100, "account_id": 2, "generic_asset_type": {"id": 1, "name": "battery"} } ], "num-records" : 1, "filtered-records" : 1 }
If no pagination is requested, the response only consists of the list under the “data” key.
- Reqheader Authorization:
The authentication token
- Reqheader Content-Type:
application/json
- Resheader Content-Type:
application/json
- Status 200:
PROCESSED
- Status 400:
INVALID_REQUEST
- Status 401:
UNAUTHORIZED
- Status 403:
INVALID_SENDER
- Status 422:
UNPROCESSABLE_ENTITY
- auditlog(id: int, asset: GenericAsset, page: int | None = None, per_page: int | None = None, filter: list[str] | None = None, sort_by: str | None = None, sort_dir: str | None = None)
API endpoint to get history of asset related actions.
The endpoint is paginated and supports search filters.
If the page parameter is not provided, all audit logs are returned paginated by per_page (default is 10).
If a page parameter is provided, the response will be paginated, showing a specific number of assets per page as defined by per_page (default is 10).
If a search ‘filter’ is provided, the response will filter out audit logs where each search term is either present in the event or active user name. The response schema for pagination is inspired by https://datatables.net/manual/server-side
Example response
- Reqheader Authorization:
The authentication token
- Reqheader Content-Type:
application/json
- Resheader Content-Type:
application/json
- Status 200:
PROCESSED
- Status 400:
INVALID_REQUEST, REQUIRED_INFO_MISSING, UNEXPECTED_PARAMS
- Status 401:
UNAUTHORIZED
- Status 403:
INVALID_SENDER
- Status 422:
UNPROCESSABLE_ENTITY
- delete(id: int, asset: GenericAsset)
Delete an asset given its identifier.
This endpoint deletes an existing asset, as well as all sensors and measurements recorded for it.
- Reqheader Authorization:
The authentication token
- Reqheader Content-Type:
application/json
- Resheader Content-Type:
application/json
- Status 204:
DELETED
- Status 400:
INVALID_REQUEST, REQUIRED_INFO_MISSING, UNEXPECTED_PARAMS
- Status 401:
UNAUTHORIZED
- Status 403:
INVALID_SENDER
- Status 422:
UNPROCESSABLE_ENTITY
- fetch_one(id, asset)
Fetch a given asset.
This endpoint gets an asset.
Example response
{ "generic_asset_type_id": 2, "name": "Test battery", "id": 1, "latitude": 10, "longitude": 100, "account_id": 1, }
- Reqheader Authorization:
The authentication token
- Reqheader Content-Type:
application/json
- Resheader Content-Type:
application/json
- Status 200:
PROCESSED
- Status 400:
INVALID_REQUEST, REQUIRED_INFO_MISSING, UNEXPECTED_PARAMS
- Status 401:
UNAUTHORIZED
- Status 403:
INVALID_SENDER
- Status 422:
UNPROCESSABLE_ENTITY
- get_chart(id: int, asset: GenericAsset, **kwargs)
GET from /assets/<id>/chart
- get_chart_data(id: int, asset: GenericAsset, **kwargs)
GET from /assets/<id>/chart_data
Data for use in charts (in case you have the chart specs already).
- index(account: Account | None, all_accessible: bool, include_public: bool, page: int | None = None, per_page: int | None = None, filter: list[str] | None = None, sort_by: str | None = None, sort_dir: str | None = None)
List all assets owned by user’s accounts, or a certain account or all accessible accounts.
This endpoint returns all accessible assets by accounts. The account_id query parameter can be used to list assets from any account (if the user is allowed to read them). Per default, the user’s account is used. Alternatively, the all_accessible query parameter can be used to list assets from all accounts the current_user has read-access to, plus all public assets. Defaults to false. The include_public query parameter can be used to include public assets in the response. Defaults to false.
The endpoint supports pagination of the asset list using the page and per_page query parameters.
If the page parameter is not provided, all assets are returned, without pagination information. The result will be a list of assets.
If a page parameter is provided, the response will be paginated, showing a specific number of assets per page as defined by per_page (default is 10).
If a search ‘filter’ such as ‘solar “ACME corp”’ is provided, the response will filter out assets where each search term is either present in their name or account name. The response schema for pagination is inspired by https://datatables.net/manual/server-side#Returned-data
Example response
An example of one asset being returned in a paginated response:
{ "data" : [ { "id": 1, "name": "Test battery", "latitude": 10, "longitude": 100, "account_id": 2, "generic_asset_type": {"id": 1, "name": "battery"} } ], "num-records" : 1, "filtered-records" : 1 }
If no pagination is requested, the response only consists of the list under the “data” key.
- Reqheader Authorization:
The authentication token
- Reqheader Content-Type:
application/json
- Resheader Content-Type:
application/json
- Status 200:
PROCESSED
- Status 400:
INVALID_REQUEST
- Status 401:
UNAUTHORIZED
- Status 403:
INVALID_SENDER
- Status 422:
UNPROCESSABLE_ENTITY
- patch(asset_data: dict, id: int, db_asset: GenericAsset)
Update an asset given its identifier.
This endpoint sets data for an existing asset. Any subset of asset fields can be sent.
The following fields are not allowed to be updated: - id - account_id
Example request
{ "latitude": 11.1, "longitude": 99.9, }
Example response
The whole asset is returned in the response:
{ "generic_asset_type_id": 2, "id": 1, "latitude": 11.1, "longitude": 99.9, "name": "Test battery", "account_id": 2, }
- Reqheader Authorization:
The authentication token
- Reqheader Content-Type:
application/json
- Resheader Content-Type:
application/json
- Status 200:
UPDATED
- Status 400:
INVALID_REQUEST, REQUIRED_INFO_MISSING, UNEXPECTED_PARAMS
- Status 401:
UNAUTHORIZED
- Status 403:
INVALID_SENDER
- Status 422:
UNPROCESSABLE_ENTITY
- post(asset_data: dict)
Create new asset.
This endpoint creates a new asset.
Example request
{ "name": "Test battery", "generic_asset_type_id": 2, "account_id": 2, "latitude": 40, "longitude": 170.3, }
The newly posted asset is returned in the response.
- Reqheader Authorization:
The authentication token
- Reqheader Content-Type:
application/json
- Resheader Content-Type:
application/json
- Status 201:
CREATED
- Status 400:
INVALID_REQUEST
- Status 401:
UNAUTHORIZED
- Status 403:
INVALID_SENDER
- Status 422:
UNPROCESSABLE_ENTITY
- public()
Return all public assets.
This endpoint returns all public assets.
- Reqheader Authorization:
The authentication token
- Reqheader Content-Type:
application/json
- Resheader Content-Type:
application/json
- Status 200:
PROCESSED
- Status 400:
INVALID_REQUEST
- Status 401:
UNAUTHORIZED
- Status 422:
UNPROCESSABLE_ENTITY