diff --git a/README.md b/README.md index dfac883..34161a4 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ The following values can either be added to the `config.yaml` file or entered wh - PlexTrac Top Level Domain e.g. https://yourapp.plextrac.com - Username - Password +- Client ID (optional): used by the example `get_client` call; if omitted, the script uses the first client you have access to ## Script Execution Flow - Starts executing the main.py file diff --git a/config.yaml b/config.yaml index ac4c0a5..02b44c1 100644 --- a/config.yaml +++ b/config.yaml @@ -2,3 +2,4 @@ instance_url: username: password: +# client_id: optional - used by example script; if omitted, first accessible client is used diff --git a/main.py b/main.py index ab2863d..f9d2042 100644 --- a/main.py +++ b/main.py @@ -69,8 +69,26 @@ def main(): """ import api - client_id = "" - response = api.clients.get_client(auth.base_url, auth.get_auth_headers(), client_id) + # Get a real client ID: from config, or list clients first to pick one + client_id = args.get('client_id') + if not client_id: + clients_response = api.clients.list_tenant_clients(auth.base_url, auth.get_auth_headers(), auth.tenant_id) + if clients_response and 200 <= clients_response.status_code < 300: + clients = clients_response.json + # Response shape varies; extract first client id (e.g. from doc_id or data) + if isinstance(clients, list) and clients: + first = clients[0] + client_id = first.get('doc_id', [first.get('id')])[0] if isinstance(first, dict) else first + elif isinstance(clients, dict) and clients.get('data'): + client_id = clients['data'][0].get('doc_id', [clients['data'][0].get('id')])[0] + else: + client_id = None + else: + client_id = None + if not client_id: + log.warning("No clients found. Add client_id to config.yaml or ensure your user has access to clients.") + if client_id: + response = api.clients.get_client(auth.base_url, auth.get_auth_headers(), client_id) """