Content
"Add attachment to work package" API Endpoint - difficulties
Added by R B over 1 year ago
https://www.openproject.org/docs/api/endpoints/attachments/
"/api/v3/work_packages/{id}/attachmentsTo add an attachment to a work package, a client needs to issue a request of type
multipart/form-data
with exactly two parts.The first part must be called
metadata
. Its content type is expected to beapplication/json
, the body must be a single JSON object, containing at least thefileName
and optionally the attachmentsdescription
.The second part must be called
file
, its content type should match the mime type of the file. The body must be the raw content of the file. Note that afilename
must be indicated in theContent-Disposition
of this part, however it will be ignored. Instead thefileName
inside the JSON of the metadata part will be used."
I have tried coding a solution to this, I've tried a mock in Postman.
Possibly this is a language barrier, however, I nonetheless remain at a loss on how to upload a file and attach it to a workpackage via the API.
In postman, the response I get is simply a "400 bad request":
https://***/api/v3/work_packages/23921/attachments
"form-data" checked.
The below key value pairs:
Key: Value:
metadata {"fileName":"test.png"}
file file.png
I would very much appreciate anyone's time in pointing me in the right direction.
My eventual plan is to implement in Axios, but with a workable mock, I assume I can resolve this...
Replies (3)
This may come a little bit late, but there is a fairly straight-forward way to do this using bash. We link to a script for this in our docs.
But here is the essence of it:
R B wrote:
any one have solution in nodejs?