3.5 Python Examples

Python code examples for interacting with the JSONAir API.

The following examples use only the Python standard library. No third-party HTTP client is required.


Authentication — Get a Bearer Token

import json
import urllib.request
import urllib.error


def get_token(base_url: str, pat: str) -> str:
    payload = json.dumps({"token": pat}).encode()
    req = urllib.request.Request(
        f"{base_url}/api/v1/jsonair/auth/token",
        data=payload,
        headers={"Content-Type": "application/json"},
        method="POST",
    )
    with urllib.request.urlopen(req) as resp:
        body = json.loads(resp.read())
    return body["access_token"]

Fetch Configuration Data


Putting It Together — Poll with Re-Authentication

This pattern mirrors what the JSONAir agent does: authenticate once, poll on an interval, and re-authenticate automatically when the JWT expires.


Fetch the Reload Key


Fetch the Debug Level

Last updated