Using the files endpoint (REST API) to download attachments

Erik Haake
Erik Haake
  • Updated

Author: Erik Haake

Date: 6/9/25

Audience: Everyone

Environmental details: Cloud and Self-Hosted

Summary

While there are a number of ways to download attachments from items in Jama, this guide will go over how to use the /files endpoint to download inline, or "implicit" attachments from items. Implicit attachments are files that are added to rich text fields such as description fields. This does not apply to files that are attached to items via the Attachments field.

Solution

When a file is added to a rich text field by copy/pasting, dragging/dropping or using the "Add image" button above the RTF, it will be assigned a url based on its filename. This type of attachment is sometimes known as an "implicit" attachment. The url for the attachment can be found by clicking the "Source" button in the rich text field toolbar, which displays the markup for all the content in the field. The url follows the "src" tag in the markup. 

An example is shown below:

 

To download this file using the /files endpoint, you need to supply the url of the attachment in its entirety as a query parameter. The resulting request url will look like the following:

https://ehaake-robotics.jamacloud.com/rest/v1/files?url=https://ehaake-robotics.jamacloud.com/attachment/905/catpic.jpeg

 

Saving the file

The files endpoint returns binary blob data and so will need to be handled and saved appropriately. It will not be returned from the server with its original title so once it is downloaded, it will need to be renamed with the appropriate title and file extension.

Below is a simple python script which does this:

import os
import requests

JAMA_URL = "https://ehaake-robotics.jamacloud.com"
AUTH_HEADERS = {
 'Authorization': 'Bearer <your token here>',
 'Cookie': '<fill this in>'

# Directory on your local machine
DOWNLOAD_DIR = "jama_attachments"

def download_file(file_url, local_path):
   """
   Download a file from `file_url` and save it to `local_path`,
   using AUTH_HEADERS for REST API authentication.
   """

   attachment_file = requests.get(file_url, headers=AUTH_HEADERS)
   attachment_file.raise_for_status()

   os.makedirs(os.path.dirname(local_path) or ".", exist_ok=True)
   with open(local_path, "wb") as f:
       f.write(attachment_file.content)

if __name__ == "__main__":
   file_url = "https://ehaake-robotics.jamacloud.com/rest/v1/files?url=https://ehaake-robotics.jamacloud.com/attachment/905/catpic.jpeg"
   save_as  = os.path.join(DOWNLOAD_DIR, "filename.png")
   download_file(file_url, save_as) 

 

Additional Information/Metadata

  • Attachments
  • Files
  • Download
  • REST API

References

 

Please feel free to leave feedback in the comments below.

 

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.