Last active
June 10, 2026 13:59
-
-
Save fredrik/13439c8683e0e7ec285d7a9b8aceb3c4 to your computer and use it in GitHub Desktop.
Cinode API client
This file contains hidden or 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
| 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() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: