api_keys¶
The following methods allow for interaction with the ZPA API Keys Controller API endpoints.
Methods are accessible via zpa.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 ApiKeysAPI¶
Bases:
APIClientA Client object for the Api Keys resource.
- add_api_key(**kwargs)¶
Adds a new ZPA API Key.
- Parameters:
name (str) – The name of the API Key.
- Keyword Arguments:
- Returns:
A tuple containing: - An empty dictionary {} on success (due to 204 No Content), - The raw Response object, - Or an Exception if an error occurred. - This returns the client_secret attribute
- Return type:
Tuple[dict, Response, Exception]
Examples
>>> added_key, _, err = client.zpa.api_keys.add_api_key( ... name=f"NewAPIKey_{random.randint(1000, 10000)}", ... enabled=True, ... token_expiry_time_in_sec= '3600', ... role_id='28', ... ) ... if err: ... print(f"Error creating api key: {err}") ... return ... print(f"API key created successfully: {added_key.as_dict()}") ... key_dict = added_key.as_dict() ... client_secret = key_dict.get('client_secret') ... print(f"Client Secret: {client_secret}")
- delete_api_key(key_id, microtenant_id=None)¶
Deletes the specified API Key from ZPA.
- Parameters:
- Returns:
A tuple containing the response and error (if any).
- Return type:
Examples
>>> _, _, err = client.zpa.api_keys.delete_key_id( ... key_id='999999' ... ) ... if err: ... print(f"Error deleting api key: {err}") ... return ... print(f"API Key with ID {'999999'} deleted successfully.")
- get_api_key(key_id, query_params=None)¶
Fetches a specific api key by ID.
- Parameters:
- Returns:
A tuple containing (ApiKeys instance, Response, error).
- Return type:
Tuple
Examples
>>> fetched_key, _, err = client.zpa.api_keys.get_api_key('999999') ... if err: ... print(f"Error fetching key by ID: {err}") ... return ... print(f"Fetched key by ID: {fetched_key.as_dict()}")
- list_api_keys(query_params=None)¶
List all API keys details.
- Parameters:
{dict} (query_params) –
Map of query parameters for the request.
[query_params.page]{str}: Specifies the page number.[query_params.page_size]{str}: Specifies the page size.If not provided, the default page size is 20. The max page size is 500.
[query_params.search]{str}: Search string for filtering results.[query_params.microtenant_id]{str}: The unique identifier of the microtenant of ZPA tenant.- Returns:
A tuple containing (list of ApiKeys instances, Response, error)
- Return type:
Tuple
Examples
>>> key_list, _, err = client.zpa.api_keys.list_api_keys( ... query_params={'search': 'ZPA_Dev01', 'page': '1', 'page_size': '100'}) ... if err: ... print(f"Error listing api key: {err}") ... return ... print(f"Total api key found: {len(key_list)}") ... for key in keys: ... print(key.as_dict())
- update_api_key(key_id, **kwargs)¶
Update a new ZPA API Key.
- Parameters:
- Keyword Arguments:
- Returns:
A tuple containing: - An empty dictionary {} on success (due to 204 No Content), - The raw Response object, - Or an Exception if an error occurred. - This method does not return the client_secret attribute
The dictionary is always empty since the API returns no response body.
- Return type:
Tuple[dict, Response, Exception]
Examples
>>> added_key, _, err = client.zpa.api_keys.add_api_key( ... name=f"NewAPIKey_{random.randint(1000, 10000)}", ... enabled=True, ... token_expiry_time_in_sec= '3600', ... role_id='28', ... ) ... if err: ... print(f"Error creating api key: {err}") ... return ... print(f"API key created successfully: {added_key.as_dict()}")