Deleting multiple files

  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 files_data, and then assign an object containing the list of the file IDs in the file_ids key to this variable:

    >>> files_data = {
    ...     'file_ids': [
    ...         'aa95bac7-33fd-4faa-9fa1-f4baeaca82cd',
    ...         'ba635289-d3a1-45a2-a0ff-a8518607f656'
    ...     ]
    ... }
    
  3. Convert the files_data object to a JSON text:

    >>> files_data = json.dumps(files_data, indent=4)
    >>> print(files_data)
    {
        "file_ids": [
            "aa95bac7-33fd-4faa-9fa1-f4baeaca82cd",
            "ba635289-d3a1-45a2-a0ff-a8518607f656"
        ]
    }
    
  4. Send a DELETE request with the JSON text to the /stored-files endpoint:

    >>> response = requests.delete(
    ...     f'{base_url}/stored-files',
    ...     headers={'Content-Type': 'application/json', **auth},
    ...     data=files_data,
    ... )
    
  5. Check the status code of the response:

    >>> response.status_code
    200
    

    Status code 200 means that the notary service has deleted the files from the storage and decreased the usage of the Notary storage quota. If the files were signed or were being signed, their documents and the PDF files of the signature certificate have been also deleted.

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

    >>> pprint.pprint(response.json())
    {'deleted': [{'cert': '66692ad42b5e1c8baed89b225321182537164c46be6cb232f09b0121af8313b7',
                  ...
                  'id': 'aa95bac7-33fd-4faa-9fa1-f4baeaca82cd',
                  ...},
                 {'cert': '6cb238637164c46bebaed89b225321182572f09b0121af8313b6692ad42b5e1c',
                  ...
                  'id': 'ba635289-d3a1-45a2-a0ff-a8518607f656',
                  ...}]}
    
  6. Fetch the information about the files, and then save the notarization certificate IDs stored in the cert key. You will always be able to fetch this certificate by sending the GET request to the /certificates/{certificate_id} endpoint or to access the certificate web page at: https://eu2-cloud.acronis.com/notary/certificate/{certificate_id}

    >>> deleted_files = response.json()['deleted']
    >>> for file in deleted_files:
    ...     print(file['cert'])
    

Full code example