Fetching a list of plans applicable for a resource

  1. Authenticate to the cloud platform via the Python shell.

    The following variables should be available now:

    >>> base_url  # the base URL of the API
    >>> auth  # the 'Authorization' header value with the access token
    {'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6ImMwMD...'}
  2. Fetch the resources as described in Fetching a list of all resources, then define the resource_id variable and assign it with the ID of a resource. As an example, the ID of the first resource will be taken:

    >>> resource_id = resources[0]['id']
    >>> resource_id
  3. Define a variable named filters, and then assign an object containing the resource ID in the applicable_to_context_id key to this variable:

    >>> filters = {
    ...     'applicable_to_context_id': resource_id
    ... }


    To fetch plans that are applicable to multiple resources, provide the resource IDs in the following format: or(5b15f6e1-88ec-4dce-b523-0e8394c0bc19,c70134c4-a244-4b22-99ad-e081301f7530)

  4. Send a GET request to the /policy_management/v4/policies endpoint:

    >>> response = requests.get(f'{base_url}/policy_management/v4/policies', headers=auth, params=filters)
  5. Check the status code of the response:

    >>> response.status_code

    Status code 200 means that the request was successful.

    A different status code means that an error has occurred. For the details, refer to “Status and error codes”.

    Also, the response body contains an object with the items key containing an array of protection policy objects formatted as a JSON text. When converted to an object, it will look as follows:

    >>> pprint.pprint(response.json())
    {'items': [{'policy': [{'created_at': '2020-03-19T21:01:17.548049845Z',
                            'days_without_backup_alert': None,
                            'default_name_template_id': '',
                            'deleted_at': None,
                            'enabled': True,
                            'id': 'd7836ee7-203a-4037-be0b-cabff37fa267',
                            'ls_features': '',
                            'name': 'My Protection Plan',
                            'origin': 'upstream',
                            'plan_hash': '',
                            'root_template_id': '',
                            'source_type': '',
                            'template': True,
                            'template_source_id': '',
                            'tenant_id': '23',
                            'type': 'policy.protection.total',
                            'updated_at': '2020-03-19T21:02:29.031812085Z'},
     'paging': {'cursors': {'total': 1}}}