microtenants

The following methods allow for interaction with the ZPA Microtenants API endpoints.

Methods are accessible via zpa.microtenants

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 MicrotenantsAPI

Bases: APIClient

A client object for the Microtenants resource.

add_microtenant(**kwargs)

Add a new microtenant.

Parameters:
  • name (str) – The name of the microtenant.

  • criteria_attribute (str) – The criteria attribute for the microtenant.

  • criteria_attribute_values (list) – The values for the criteria attribute.

Keyword Arguments:
  • description (str) – A description for the microtenant.

  • enabled (bool) – Whether the microtenant is enabled. Defaults to True.

  • privileged_approvals_enabled (bool) – Whether privileged approvals are enabled. Defaults to True.

Returns:

The resource record for the newly created microtenant.

Return type:

Microtenant

Examples

>>> microtenant = zpa.microtenants.add_microtenant(
        name="Microtenant_A",
        criteria_attribute="AuthDomain",
        criteria_attribute_values=["acme.com"]
    )
delete_microtenant(microtenant_id)

Deletes the specified microtenant.

Parameters:

microtenant_id (str) – The unique identifier for the microtenant to be deleted.

Returns:

Status code of the delete operation.

Return type:

int

Examples

>>> zpa.microtenants.delete_microtenant('99999')
get_microtenant(microtenant_id)

Returns information on the specified microtenant.

Parameters:

microtenant_id (str) – The unique identifier for the microtenant.

Returns:

Microtenant: The resource record for the microtenant.

Return type:

Tuple

Examples

>>> fetched_microtenant, _, err = client.zpa.microtenants.get_microtenant('999999')
... if err:
...     print(f"Error fetching microtenant by ID: {err}")
...     return
... print(fetched_microtenant.id)

Gets all configured Microtenants for the specified customer based on given filters.

Parameters:

**kwargs – Keyword arguments that define search filters, pagination, and sorting criteria.

Keyword Arguments:

filter_and_sort_dto (dict) –

A dictionary containing filtering, pagination, and sorting information.

  • filter_by (list): A list of filter condition dictionaries.

    • filter_name (str): The name of the field to filter on (e.g., name, criteria_attribute_values).

    • operator (str): The logical operator (e.g., EQUALS, LIKE).

    • values (list): A list of values to match.

    • comma_sep_values (str, optional): Optional comma-separated string version of values.

  • page_by (dict, optional): Dictionary containing pagination configuration.

    • page (int): The current page number.

    • page_size (int): The number of records per page.

    • valid_page (int, optional): Optional page validation flag.

    • valid_page_size (int, optional): Optional page size validation flag.

  • sort_by (dict, optional): Dictionary defining sorting options.

    • sort_name (str): The name of the field to sort by (e.g., name).

    • sort_order (str): Sorting direction (e.g., ASC or DESC).

Returns:

A tuple containing:

  • MicrotenantSearch: The parsed response object containing filter results, paging, and sorting.

  • Response: The raw response object returned by the request executor.

  • Error: An exception if one occurred, otherwise None.

Return type:

tuple

Example

>>> search_payload = {
...     "filter_and_sort_dto": {
...         "filter_by": [
...             {
...                 "filter_name": "criteria_attribute_values",
...                 "operator": "LIKE",
...                 "values": ["Test"]
...             }
...         ],
...         "page_by": {
...             "page": 1,
...             "page_size": 20
...         },
...         "sort_by": {
...             "sort_name": "name",
...             "sort_order": "ASC"
...         }
...     }
... }
>>> result, _, err = client.zpa.microtenants.get_microtenant_search(**search_payload)
>>> if err:
...     print(f"Error searching microtenants: {err}")
... else:
...     for item in result.filter_by:
...         print(item.request_format())
get_microtenant_summary()

Returns the name and ID of the configured Microtenant.

Returns:

Microtenant: The resource record for the microtenant.

Return type:

Tuple

Examples

>>> microtenants_list, err = client.zpa.microtenants.get_microtenant_summary()
... if err:
...     print(f"Error listing microtenants: {err}")
...     return
... print(f"Total microtenants found: {len(microtenants_list)}")
... for microtenant in microtenants_list:
...     print(microtenant.as_dict())
list_microtenants(query_params=None)

Enumerates microtenants in your organization with pagination. A subset of microtenants can be returned that match a supported filter expression or query.

Parameters:

{dict} (query_params) – Map of query parameters for the request. [query_params.page_size] {int}: Page size for pagination. [query_params.search] {str}: Search string for filtering results. [query_params.include_roles] {bool}: Include roles information in the API response. Default value: False

Returns:

A tuple containing (list of Microtenants instances, Response, error)

>>> microtenant_list, _, err = client.zpa.microtenants.list_microtenants(
... query_params={'search': 'Microtenant_A', 'page': '1', 'page_size': '100'})
... if err:
...     print(f"Error listing microtenants: {err}")
...     return
... print(f"Total certificates found: {len(microtenant_list)}")
... for tenant in microtenant_list:
...     print(tenant.as_dict())

Return type:

Tuple

update_microtenant(microtenant_id, **kwargs)

Updates the specified microtenant.

Parameters:

microtenant_id (str) – The unique identifier for the microtenant being updated.

Keyword Arguments:
  • name (str) – The name of the microtenant.

  • description (str) – A description for the microtenant.

  • enabled (bool) – Whether the microtenant is enabled. Defaults to True.

  • privileged_approvals_enabled (bool) – Whether privileged approvals are enabled. Defaults to True.

  • criteria_attribute (str) – The criteria attribute for the microtenant.

  • criteria_attribute_values (list) – The values for the criteria attribute.

Returns:

The updated resource record for the microtenant.

Return type:

Microtenant

Examples

>>> updated_microtenant = zpa.microtenants.update_microtenant(
        microtenant_id="216199618143368569",
        name="Microtenant_A",
        enabled=False
    )