Das Skript
import json
import os
import urllib.request
API = "https://indizio.rexago.com/api/v1"
KEY = os.environ["INDIZIO_API_KEY"]
def indizio(path, body=None):
req = urllib.request.Request(
API + path,
data=json.dumps(body).encode() if body is not None else None,
method="POST" if body is not None else "GET",
headers={
"Authorization": "Bearer " + KEY,
"Content-Type": "application/json",
"Accept": "application/json",
"User-Agent": "mein-system/1.0",
},
)
with urllib.request.urlopen(req, timeout=60) as res:
print("berechnet:", res.headers.get("X-Indizio-Credits-Charged"),
"| Rest:", res.headers.get("X-Indizio-Credits-Remaining"))
return json.load(res)
firma = indizio("/enrich/company", {"domain": "goldbachkirchner.de"})
print(firma["data"]["name"], "-", firma["data"]["address"]["city"])
konto = indizio("/account")
print("Guthaben:", konto["data"]["account"]["credit_balance"])
Aufrufen mit:
INDIZIO_API_KEY=<IHR-API-SCHLÜSSEL> python3 indizio.py
Empfohlen: eine eigene Kennung
Die Zeile "User-Agent": "mein-system/1.0" ist nicht nötig — ohne sie
schickt Python Python-urllib/…, und auch das kommt an. Setz trotzdem
am besten den Namen Deines Systems ein: Das hilft uns, wenn Du einmal eine
Frage zu einem bestimmten Aufruf haben.