Introduction
Welcome to the EnergyData API V2! This API allows you to interact with the energy data from energydata.stwhas.de
. You can authenticate, fetch, and write energy measurements using the endpoints provided.
The examples in this documentation include Shell, Python, and JavaScript.
Authentication
The API uses Basic Authentication to authenticate the user and obtain a JSON Web Token (JWT). Include the token in subsequent requests as an x-access-token
header.
Authenticate (POST /login
)
Example authentication:
curl --location --request POST 'https://energydata.stwhas.de/api/login' \
--header 'Authorization: Basic your_encoded_credentials'
import requests
response = requests.post(
'https://energydata.stwhas.de/api/login',
headers={'Authorization': 'Basic your_encoded_credentials'}
)
print(response.json())
const fetch = require('node-fetch');
fetch('https://energydata.stwhas.de/api/login', {
method: 'POST',
headers: {
'Authorization': 'Basic your_encoded_credentials'
}
})
.then(response => response.json())
.then(data => console.log(data));
Response example:
{
"expires": 1728214487,
"token": "your_token_here"
}
Authenticate and retrieve a token for accessing the API.
Credentials
Your credentials have to be encoded in Base64 in the format username:password
.
For example: testuser:testpassword
--> dGVzdHVzZXI6dGVzdHBhc3N3b3JkCg==
).
HTTP Request
POST https://energydata.stwhas.de/api/login
Headers
Header | Value | Description |
---|---|---|
Authorization | Basic your_encoded_credentials |
Basic Auth credentials |
Measurements
Get All Measurements (GET /measurements/all_measurements
)
Example request:
curl --location 'https://energydata.stwhas.de/api/measurements/all_measurements' \
--header 'x-access-token: your_token_here'
import requests
response = requests.get(
'https://energydata.stwhas.de/api/measurements/all_measurements',
headers={'x-access-token': 'your_token_here'}
)
print(response.json())
const fetch = require('node-fetch');
fetch('https://energydata.stwhas.de/api/measurements/all_measurements', {
headers: {
'x-access-token': 'your_token_here'
}
})
.then(response => response.json())
.then(data => console.log(data));
Example response:
[
{
"measurements": [
"MW1177",
"MW1178",
"MW1179",
"MW1180"
]
}
]
Retrieve all measurements from the API.
HTTP Request
GET https://energydata.stwhas.de/api/measurements/all_measurements
Headers
Header | Value | Description |
---|---|---|
x-access-token | your_token_here |
Authorization token |
Get Specific Measurement (GET /measurements/<measurement>
)
Example request:
curl --location 'https://energydata.stwhas.de/api/measurements/RW175' \
--header 'x-access-token: your_token_here'
response = requests.get(
'https://energydata.stwhas.de/api/measurements/RW175',
headers={'x-access-token': 'your_token_here'}
)
print(response.json())
fetch('https://energydata.stwhas.de/api/measurements/RW175', {
headers: {
'x-access-token': 'your_token_here'
}
})
.then(response => response.json())
.then(data => console.log(data));
Example with time range:
curl --location 'https://energydata.stwhas.de/api/measurements/RW175?from=2024-08-06T20:10:00Z&to=2024-08-06T20:12:00Z' \\
--header 'x-access-token: your_token_here'
import requests
response = requests.get(
'https://energydata.stwhas.de/api/measurements/RW175',
headers={'x-access-token': 'your_token_here'},
params={'from': '2024-08-06T20:10:00Z', 'to': '2024-08-06T20:12:00Z'}
)
print(response.json())
const fetch = require('node-fetch');
fetch('https://energydata.stwhas.de/api/measurements/RW175?from=2024-08-06T20:10:00Z&to=2024-08-06T20:12:00Z', {
headers: {
'x-access-token': 'your_token_here'
}
})
.then(response => response.json())
.then(data => console.log(data));
Example response:
[
{
"measurement": "RW175",
"description": "Einspeisung|Windkraft|gesamt",
"value": 13.236,
"unit": "MW",
"datetime": "2024-08-09T19:04:10.090000+00:00"
}
]
Retrieve data for a specific measurement. If no query parameters are provided, the most recent energy data entries from the database are returned. Alternatively, you can specify a time range to retrieve data from that specific period.
HTTP Request
GET https://energydata.stwhas.de/api/measurements/<measurement>
URL Parameters
Parameter | Type | Description |
---|---|---|
measurement | string | The measurement to retrieve. |
Query Parameters
Parameter | Type | Description | Example |
---|---|---|---|
from | string | Start time of the range | 2024-08-06T20:10:00Z |
to | string | End time of the range | 2024-08-06T22:10:00Z |
Get EnergyData (GET /energydata
)
Example request:
curl --location 'https://energydata.stwhas.de/api/energydata' \
--header 'x-access-token: your_token_here'
import requests
response = requests.get(
'https://energydata.stwhas.de/api/energydata',
headers={'x-access-token': 'your_token_here'}
)
print(response.json())
const fetch = require('node-fetch');
fetch('https://energydata.stwhas.de/api/energydata', {
headers: {
'x-access-token': 'your_token_here'
}
})
.then(response => response.json())
.then(data => console.log(data));
Example with time range:
curl --location 'https://energydata.stwhas.de/api/energydata?from=2024-08-06T20:10:00Z&to=2024-08-06T20:12:00Z' \\
--header 'x-access-token: your_token_here'
import requests
response = requests.get(
'https://energydata.stwhas.de/api/energydata',
headers={'x-access-token': 'your_token_here'},
params={'from': '2024-08-06T20:10:00Z', 'to': '2024-08-06T20:12:00Z'}
)
print(response.json())
const fetch = require('node-fetch');
fetch('https://energydata.stwhas.de/api/energydata?from=2024-08-06T20:10:00Z&to=2024-08-06T20:12:00Z', {
headers: {
'x-access-token': 'your_token_here'
}
})
.then(response => response.json())
.then(data => console.log(data));
Example response:
[
{
"measurement": "MW249",
"description": "HAS 24 - MicroGrid|Batteriespeicher|Ladezustand",
"value": 49.9,
"unit": "%",
"datetime": "2024-04-09T11:35:15.377000+00:00"
},
{
"measurement": "MW261",
"description": "HAS 24 - MicroGrid|Batteriespeicher|Sollwerte Aktuell",
"value": -45.97648620605469,
"unit": "kW",
"datetime": "2024-04-09T11:35:47.417000+00:00"
},
{
"..."
}
]
Retrieve energydata from the database. If no query parameters are provided, the most recent energy data entries from the database are returned. Alternatively, you can specify a time range to retrieve data from that specific period.
HTTP Request
GET https://energydata.stwhas.de/api/energydata
Query Parameters
Parameter | Type | Description | Example |
---|---|---|---|
from | string | Start time of the range | 2024-08-06T20:10:00Z |
to | string | End time of the range | 2024-08-06T20:12:00Z |
Headers
Header | Value | Description |
---|---|---|
x-access-token | your_token_here |
Authorization token |
User Measurements
Write Measurement (POST /measurements/write
)
Example request:
curl --location --request POST 'https://energydata.stwhas.de/api/measurements/write' \
--header 'x-access-token: your_token_here' \
--header 'Content-Type: application/json' \
--data '{
"measurement": "temperature",
"value": 26.8,
"unit": "C",
"description": "Raumtemperatur"
}'
response = requests.post(
'https://energydata.stwhas.de/api/measurements/write',
headers={
'x-access-token': 'your_token_here',
'Content-Type': 'application/json'
},
json={
'measurement': 'temperature',
'value': 26.8,
'unit': 'C',
'description': 'Raumtemperatur'
}
)
print(response.json())
fetch('https://energydata.stwhas.de/api/measurements/write', {
method: 'POST',
headers: {
'x-access-token': 'your_token_here',
'Content-Type': 'application/json'
},
body: JSON.stringify({
measurement: 'temperature',
value: 26.8,
unit: 'C',
description: 'Raumtemperatur'
})
})
.then(response => response.json())
.then(data => console.log(data));
Example response:
{
"message": "Data written successfully"
}
Submit new measurement data to the API.
HTTP Request
POST https://energydata.stwhas.de/api/measurements/write
Request Body
Field | Type | Description |
---|---|---|
measurement | string | The type of measurement. |
value | number | The measurement value. |
unit | string | The unit of measurement. |
description | string | A description of the data. |
Get All User Measurements (GET /measurements/user/all_measurements
)
Example request:
curl --location 'https://energydata.stwhas.de/api/measurements/user/all_measurements' \
--header 'x-access-token: your_token_here'
import requests
response = requests.get(
'https://energydata.stwhas.de/api/measurements/user/all_measurements',
headers={'x-access-token': 'your_token_here'}
)
print(response.json())
const fetch = require('node-fetch');
fetch('https://energydata.stwhas.de/api/measurements/user/all_measurements', {
headers: {
'x-access-token': 'your_token_here'
}
})
.then(response => response.json())
.then(data => console.log(data));
Example response:
[
{
"entries": {
"humidity": 6,
"temperature": 5
},
"measurements": [
"humidity",
"temperature"
],
"user_id": "afa7bfc4-1ec8-4235-a880-00b8f6967423",
"user_name": "testuser"
}
]
Retrieve all measurements for a user from the database.
HTTP Request
GET https://energydata.stwhas.de/api/measurements/user/all_measurements
Headers
Header | Value | Description |
---|---|---|
x-access-token | your_token_here |
Authorization token |
Get Specific User Measurements (GET /measurements/user
)
Example request:
curl --location 'https://energydata.stwhas.de/api/measurements/user?measurement=humidity' \
--header 'x-access-token: your_token_here'
import requests
response = requests.get(
'https://energydata.stwhas.de/api/measurements/user?measurement=humidity',
headers={'x-access-token': 'your_token_here'}
)
print(response.json())
const fetch = require('node-fetch');
fetch('https://energydata.stwhas.de/api/measurements/user?measurement=humidity', {
headers: {
'x-access-token': 'your_token_here'
}
})
.then(response => response.json())
.then(data => console.log(data));
Example with time range:
curl --location 'https://energydata.stwhas.de/api/measurements/user?measurement=humidity&from=2024-08-06T20:10:00Z&to=2024-08-06T22:10:00Z' \\
--header 'x-access-token: your_token_here'
import requests
response = requests.get(
'https://energydata.stwhas.de/api/measurements/user',
headers={'x-access-token': 'your_token_here'},
params={'measurement': 'humidity', 'from': '2024-08-06T20:10:00Z', 'to': '2024-08-06T22:10:00Z'}
)
print(response.json())
const fetch = require('node-fetch');
fetch('https://energydata.stwhas.de/api/measurements/user?measurement=humidity&from=2024-08-06T20:10:00Z&to=2024-08-06T22:10:00Z', {
headers: {
'x-access-token': 'your_token_here'
}
})
.then(response => response.json())
.then(data => console.log(data));
Example response:
[
{
"measurement": "humidity",
"description": "Office humidity",
"user": "afa7bfc4-1ec8-4235-a880-00b8f6967423",
"value": 48,
"unit": "%",
"datetime": "2024-11-06T11:30:00+00:00"
}
]
Retrieve measurements for your user from the database. If no query parameters are provided, the most recent energy data entries from the database are returned. Alternatively, you can specify a time range to retrieve data from that specific period.
HTTP Request
GET https://energydata.stwhas.de/api/measurements/user
Query Parameters
Parameter | Type | Description |
---|---|---|
measurement | string | The type of measurement to retrieve |
from | string | Start time of the range |
to | string | End time of the range |
Headers
Header | Value | Description |
---|---|---|
x-access-token | your_token_here |
Authorization token |
Get Every User Measurement(GET /measurements/user/<user-id>
)
Example request:
curl --location 'https://energydata.stwhas.de/api/measurements/user/afa7bfc4-1ec8-4235-a880-00b8f6967423?measurement=temperature' \
--header 'x-access-token: your_token_here'
import requests
response = requests.get(
'https://energydata.stwhas.de/api/measurements/user/afa7bfc4-1ec8-4235-a880-00b8f6967423?measurement=temperature',
headers={'x-access-token': 'your_token_here'}
)
print(response.json())
const fetch = require('node-fetch');
fetch('https://energydata.stwhas.de/api/measurements/user/afa7bfc4-1ec8-4235-a880-00b8f6967423?measurement=temperature', {
headers: {
'x-access-token': 'your_token_here'
}
})
.then(response => response.json())
.then(data => console.log(data));
Example with time range:
curl --location 'https://energydata.stwhas.de/api/measurements/user/afa7bfc4-1ec8-4235-a880-00b8f6967423?measurement=temperature&from=2024-08-06T20:10:00Z&to=2024-08-06T22:10:00Z' \\
--header 'x-access-token: your_token_here'
import requests
response = requests.get(
'https://energydata.stwhas.de/api/measurements/useruser/afa7bfc4-1ec8-4235-a880-00b8f6967423',
headers={'x-access-token': 'your_token_here'},
params={'measurement': 'temperature', 'from': '2024-08-06T20:10:00Z', 'to': '2024-08-06T22:10:00Z'}
)
print(response.json())
const fetch = require('node-fetch');
fetch('https://energydata.stwhas.de/api/measurements/user/afa7bfc4-1ec8-4235-a880-00b8f6967423?measurement=temperature&from=2024-08-06T20:10:00Z&to=2024-08-06T22:10:00Z', {
headers: {
'x-access-token': 'your_token_here'
}
})
.then(response => response.json())
.then(data => console.log(data));
Example response:
[
{
"measurement": "temperature",
"description": "Office temperature",
"user": "afa7bfc4-1ec8-4235-a880-00b8f6967423",
"value": 24.1,
"unit": "°C",
"datetime": "2024-11-06T09:12:00+00:00"
}
]
This endpoint retrieves the measurements for a specific user from the database. If no query parameters are provided, the most recent energy data entries from the database are returned. Alternatively, you can specify a time range to retrieve data from that specific period.
HTTP Request
GET https://energydata.stwhas.de/api/measurements/user/<user-id>
Query Parameters
Parameter | Type | Description |
---|---|---|
measurement | string | The type of measurement to retrieve |
from | string | Start time of the range |
to | string | End time of the range |
Headers
Header | Value | Description |
---|---|---|
x-access-token | your_token_here |
Authorization token |