How can i add a comment to a issue via REST API?
Added by Bartłomiej Ekiert almost 7 years ago
Hi.
How can i add a comment to a issue via REST API?
Thank you for response.
Nest Regards
Bartłomeiej
Replies (5)
RE: How can i add a comment to a issue via REST API? - Added by Mayama Takeshi almost 7 years ago
Hi,
see: http://www.redmine.org/projects/redmine/wiki/Rest_Issues#Updating-an-issue
here is an example using curl:
curl -x '' -H 'X-Redmine-API-Key: YOUR_API_KEY' http://YOUR_REDMINE_SERVER/issues/ISSUE_ID.json -X PUT -H 'Content-Type: application/json' -d '{"issue": {"notes": "This is a note added via API"}}'
RE: How can i add a comment to a issue via REST API? - Added by Brian Rose about 6 years ago
Trying the following command. The Note does not show up in the issue. I can log into the project and update the issue via the web browser, so I know its not a permissions issue.
Note: I am using SSL with a self signed certificate.
I can view the issue in a web browser - https://servername/issues/1
$ curl -v -H "Content-Type: application/xml" -X POST -d '{"issue": {"notes": "This is a note added via API"}}' -k -u username https://servername/issues/1.json
The status reports Status: 400 Bad Request. Any ideas?
Enter host password for user 'username': Note: Unnecessary use of -X or --request, POST is already inferred. * STATE: INIT => CONNECT handle 0x6000578f0; line 1410 (connection #-5000) * Added connection 0. The cache now contains 1 members * Trying servername... * TCP_NODELAY set * STATE: CONNECT => WAITCONNECT handle 0x6000578f0; line 1462 (connection #0) * Connected to servername (serverip) port 443 (#0) * STATE: WAITCONNECT => SENDPROTOCONNECT handle 0x6000578f0; line 1579 (connection #0) * Marked for [keep alive]: HTTP default * ALPN, offering h2 * ALPN, offering http/1.1 * Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH * successfully set certificate verify locations: * CAfile: /etc/pki/tls/certs/ca-bundle.crt CApath: none * TLSv1.2 (OUT), TLS header, Certificate Status (22): * TLSv1.2 (OUT), TLS handshake, Client hello (1): * STATE: SENDPROTOCONNECT => PROTOCONNECT handle 0x6000578f0; line 1593 (connection #0) * TLSv1.2 (IN), TLS handshake, Server hello (2): * TLSv1.2 (IN), TLS handshake, Certificate (11): * TLSv1.2 (IN), TLS handshake, Server key exchange (12): * TLSv1.2 (IN), TLS handshake, Server finished (14): * TLSv1.2 (OUT), TLS handshake, Client key exchange (16): * TLSv1.2 (OUT), TLS change cipher, Client hello (1): * TLSv1.2 (OUT), TLS handshake, Finished (20): * TLSv1.2 (IN), TLS change cipher, Client hello (1): * TLSv1.2 (IN), TLS handshake, Finished (20): * SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384 * ALPN, server did not agree to a protocol * Server certificate: * subject: C=US; ST=Florida; L=City; O=MyOrg; OU=Engineering; CN=servername; emailAddress=username@MyOrg.com * start date: Aug 29 00:53:51 2018 GMT * expire date: Aug 29 00:53:51 2019 GMT * issuer: C=US; ST=Florida; L=City; O=MyOrg; OU=Engineering; CN=servername; emailAddress=username@MyOrg.com * SSL certificate verify result: self signed certificate (18), continuing anyway. * STATE: PROTOCONNECT => DO handle 0x6000578f0; line 1614 (connection #0) * Server auth using Basic with user 'username' > POST /issues/1.json HTTP/1.1 > Host: servername > Authorization: Basic YnJvc2U6a3d5amliMCE= > User-Agent: curl/7.54.1 > Accept: */* > Content-Type: application/xml > Content-Length: 52 > * upload completely sent off: 52 out of 52 bytes * STATE: DO => DO_DONE handle 0x6000578f0; line 1676 (connection #0) * STATE: DO_DONE => WAITPERFORM handle 0x6000578f0; line 1801 (connection #0) * STATE: WAITPERFORM => PERFORM handle 0x6000578f0; line 1811 (connection #0) * HTTP 1.1 or later with persistent connection, pipelining supported < HTTP/1.1 400 Bad Request < Date: Fri, 28 Sep 2018 12:20:36 GMT * Server Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips Phusion_Passenger/5.3.4 PHP/5.4.16 is not blacklisted < Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips Phusion_Passenger/5.3.4 PHP/5.4.16 < X-Runtime: 0.002491 < X-Request-Id: 090781ed-89df-43aa-9a61-9d1ba643ae71 < X-Powered-By: Phusion Passenger 5.3.4 < Strict-Transport-Security: max-age=63072000; includeSubdomains < X-Frame-Options: DENY < X-Content-Type-Options: nosniff < Content-Length: 0 < Status: 400 Bad Request * Marked for [closure]: Connection: close used < Connection: close < Content-Type: text/html; charset=utf-8 < * STATE: PERFORM => DONE handle 0x6000578f0; line 1980 (connection #0) * multi_done * Closing connection 0 * The cache now contains 0 members * TLSv1.2 (OUT), TLS alert, Client hello (1): * Expire cleared
RE: How can i add a comment to a issue via REST API? - Added by Brian Rose about 6 years ago
Updated request to (content type = json instead of xml)
curl -v -H "Content-Type: application/json" -X POST -d '{"issue": {"notes": "This is a note added via API"}}' -k -u username https://servername/issues/1
Now I am getting a Redmine 404 error.
Do I need to do something different with the URL in the POST command?
... snip ... < Content-Length: 459 < Status: 404 Not Found < Content-Type: text/html; charset=utf-8 < <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Redmine 404 error</title> <style> body {font-family: "Trebuchet MS", Georgia, "Times New Roman", serif; color: #303030; margin: 10px;} h1 {font-size:1.5em;} p {font-size:0.8em;} </style> </head> <body> <h1>Page not found</h1> <p>The page you were trying to access doesn't exist or has been removed.</p> <p><a href="javascript:history.back()">Back</a></p> </body> </html> * STATE: PERFORM => DONE handle 0x6000578f0; line 1980 (connection #0) * multi_done * Connection #0 to host 192.168.11.141 left intact * Expire cleared
RE: How can i add a comment to a issue via REST API? - Added by Brian Rose about 6 years ago
Curl GET appears to work. I get a long output with all the javascript and page contents.
curl -v GET -k -u username https://servername/issues/1/
RE: How can i add a comment to a issue via REST API? - Added by Mayama Takeshi about 6 years ago
To update an issue you should use method PUT instead of POST.
So you should have used:
curl -v -H "Content-Type: application/json" -X PUT -d '{"issue": {"notes": "This is a note added via API"}}' -u username https://servername/issues/1.json
And to get data from issue, add xml or json at the end of the URL:
curl -v -u username https://servername/issues/1.json
Otherwise, you'll get content for browser consumption instead of reply for an API call.