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:
- What am I doing wrong at the first request? Should I use a different endpoint?
- 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
- 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