Creating a protection plan

  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
    'https://eu2-cloud.acronis.com/api'
    >>> auth  # the 'Authorization' header value with the access token
    {'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6ImMwMD...'}
    
  2. Import the uuid4 function from the uuid python module:

    >>> from uuid import uuid4
    
  3. Define a variable named protection_plan_id, and then assign the UUID generated with the uuid4() function and converted to string to this variable:

    >>> protection_plan_id = str(uuid4())
    '5b15f6e1-88ec-4dce-b523-0e8394c0bc19'
    
  4. Define a variable named plan_data, and then assign an object with the subject key with an object containing the policy key with an array containing a total protection policy to this variable:

    >>> plan_data = {
    ...     'subject': {
    ...         'policy': [
    ...             {
    ...                 'id': protection_plan_id,
    ...                 'type': 'policy.protection.total',
    ...                 'origin': 'upstream',
    ...                 'enabled': True,
    ...                 'name': 'My Protection Plan'
    ...             }
    ...         ]
    ...     }
    ... }
    
  5. Define the variable named policies and assign it with the list of protection policy objects. As an example, a machine backup policy with default settings will be included:

    Full code

    For more policy settings, refer to Protection policy settings.

  6. Merge the list of protection policy objects into the policy key of the plan_data object:

    >>> plan_data['subject']['policy'] += policies
    
  7. Convert the plan_data object to a JSON text:

    >>> plan_data = json.dumps(plan_data, indent=4)
    
  8. Send a POST request with the JSON text to the /policy_management/v4/policies endpoint:

    >>> response = requests.post(
    ...     f'{base_url}/policy_management/v4/policies',
    ...     headers={'Content-Type': 'application/json', **auth},
    ...     data=plan_data,
    ... )
    
  9. Check the status code of the response:

    >>> response.status_code
    200
    

    Status code 200 means that the protection plan has been created.

    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 result key containing an array of policy IDs formatted as a JSON text. When converted to an object, it will look as follows:

    >>> pprint.pprint(response.json())
    {'result': ['5b15f6e1-88ec-4dce-b523-0e8394c0bc19@policy.protection.total',
                '256f2ee5-c9fd-4aad-8607-97a977deeaae@policy.backup.machine',
                '260a95af-366f-4331-ad88-6f188f034870@policy.security.vulnerability_assessment',
                'fce55bf0-efb2-4220-b9bf-6fdebc5af660@policy.security.backups_scanning',
                'a1d5efa0-f9d7-4493-9bc9-c159879c7724@policy.security.windows_defender',
                '23f0fc3c-1b52-4da5-a765-fd856255b023@policy.security.patch_management',
                '9502bbc1-b37c-4617-8a8e-c174a945e98d@policy.security.microsoft_security_essentials',
                'f354c80f-5b7a-4466-97f1-df670cccb673@policy.security.antimalware_protection',
                '4f3c7359-2a83-40cf-9733-172253d85484@policy.security.data_protection_map',
                '3c496736-8fdf-48b7-bd4d-66c770448e83@policy.security.active_protection',
                '6c120d91-7ce3-463e-abae-b6c43ab27c87@policy.security.url_filtering']}