Signing a file available by a permanent link
Start the Python shell and configure its session.
The following variables should be available now:
>>> base_url # the base URL of the API 'https://eu2-cloud.acronis.com/api/notary/v2' >>> auth # the 'Authorization' header value with the access token {'Authorization': 'Bearer 8770b34b74f9e4d9424eff50c38182bb4ae7f5596582ae61900b1b6a23e3ec58'}
Define a variable named
file_path
, and then assign the path to your file to this variable:>>> file_path = '<path to file>'
Important
If the path contains backslashes, remember to escape them with an additional backslash.
Define a variable named
file_link
, and then assign the permanent link to the file to this variable:>>> file_link = 'https://www.example.com/loremipsum'
Open the file for reading in binary mode:
>>> file = open(file_path, 'rb')
Calculate the hash value of the file contents by using the SHA-256 algorithm:
>>> sha256 = hashlib.sha256() >>> chunk = file.read(128 * sha256.block_size) >>> while chunk: ... sha256.update(chunk) ... chunk = file.read(128 * sha256.block_size) >>> file_hash '2c7c3d5f244f1a40069a32224215e0cf9b42485c99d80f357d76f006359c7a18'
A correctly calculated hash value of the file contents may help signees to prove, via the API, that the file they see in an email message with the signature request is indeed being signed by using the notary service.
Close the file:
>>> file.close()
Fetch the size of the file:
>>> file_size = os.path.getsize(file_path) >>> file_size 446
Fetch the file name from the file path:
>>> file_name = os.path.basename(file_path)
Define a variable named
file_info
, and then assign the information about the file to this variable:>>> file_info = { ... 'link': file_link, ... 'name': file_name, ... 'size': file_size, ... 'hash': file_hash ... }
Define a variable named
file_owner
, and then assign the information about the signing initiator who is considered to be the file owner to this variable:>>> file_owner = { ... 'email': 'john.doe@example.com', ... 'full_name': 'John Doe' ... }
Define a variable named
file_data
, and then assign an object with the following JSON parameters to this variable:>>> file_data = { ... 'file': file_info, ... 'owner': file_owner, ... 'exclude_me': False, ... 'lang': 'en' ... }
The
exclude_me
key defines whether to exclude the signing initiator from the list of signees.The
lang
key defines the language that will be used in email messages sent by the notary service during the signing and in the generated signature certificate file.Available values:
da - Danish
de - German
en - English
es - Spanish
fr - French
hu - Hungarian
it - Italian
ja - Japanese
ru - Russian
tr - Turkish
[Optional] To sign the file with embedded signatures of the signees, add the
embedded
key and set its value to true:>>> file_data['embedded'] = True
Note
In order to sign the file with embedded signature, it must comply with the following requirements:
The file must be either in PDF or in one of the following file types that will be converted to PDF by the notary service:
.doc/.docx
.xls/.xlsx
.ppt/.pptx
.txt
Maximum file size limit is 32 MB.
The file must not be protected by password.
If the uploaded file is in PDF, “Changing the Document” and “Commenting” permissions must be set to “Allowed”.
The link must be publicly accessible in order to be downloaded by the notary service.
Convert the
file_data
object to a JSON text:>>> file_data = json.dumps(file_data, indent=4)
Send a POST request with the JSON text to the
/documents
endpoint:>>> response = requests.post( ... f'{base_url}/documents', ... headers={'Content-Type': 'application/json', **auth}, ... data=file_data, ... )
Check the status code of the response:
>>> response.status_code 200
Status code 200 means that the notary service has received the object and created an e-sign document for it.
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 containing the ID of the document formatted as a JSON text. When converted to an object, it will look as follows:
>>> pprint.pprint(response.json()) { "document_id": "8592b052a9979f8d651618092bb3ac8472beebc66d52ab980deb4d320e26b0cb" }
Convert the JSON text that the response body contains to an object, and then fetch the ID of the e-sign document:
>>> doc_id = response.json()['document_id'] >>> doc_id '8592b052a9979f8d651618092bb3ac8472beebc66d52ab980deb4d320e26b0cb'
Define a variable named
signees
, and then assign an object containing the list of signees’ email addresses in theemails
key to this variable:>>> signees = { ... 'emails': ['john.smith@example.com', 'john.doe@example.com'] ... }
If you want to sign this file, include your email address in this list.
Warning
It will not be possible to change the list of signees after sending the initial list to the notary service.
[Optional] If you chose to embed the signee signatures in the file:
Follow the Generating PDF annotations procedure to fetch the list of PDF annotations.
Add the
annotations
key and assign it with the list of PDF annotations:>>> signees['annotations'] = [ ... "{\"bbox\":[129.81423950195312,216.01904296875,200,50], ...}", ... "{\"bbox\":[186.60797119140625,409.7261962890625,200,50], ...}" ... ]
Convert the
signees
object to a JSON text:>>> signees = json.dumps(signees, indent=4) >>> print(signees) { "emails": [ "john.smith@example.com", "john.doe@example.com" ] }
Send a POST request with the JSON text to the
/documents/{doc_id}/signees
endpoint:>>> response = requests.post( ... f'{base_url}/documents/{doc_id}/signees', ... headers={'Content-Type': 'application/json', **auth}, ... data=signees, ... )
Check the status code of the response:
>>> response.status_code 200
Status code 200 means that the notary service has initiated the signing and sent email messages with the signature request to the signees. To check the signing status, refer to Checking the status of signing process.
A different status code means that an error has occurred. For the details, refer to “Status and error codes”.