1#!/usr/bin/env python3
2
3import requests # Will be used for sending requests to the API.
4import hashlib # Will be used for calculating hash values.
5import os.path # Will be used for path-related operations.
6import pprint # Will be used for formatting the output of JSON objects received in API responses.
7import json # Will be used for converting dictionaries into JSON text
8
9# Define variables named "LOGIN" and "PASSWORD" and then assign them with your account credentials
10LOGIN = '<your login>' # Change login here
11PASSWORD = '<your password>' # Change password here
12
13# Define a variable named "cloud_url" and then assign it with the URL of the cloud platform
14cloud_url = 'https://cloud.acronis.com'
15
16# Fetch the URL of the data center where your account is located by sending a GET request to the "/api/1/accounts" endpoint
17response = requests.get(
18 f'{cloud_url}/api/1/accounts',
19 params={'login': LOGIN}
20)
21response.raise_for_status()
22
23# Convert the JSON text that the response body contains to a dictionary and store the data center URL
24# in a variable that will be used in further requests
25server_url = response.json()['server_url']
26
27# Define a variable named "account_creds", and then assign the username and password to this variable
28account_creds = {
29 'username': LOGIN,
30 'password': PASSWORD
31}
32
33# Generate a token by sending a POST request to the "/api/2/idp/token" with your account credentials to the cloud platform
34response = requests.post(
35 f'{server_url}/api/2/idp/token',
36 headers={'Content-Type': 'application/x-www-form-urlencoded'},
37 data={'grant_type': 'password', **account_creds}
38)
39response.raise_for_status()
40
41# Convert the JSON text that the response body contains to a dictionary and then assign it to a variable named "token_info"
42token_info = response.json()
43
44# Define a variable named "auth" and then assign it with a dictionary with "Authorization" key containing
45# token string formatted as "Bearer <access_token>"
46auth = {
47 'Authorization': 'Bearer ' + token_info['access_token']
48}
49
50# Define a variable named "base_url", and then assign the API base URL using the data center URL
51# to this variable
52base_url = f'{server_url}/api/notary/v2'
53
54# Define a variable named "template_id" and then assign it with an ID of the e-sign document template
55template_id = '3922edc2-d70d-4d5d-9789-5d739a6e7bdc'
56
57# Define a variable named "template_data", and then assign an object with a new name of the template to this variable
58template_data = {
59 'name': 'Contract Template'
60}
61
62# Convert the template_data object to a JSON text:
63template_data = json.dumps(template_data, indent=4)
64
65# Update the name of the e-sign document by sending a PUT request to the "/templates/{template_id}" endpoint
66response = requests.put(
67 f'{base_url}/templates/{template_id}',
68 headers={'Content-Type': 'application/json', **auth},
69 data=template_data,
70)
71response.raise_for_status()