1

followed all the documentation as outlined here

https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/comments/add?view=azure-devops-rest-6.0

but not able to add comments to the work item don't get any useful info in the response, here is my CURL request i am using PAT for authentication.

curl -H "Authorization: Basic {Base64_PAT}" -H "Content-Type: application/x-www-form-urlencoded" -X POST -d '[{"text": "Testing REST API"}]' https://dev.azure.com/{organization}/{project}/_apis/wit/workItems/{workItemId}/comments?api-version=6.0-preview.3

i've also tried application/json content type in the header but no use.

this however gives me response of the existing comment but not adding this comment in the body to work item.

Any help is hugely appreciated don't have a clue as what might be happening as i don't get any informative response i get a html response back which has a link and when clicked on it takes me to the response which shows existing comment response body but not adding comment in the POST body to the work item

riQQ
  • 9,878
  • 7
  • 49
  • 66
KingKongCoder
  • 600
  • 4
  • 15
  • NOTE: i am able to view existing comments "GET" request but POST is not doing anything and not honoring my POST body text – KingKongCoder Dec 15 '20 at 04:20
  • 1
    OK, you're following the documentation to a tee. I suspect it's going to be `application/json` based on the input, have you tried to remove the content-type? Postman shows the same as Curl? I need to think about this, why would the GET work but not the POSTs, do any POSTs work? – Jeremy Thompson Dec 15 '20 at 04:22
  • @JeremyThompson look at my comment on the below answer, that did work. – KingKongCoder Dec 15 '20 at 14:23

1 Answers1

3

I`ve tried your example and got the answer:

curl: (3) [globbing] unmatched close brace/bracket in column 17

Try to remove space between

"text":here"Testing

Additionally, there are some issues:

  1. Do not use the square brackets in the requests: Cannot add comments to a work item with API version 5.1-preview3
  2. Escape quotation marks: CouchDB cURL Windows Command Line Invalid JSON

The following works on my windows:

curl -u :<pat> -H "Content-Type: application/json" -X POST -d {"""text""":"""Testing REST API"""} https://dev.azure.com/<org>/<project>/_apis/wit/workItems/<wiid>/comments?api-version=6.0-preview.3
Shamrai Aleksander
  • 13,096
  • 3
  • 24
  • 31
  • 1
    oh yeah that worked. Here's what i changed: 1. Removed outer square brackets for POST JSON request body 2. used `-u :"Raw_PAT"` instead of `-H "Authorization: Basic Base64_PAT"` – KingKongCoder Dec 15 '20 at 14:20