Fetching signed and converted PDF files

Note

If you are signing the file by the permanent link and already have the ID of the document, skip steps 2-5.

  1. 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'}
    
  2. Define a variable named file_id, and then assign the ID of the file being or already signed to this variable:

    >>> file_id = 'aa95bac7-33fd-4faa-9fa1-f4baeaca82cd'
    
  3. Fetch the details about the file by sending a GET request to the /stored-files/{file_id} endpoint:

    >>> response = requests.get(f'{base_url}/stored-files/{file_id}', headers=auth)
    
  4. Check the status code of the response:

    >>> response.status_code
    200
    

    Status code 200 means that the request was successful.

    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 file key containing the details about the file formatted as a JSON text. When converted to an object, it will look as follows:

    >>> pprint.pprint(response.json())
    {'file': {..., 'document': {...},
              'document_id': '8592b052a9979f8d651618092bb3ac8472beebc66d52ab980deb4d320e26b0cb'}}
    
  5. Convert the JSON text that the response body contains to an object, and then fetch the ID of the document:

    >>> doc_id = response.json()['file']['document_id']
    >>> doc_id
    '8592b052a9979f8d651618092bb3ac8472beebc66d52ab980deb4d320e26b0cb'
    
  6. Fetch the details about the e-sign document by sending a GET request to the /documents/{doc_id} endpoint:

    >>> response = requests.get(f'{base_url}/documents/{doc_id}', headers=auth)
    
  7. Check the status code of the response:

    >>> response.status_code
    200
    

    Status code 200 means that the request was successful.

    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 document key containing the details about the e-sign document formatted as a JSON text. When converted to an object, it will look as follows:

    >>> pprint.pprint(response.json())
    {'document': {'certificate_id': '',
                  'id': '8eb2c5179b84a1b97a4f69eb0e97b4e910a1eace1b781926f83ee964f12e6922',
                  'signed_at': null,
                  'signature_certificate_link': '/doc/8eb2c5179b84a1b97a4f69eb0e97b4e910a1eace1b781926f83ee964f12e6922/download',
                  ...
                  'esign': {'embedded': True, 'converted_pdf_file_id': '60913aa1-3151-496a-a851-4063fd46982c'}
                  'signees': [{'email': 'johndoe@mycompany.com',
                               'fullname': 'John Doe',
                               'id': '867139bf-30ca-4c83-8683-a30c5db57046',
                               'owner': True,
                               'signed_at': '2019-11-11T13:54:38.619811Z'},
                              {'email': 'foobar@othercompany.com',
                               'fullname': 'Foo Bar',
                               'id': '32ff6407-605c-4203-a611-34deb036cda4',
                               'owner': False,
                               'signed_at': null}]},
     'document_id': '8eb2c5179b84a1b97a4f69eb0e97b4e910a1eace1b781926f83ee964f12e6922',
     ...}}
    
  8. Convert the JSON text that the response body contains to an object, and then fetch the value of the esign key of the document object:

    >>> esign = response.json()['document']['esign']
    
  9. Fetch the ID of the PDF file that needs to be downloaded:

    If the file has been converted to PDF by the notary service, the ID of the converted PDF file can be fetched from the converted_pdf_file_id key:

    >>> file_id = esign['converted_pdf_file_id']
    

    If the file has been signed by all the signees, the ID of the signed version of the PDF file can be fetched from the signed_file_id key:

    >>> file_id = esign['signed_file_id']
    
  10. Download the PDF file by following the Downloading a file procedure.

Full code example