Updating a policy or protection plan
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...'}
Fetch the protection policies as described in Fetching a list of policies and protection plans, then define the
policy_id
variable and assign it with the ID of a protection policy. As an example, the ID of the first policy will be taken:>>> policy_id = policies[0]['id'] >>> policy_id 33965f81-7293-45d4-9f13-dc4281d7bdfd
Define a variable named
policy_status
, and then assign an object with thesubject
key containing a policy to this variable:>>> policy_status = { ... "subject": { ... "policy": [ ... { ... "enabled": true ... } ... ] ... } ... }
For the list of available JSON parameters, refer to the API reference.
Convert the
policy_status
object to a JSON text:>>> policy_status = json.dumps(policy_status, indent=4)
Send a PATCH request with the JSON text to the
/policy_management/v4/policies/{policy_id}
endpoint:>>> response = requests.patch( ... f'{base_url}/policy_management/v4/policies/{policy_id}', ... headers={'Content-Type': 'application/json', **auth}, ... data=policy_status, ... )
Check the status code of the response:
>>> response.status_code 204
Status code 204 means that the plan has been updated without any issues.
A different status code means that an error has occurred. For the details, refer to “Status and error codes”.