Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,463,219
Community Members
 
Community Events
176
Community Groups

How do I add a file to the attachments section of an asset using the REST APIs?

Hi,

I tried to attach a text file to an asset using the assets REST API but for some reason I can't get the request right.

I took the request headers from this documentation: https://insight-javadoc.riada.io/assets-rest/#attachments_object__objectid__post because this other one doesn't describe the attachments endpoint although the endpoint exists https://developer.atlassian.com/cloud/assets/rest/api-group-aql/

My request:

POST /jsm/assets/workspace/{workspaceId}/v1/attachments/object/{objectId} HTTP/1.1

X-Atlassian-Token: no-check

Cache-Control: no-cache

Authorization: Basic XXXXXXXXXXXX
Postman-Token: XXXXXXXXXXX

Host: api.atlassian.com

Content-Type: multipart/form-data; boundary=--------------------------781657821705825765126353

 

----------------------------781657821705825765126353

Content-Disposition: form-data; name="file"; filename="fan.txt"

Content-Type: text/plain

<fan.txt>
----------------------------781657821705825765126353--

 

Here is the response I get:

HTTP/1.1 415 Unsupported Media Type

Date: Fri, 06 Jan 2023 13:40:32 GMT

Content-Type: application/json

Content-Length: 65

Cache-Control: no-cache, no-store, max-age=0, must-revalidate

Expires: 0

Pragma: no-cache

X-Computation-Group-Id: 4700a49f-dc08-455d-9e7f-477fc1dc97bc

X-Monolith-Alive: true

X-Pod-Type: standard

Vary: Accept-Encoding

Server: AtlassianEdge

X-Trace-Id: a144c572810f56b9

X-Frame-Options: SameOrigin

Expect-Ct: report-uri="https://web-security-reports.services.atlassian.com/expect-ct-report/stargate2", max-age=86400

X-Content-Type-Options: nosniff

X-Xss-Protection: 1; mode=block

Atl-Traceid: a144c572810f56b9

Report-To: {"endpoints": [{"url": "https://dz8aopenkvv6s.cloudfront.net"}], "group": "endpoint-1", "include_subdomains": true, "max_age": 600}

Nel: {"failure_fraction": 0.001, "include_subdomains": true, "max_age": 600, "report_to": "endpoint-1"}

Strict-Transport-Security: max-age=63072000; preload

 

{"errorMessages":["HTTP 415 Unsupported Media Type"],"errors":{}}

 

The request for getting the existing attachments from an asset works fine.

GET /jsm/assets/workspace/{workspaceId}/v1/attachments/object/{objectId} HTTP/1.1

Authorization: Basic XXXXXXXXXXXXXXXXXX

Postman-Token: XXXXXXXXXXXXXXX

Host: api.atlassian.com 

 

When I tried to add the same file to a jira issue instead of an asset the request worked.

POST /rest/api/2/issue/{issueKey}/attachments HTTP/1.1

X-Atlassian-Token: no-check

Authorization: Basic XXXXXXXXXXXXXXXXXXX
Postman-Token: XXXXXXXXXX

Host: your-domain.atlassian.net

Content-Type: multipart/form-data; boundary=--------------------------787394739551725715867800

Cookie: atlassian.xsrf.token=XXXXXXXXXXXXXXXXX
 

----------------------------787394739551725715867800

Content-Disposition: form-data; name="file"; filename="fan.txt"

Content-Type: text/plain

<fan.txt>

----------------------------787394739551725715867800--

 

Please help me with some answers to the following questions:

  1. What am I doing wrong at the first request? Should I use a different endpoint?
  2. Is this REST API only available on jira server https://insight-javadoc.riada.io/assets-rest/#? If not, how should I use it in jira cloud
  3. The endpoint which gets the attachments from an asset (the second request in the question) returns only the name of the file and other info but it doesn't return the file content. Is there a way to get the file content too?

Thank you

1 answer

1 accepted

1 vote
Answer accepted

Hi @CristinaVo  I'm also looking for a way to attach documents to objects on Jira Asset (Ex Insight) too.
Currently it is not possible with the official and documented APIs.
There is an open issue in Atlassian here: https://jira.atlassian.com/browse/JSDCLOUD-10454

Gabriele

Hi @Gabriele Cecco, I eventually found out about about this issue from the Atlassian support team, and I also voted it.

Thank you very much for your answer,

Cristina

Like Gabriele Cecco likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Site Admin
TAGS

Atlassian Community Events