Verifying the authenticity of multiple files by sending them to the notary service
Important
When sending multiple files, total size of all files cannot be larger than 1 GiB.
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_paths_certificate_ids
, and then assign an object with file paths as keys and notarization certificate IDs as values to this variable:>>> file_paths_certificate_ids = { ... '<path to file 1>': '7605f73deaee7b071a570b3ac20cc9fe7a3abf337be7c86c55c28af9d3d8435c', ... '<path to file 2>': 'c7be6b0e99c854d1b8fc233a21beabecc1229a6061fe3b1c15a6cbf27222a35e' ... }
Important
If the path contains backslashes, remember to escape them with an additional backslash.
Prepare the request data:
Define
multiple_files
andfiles_data
variables and assign an empty list to them:>>> multiple_files = [] >>> files_data = []
Create a loop that will iterate over the object with file paths and their notarization certificate IDs:
>>> for file_path, certificate_id in file_paths_certificate_ids.items(): ... # Fetch the file name from the file path ... file_name = os.path.basename(file_path) ... # Handle "FileNotFoundError" exception and do not add file data if file was not found ... try: ... # Open the file for reading in binary mode and append it to the list of multiple files ... multiple_files.append( ... (file_name, (file_name, open(file_path, 'rb'))) ... ) ... except FileNotFoundError: ... print(f'{file_path} does not exist.') ... continue ... # Append an object with the file name and notarization certificate ID corresponding to it to the "files_data" list ... files_data.append( ... { ... 'key': file_name, ... 'certificate_hash': certificate_id ... } ... )
Convert the
files_data
object to a JSON text:>>> files_data = json.dumps(files_data, indent=4)
Send the files to the notary service for verification by sending a POST request to the
/files/verify_batch
endpoint:>>> response = requests.post( ... f'{base_url}/files/verify_batch', ... files=multiple_files, ... data={'files_data': files_data}, ... )
Note
The
/files/verify_batch
endpoint does not require authentication soAuthorization
header can be safely omitted.Close the files:
>>> for file in multiple_files: ... file[1][1].close()
Check the status code of the response:
>>> response.status_code 200
Status code 200 means that the notary service has found the notarization certificate for at least one of the files (the file is notarized or is being notarized) and responded to you with this data. If the status code is 404, no certificates are found (the service has never received and notarized provided files).
A different status code means that an error has occurred. For the details, refer to “Status and error codes”.
Also, the response body contains the
certificates
key containing an array of notarization certificate objects formatted as a JSON text. When converted to an object, it will look as follows:>>> pprint.pprint(response.json()) {'certificates': [{'contract': '0xd10e3Be2bc8f959Bc8C41CF65F60dE721cF89ADF', 'eventtime': '2019-11-11T13:07:07.004366Z', 'id': '7605f73deaee7b071a570b3ac20cc9fe7a3abf337be7c86c55c28af9d3d8435c', 'merkle_proof': '[{"left":"88c20ca21dd6fa9e0a64c7e981a012812bbca152010195cd4296d959cfa35f1e"}]', 'merkle_root': '6d05fb9f0c2cff4942987661a44e71f0f554d435ce494dd3e7a21df6c6ba963c', 'notarized_location': 'beta-baas', 'object': {'eTag': '2c7c3d5f244f1a40069a32224215e0cf9b42485c99d80f357d76f006359c7a18', 'key': '<file name 1>', 'sequencer': 'DEF04BD0C5114542F8', 'size': 446}, 'blockchain': 'eth', 'qr_code': 'data:image/png;base64,iVBORw0KGgoAAAANSUh...', 'sender': '0x201354729f8d0f8b64e9a0c353c672c6a66b3857', 'signee_details': {'tenant_name': 'John Doe'}, 'timestamp': 1573572432, 'txid': '0x6494a098f6487ebbcfa85b7cbe64c1f9f077f03866477b67be64320ea109fa73', 'version': '3.1'}, {'contract': '', 'eventtime': None, 'id': '', 'merkle_proof': '', 'merkle_root': '', 'object': None, 'sender': '', 'timestamp': 0, 'txid': ''}]}
If the
id
key is empty, this means that the file was not sent for notarization.If the notarization is complete:
The
txid
key contains the hash of the blockchain transaction that can be viewed on https://etherscan.io/tx/{txid}.The
contract
,sender
,merkle_root
, andmerkle_proof
keys contain the blockchain transaction details.The
timestamp
key contains the Unix time when the hash value of the file contents was written to the blockchain (notarization completion time).The
eTag
key of theobject
object contains the actual hash value that was written to the blockchain.The web version of the notarization certificate is available at
https://eu2-cloud.acronis.com/notary/certificate/{certificate_id}
.
Empty
txid
,contract
,merkle_proof
,merkle_root
, andsender
keys mean that the notarization is still in progress and the web version of the certificate is not created yet.