How to read file from the response

Compliancely delivers files through the API response for certain features. Some of these files contain sensitive and confidential information.

It's important to note that any links within any API response, are not public and have a Response Content-Type of application/octet-stream. As a result, these links should be treated as additional API endpoints, and they require an access_token for access. Using the access_token, triggering the file link as an API endpoint is necessary. The resulting data from the response should be stored in a file. Below is an example in cURL & Python illustrating how to save this data. Users who wish to open these links in a web browser while logged into the Compliancely portal can download the files directly.

curl -X GET "<file link>" -H "Authorization: Token <Authtoken>" -o "<dir>/<filename>.<ext>"
import requests
import os

headers = {
  'Authorization': f'Token <Authtoken>'
}
response = requests.get('<file link>', headers=headers)
destination_file_name = "{}.{}".format(<filename>,<extention>)
destination_file_path = os.path.join(<dir>, destination_file_name)
with open(destination_file_path, 'wb') as file:
    file.write(response.content)