How to use Postman to interact with the attachments endpoint

Sravya Bandari
Sravya Bandari
  • Updated

 

Author: Sravya Bandari

Date: Nov 17th, 2023

Audience: Everyone

Summary:

How to use Postman with the 'attachments' API endpoint. Step-by-Step

Steps:

This is a step-by-step guide to the following documentation

   ( Basic Authentication is used in this example, but you can also utilize API credentials if preferred.)

  1. Create an attachment item:
    • Endpoint: POST /rest/v1/projects/{projectID}/attachments 
    • Request Body: Copy the following code block under the "Raw" section, and choose the JSON format (adjust the name and description as needed).

      { "fields": { "name": "Poppy Flower", "description": "A pretty picture" } }
    • Response code: 201 Created
    • Click the "Send" button to initiate the POST request.
    • Response body:
      { "meta": { "status": "Created", "timestamp": "2023-05-26T09:02:11.937+0000", "location": "https://xxx.jamacloud.com/rest/v1/attachments/12538", "id": 12538 } }

  2. Upload the attachment file using the attachment ID obtained in the first step:
    • Endpoint: PUT /rest/v1/attachments/{attachmentID}/file (attachmentID: 12358)
    • In the "Body" section, select "form-data" as the body type.
    • Add a new key-value pair in the form-data:
      • Key: file (or any suitable key)
      • Value: Select the file you want to upload using the "Select Files" button.
    • Click the "Send" button to initiate the PUT request.

  3. Associate the attachment with an item:
    • Endpoint: POST /rest/v1/items/{itemID}/attachments
    • Request body: Copy the following code block under the "Raw" section, and choose the JSON format (adjust the attachment value as needed).
      { "attachment": 12538 }
    • Click the "Send" button to initiate the POST request.



  4. Use the GET /rest/v1/attachments/{attachmentID} (attachmentID: 12538)

"data": { ---------------------------------------------------------- (This section contains the details of the attachment item)
"id": 12538, --------------------------------------------------- (The ID of the attachment item is 12091)
"documentKey": "SYS_SOL-ATT-17",
"globalId": "GID-57723",
"itemType": 22,
"project": 18,
"createdDate": "2023-08-17T12:22:49.000+0000",
"modifiedDate": "2023-08-17T12:39:00.000+0000",
"lastActivityDate": "2023-08-17T12:39:00.000+0000",
"createdBy": 13,
"modifiedBy": 13,
"fields": { ----------------------------------------------------- (This section contains additional fields associated with the attachment item)
"attachment": 401, -------------------------------------------- (The value of this field (294) represents the attachment value stored in the fields section, not the attachment item's ID.)
"globalId": "GID-57723",
"name": "Poppy Flower",
"description": "A pretty picture"
},
"resources": {
"self": {
"allowed": [
"GET"
]
}
},
"fileName": "20230717_JamaSupport.txt",
"mimeType": "text/plain",
"fileSize": 14312,
"type": "attachments"
}
}


From the provided response code, it may seem that the attachment ID is 294. However, it is important to note that the attachment value specified within the "attachment" field in the "fields" section does not directly represent the attachment item's ID. Instead, it refers to the attachment value stored within the fields section of the attachment object

 

 

 

 

 

 

 

Related to

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.