API Key
Authentication
All API requests require authentication using an API key. Your API key should be included in the request headers.
API Key Header
Include your API key in the x-api-key header:
Requestbash
curl -X GET "https://www.strompreise-schweiz.ch/api/v1/tariffs" \
-H "x-api-key: YOUR_API_KEY"Example
JavaScriptjavascript
// JavaScript / Node.js
const response = await fetch('https://www.strompreise-schweiz.ch/api/v1/tariffs', {
method: 'GET',
headers: {
'x-api-key': process.env.API_KEY,
'Content-Type': 'application/json'
}
});
const data = await response.json();
console.log(data);Pythonpython
# Python
import requests
response = requests.get(
'https://www.strompreise-schweiz.ch/api/v1/tariffs',
headers={
'x-api-key': 'YOUR_API_KEY',
'Content-Type': 'application/json'
}
)
data = response.json()
print(data)Obtaining an API Key
To obtain an API key, you need to:
- Create an account on Strompreise Schweiz
- Navigate to your organization settings
- Go to the API Keys section
- Generate a new API key
Security Best Practices
- Never expose your API key in client-side code or public repositories
- Rotate your API keys periodically
- Use environment variables to store API keys
- Each organization should use separate API keys for different applications
Unauthorized Response
If your API key is invalid or missing, you will receive a 401 response:
Responsejson
{
"success": false,
"error": "Unauthorized",
"code": "UNAUTHORIZED"
}