7
votes

Is it possible to add a comment to a work item in Visual Studio Team Services using the REST API?

I've checked the work item doc and fields doc but I couldn't see anything in the fields JSON which looked like it's the comments field.

The scenario I'm trying to achieve is CCing an email to Zapier and having the body of the email added as a comment on the work item in VSO.

2
Not exactly sure what you're looking for, but JSON doesn't support comments. You'd have to add that as a key in the object.Christopher Marshall
There is a fields endpoint which lists all the work item fields in your VSO account. I checked the JSON response and there didn't seem to be an entry for the work item comments field.Kevin Kuszyk

2 Answers

13
votes

Following @tzachs tip, this is the API call to add a comment (or history entry in VSO jargon):

PATCH https://{account}.visualstudio.com/defaultcollection/_apis/wit/workitems/{id}?api-version=1.0-preview.2

JSON payload:

[  
  {
    "op": "add",
    "path": "/fields/System.History",
    "value": "Comment from VSO REST API"
  }
]

Note: If you want to add multiple comments, you need to issue separate patch requests, or else the last one "wins".