policy_group

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

Methods are accessible via zpa.policy_group

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 PolicyGroupAPI

Bases: APIClient

A Client object for the Policy Group resource.

add_group(group_set_id, **kwargs)

Add a new Policy Group to a Policy Group Set.

Parameters:
  • group_set_id (str) – The group set id.

  • name (str) – The name of the policy group.

  • **kwargs – Optional keyword args.

Keyword Arguments:
  • description (str) – Additional information about the policy group.

  • group_criteria_rule_gid (int) – The group criteria rule gid for this policy group.

  • group_order (int) – The group order for this policy group.

  • policy_group_set_gid (int) – The policy group set gid for this policy group.

  • microtenant_name (str) – The microtenant name for this policy group.

  • type (str) – The type for this policy group. Accepted values include e.g. GLOBAL.

  • group_criteria_rule (dict) – The ID of the group criteria rule for this policy group, e.g. {'id': 12345}.

  • microtenant_id (str) – The unique identifier of the Microtenant for the ZPA tenant.

Returns:

A tuple containing the newly added PolicyGroup instance, response, and error.

Return type:

tuple

Examples

Add a new policy group:

>>> added_group, _, error = client.zpa.policy_group.add_group(
...     'VALUE',
...     name=f"NewGroup_{random.randint(1000, 10000)}",
...     description=f"NewGroup_{random.randint(1000, 10000)}",
... )
>>> if error:
...     print(f"Error adding policy group: {error}")
...     return
... print(f"Policy group added successfully: {added_group.as_dict()}")
delete_group(group_set_id, group_id, microtenant_id=None)

Delete a Policy Group.

Parameters:
  • group_set_id (str) – The group set id.

  • group_id (str) – The unique identifier for the policy group.

  • microtenant_id (str, optional) – The microtenant ID, if applicable.

Returns:

A tuple containing the response object and error (if any).

Return type:

tuple

Examples

Delete a policy group:

>>> _, _, error = client.zpa.policy_group.delete_group('VALUE', '216196257331370181')
>>> if error:
...     print(f"Error deleting policy group: {error}")
...     return
... print(f"Policy group deleted successfully.")
get_group(group_set_id, group_id, query_params=None)

Get a specific Policy Group by ID within a Policy Group Set.

Parameters:
  • group_set_id (str) – The group set id.

  • group_id (str) – The unique identifier for the policy group.

  • query_params (dict, optional) – Map of query parameters for the request. [query_params.microtenant_id] {str}: The microtenant ID, if applicable.

Returns:

A tuple containing (PolicyGroup instance, Response, error).

Return type:

tuple

Examples

Print a specific policy group:

>>> fetched_group, _, error = client.zpa.policy_group.get_group('VALUE', '216196257331370181')
>>> if error:
...     print(f"Error fetching policy group by ID: {error}")
...     return
... print(f"Fetched policy group by ID: {fetched_group.as_dict()}")
list_groups(group_set_id, query_params=None)

Get All Policy Groups within a Policy Group Set.

Parameters:
  • group_set_id (str) – The group set id.

  • {dict} (query_params) – Map of query parameters for the request. [query_params.page] {str}: Specifies the page number. [query_params.page_size] {int}: Page size for pagination. [query_params.search] {str}: Search string for filtering results. [query_params.microtenant_id] {str}: ID of the microtenant, if applicable.

Returns:

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

Return type:

tuple

Examples

List policy groups:

>>> group_list, _, error = client.zpa.policy_group.list_groups('VALUE')
>>> if error:
...     print(f"Error listing policy groups: {error}")
...     return
... print(f"Total policy groups found: {len(group_list)}")
... for group in group_list:
...     print(group.as_dict())

List policy groups using filters:

>>> group_list, _, error = client.zpa.policy_group.list_groups(
...     'VALUE', query_params={'page': 'VALUE'})
>>> if error:
...     print(f"Error listing policy groups: {error}")
...     return
... print(f"Total policy groups found: {len(group_list)}")

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.

reorder_group(group_set_id, group_id, new_order, microtenant_id=None)

Update an existing Policy Group Order.

Parameters:
  • group_set_id (str) – The group set id.

  • group_id (str) – The unique identifier for the policy group.

  • new_order (str) – The new order position for the policy group.

  • microtenant_id (str, optional) – The microtenant ID, if applicable.

Returns:

A tuple containing the response object and error (if any).

Return type:

tuple

Examples

>>> _, _, error = client.zpa.policy_group.reorder_group('VALUE', '216196257331370181', '2')
>>> if error:
...     print(f"Error reordering policy group: {error}")
...     return
... print(f"Policy group reordered successfully.")
search_groups(group_set_id, **kwargs)

Get All Policy Groups within a Policy Group Set with advanced search and pagination.

Parameters:
  • group_set_id (str) – The group set id.

  • **kwargs – The advanced filter/page/sort payload, e.g. filter_and_sort_dto with filter_by / page_by / sort_by.

Returns:

A tuple containing the CommonFilterSearch instance (filter results, paging, sorting), response, and error.

Return type:

tuple

Examples

>>> result, _, error = client.zpa.policy_group.search_groups(
...     filter_and_sort_dto={
...         "filter_by": [{"filter_name": "name", "operator": "LIKE", "values": ["Test"]}],
...         "page_by": {"page": 1, "page_size": 20},
...     },
... )
>>> if error:
...     print(f"Error searching policy groups: {error}")
...     return
... print(result.as_dict())
update_group(group_set_id, group_id, **kwargs)

Update an existing Policy Group.

Parameters:
  • group_set_id (str) – The group set id.

  • group_id (str) – The unique identifier for the policy group.

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

  • description (str) – Additional information about the policy group.

  • group_criteria_rule_gid (int) – The group criteria rule gid for this policy group.

  • group_order (int) – The group order for this policy group.

  • policy_group_set_gid (int) – The policy group set gid for this policy group.

  • microtenant_name (str) – The microtenant name for this policy group.

  • type (str) – The type for this policy group. Accepted values include e.g. GLOBAL.

  • group_criteria_rule (dict) – The ID of the group criteria rule for this policy group, e.g. {'id': 12345}.

  • microtenant_id (str) – The unique identifier of the Microtenant for the ZPA tenant.

Returns:

A tuple containing the updated PolicyGroup instance, response, and error.

Return type:

tuple

Examples

Update an existing policy group:

>>> updated_group, _, error = client.zpa.policy_group.update_group(
...     'VALUE',
...     group_id='216196257331370181',
...     name=f"UpdatedGroup_{random.randint(1000, 10000)}",
...     description=f"UpdatedGroup_{random.randint(1000, 10000)}",
... )
>>> if error:
...     print(f"Error updating policy group: {error}")
...     return
... print(f"Policy group updated successfully: {updated_group.as_dict()}")