curl command for uploading attachment to existing issue using API?
Added by Matthew Barham about 10 years ago
Hi ive looked through the help documentation but its not clear what i should be doing to upload an attachment to an existing issue using the api, it only talks about creating a new issue with an attachment.
does anybody know the curl command for upload attachment using xml and the api?
Replies (1)
RE: curl command for uploading attachment to existing issue using API?
-
Added by Lucile Quirion about 10 years ago
Hello,
Actually when I look at the documentation, I can find the information.
Maybe you'll better know how to improve the wiki and make it more clear.
I'll point you to the relevant pages:
Rest_Issues Here you get the HTTP command PUT /issues/[id].[format]
Rest_api Here you get example as how to format the JSON / XML data with uploads
Rest_api_with_curl Here you get an example of a curl command to update an issue
Also Redmine's tests are its best documentation: source:/trunk/test/integration/api_test/issues_test.rb
And don't forget curl's man page.
First step is to create your attachment and obtain your attachment's token.
$ curl -X POST -H "Content-Type: application/octet-stream" --data "My data" -u [login]:[password] [redmine_url]/uploads.json {"upload":{"token":"30.1d4ed6b0af083550da5c350ed65fc418"}}
Second step is to update the issue with the token:
$ curl -X PUT -H "Content-Type: application/json" --data "@issue.json" -u [login]:[password] [redmine_url]/issues/[id].json
Where issue.json file content is (replace token, filename and content_type):
{ "issue": { "notes": "Attachment added", "uploads": [ { "token": "30.1d4ed6b0af083550da5c350ed65fc418", "filename": "example.txt", "content_type": "text/plain" } ] } }
Note that attachments can be linked to only one container/Issue (Project, Document and Version are not yet supported).
You can't link an attachment to several issues (but the api will not return an error if you try).