How to Read Files from the API Response?

For certain features, the API delivers files as part of the response. These files may contain sensitive and confidential information, so it’s important to handle them securely.

Key Points to Remember

  • File Links Are Not Public — Any file links returned in the API response are private and require authentication.
  • Content Type — These file links have a Content-Type of application/octet-stream, indicating binary data.
  • Access Requires Token — Treat file links as additional API endpoints. You must include a valid access_token when making the request to retrieve them.
  • Direct Downloads from Portal — If you are logged into the application portal via a web browser, you can click the file link to download it directly.

Retrieving the File Programmatically

To retrieve a file:

  1. Extract the file URL from the API response.
  2. Make a GET request to this file URL with the Authorization header containing your access_token.
  3. Save the binary response data to a file in your local system.

Examples:

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

headers = {
  'Authorization': f'Bearer <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)

❗️

Security Tip:

Always store downloaded files securely, and ensure they are accessible only to authorized users.