Skip to content

Instantly share code, notes, and snippets.

@fredrik
Last active June 10, 2026 13:59
Show Gist options
  • Select an option

  • Save fredrik/13439c8683e0e7ec285d7a9b8aceb3c4 to your computer and use it in GitHub Desktop.

Select an option

Save fredrik/13439c8683e0e7ec285d7a9b8aceb3c4 to your computer and use it in GitHub Desktop.
Cinode API client
import json
import logging
import os
import httpx
COMPANY_ID = undefined
CINODE_API_URL = "https://api.cinode.com/v0.1/"
logger = logging.getLogger(__name__)
def get_data(client: httpx.Client, endpoint: str, return_empty_data_for_codes=None):
if return_empty_data_for_codes is None:
return_empty_data_for_codes = []
response = client.get(endpoint)
code = response.status_code
if code in return_empty_data_for_codes:
return {}
if code == 401:
logger.error(
"Unauthorized response from Cinode for endpoint %s. "
"The configured API token may be invalid or expired.",
endpoint,
)
response.raise_for_status()
try:
return response.json()
except json.JSONDecodeError:
body_preview = response.text[:200].replace("\n", "\\n")
logger.warning(
"Failed to decode JSON response for endpoint %s. "
"Status=%s, body_preview=%r. Returning empty response.",
endpoint,
code,
body_preview,
)
return {}
def main():
api_token = os.environ["CINODE_API_TOKEN"]
headers = {"Authorization": f"Bearer {api_token}", "Accept": "application/json"}
with httpx.Client(base_url=CINODE_API_URL, headers=headers) as client:
users = get_data(client, f"companies/{COMPANY_ID}/users")
print(json.dumps(users, indent=2))
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
main()
@fredrik

fredrik commented Jun 10, 2026

Copy link
Copy Markdown
Author

Usage:

export CINODE_API_TOKEN='..'
uv run --with httpx cinode.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment