Created
December 1, 2022 07:39
-
-
Save AnttiKurittu/f6c4b6e0c47d9cd67ff0da82296eef1a to your computer and use it in GitHub Desktop.
Python script to request data from Wallbox API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/usr/bin/python3 | |
import requests | |
import json | |
def fetch_token(): | |
payload = {} | |
url = "https://api.wall-box.com/auth/token/user" | |
headers = { | |
'Accept': 'application/json, text/plain, */*\'', | |
'Content-Type': 'application/json;charset=utf-8' | |
} | |
response = requests.request("GET", url, headers=headers, data=payload, auth=('your email address', 'your password')) | |
response_json = json.loads(response.text) | |
return str(response_json['jwt']) | |
def main(): | |
payload = {} | |
url = "https://api.wall-box.com/v3/chargers/groups" | |
bearer_token = fetch_token() | |
headers = { | |
'Accept': 'application/json, text/plain, */*\'', | |
'Content-Type': 'application/json;charset=utf-8', | |
'Authorization': f'Bearer {bearer_token}' | |
} | |
response = requests.request("GET", url, headers=headers, data=payload) | |
chargers = json.loads(response.text) | |
print(json.dumps(chargers, indent=2)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment