api_keys¶
The following methods allow for interaction with the ZTB API Key Auth Router API endpoints.
Methods are accessible via ztb.api_keys
Copyright (c) 2023, Zscaler Inc.
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- class APIKeyAuthRouterAPI¶
Bases:
APIClientClient for the ZTB API Key Auth resource.
Provides operations for managing API keys in the Zero Trust Branch API.
Endpoints live under
/api/v3/api-key-auth.- create_api_key(**kwargs)¶
Create a new API key.
- Parameters:
name (str) – The name for the new API key.
**kwargs – Optional keyword args.
- Returns:
Tuple of (APIKeyCreateResponse instance, response, error).
Examples
Create a new API key:
>>> created_key, _, error = client.ztb.api_keys.create_api_key( ... name="Python_New_API_Key", ... ) >>> if error: ... print(f"Error creating API key: {error}") ... return ... print(f"API key created successfully: {created_key.as_dict()}")
- list_api_keys(query_params=None)¶
Get all API keys.
- Returns:
Tuple of (list of APIKeyAuthRouter instances, response, error).
- Parameters:
query_params (dict) –
Map of query parameters for the request.
[query_params.search](str): Search string for filtering results.[query_params.page](int): Page number for pagination.[query_params.limit](int): Number of results per page.[query_params.sort](str): Field to sort by.[query_params.sortdir](str): Sort direction.
Examples
List all API keys:
>>> api_keys, _, error = client.ztb.api_keys.list_api_keys() >>> if error: ... print(f"Error listing API keys: {error}") ... return ... for key in api_keys: ... print(key.as_dict())
Client-side filtering with JMESPath:
The response object supports client-side filtering and projection via
resp.search(expression). See the JMESPath documentation for expression syntax.
- revoke_api_key(api_key_id)¶
Revoke an API key by ID.
- Parameters:
api_key_id (str) – The unique identifier of the API key to revoke.
- Returns:
Tuple of (None, response, error).
Examples
Revoke an API key:
>>> _, _, error = client.ztb.api_keys.revoke_api_key("abc-123") >>> if error: ... print(f"Error revoking API key: {error}") ... return ... print(f"API key 'abc-123' revoked successfully.")