2
votes

I'm working on creating a VSTS Workitem(Task) using REST API. I'm referencing the below rest api POST https://{accountName}.visualstudio.com/{project}/_apis/wit/workitems/${type}?api-version=5.0-preview.3

On the above API, how can I pass the input to ${type}. Say if I want to create a Task, how can I pass the value. I'm using the below body as mentioned in the document.

[
  {
    "op": "add",
    "path": "/fields/System.Title",
    "from": null,
    "value": "Sample task"
  }
]

When I try this, I'm getting 404 error. Looking for the help to resolve this issue.

Thanks, Siva

2

2 Answers

3
votes

You need to keep $ symbol in the request.

Such as to add a Task work item, you can use below REST API:

POST https://account.visualstudio.com/project/_apis/wit/workitems/$Task?api-version=5.0-preview.3

application/json-patch+json:

[
  {
    "op": "add",
    "path": "/fields/System.Title",
    "from": null,
    "value": "Sample task"
  }
]
1
votes

You should specify the {type} in the URL, as well as other tokens in the sample: {accountName} and {project}:

  • When you log in to your VSTS account, the {accountName} is the value in the URL before .visualstudio.com
  • The {project} is the name of your team project in VSTS. Again, if you browse it in the browser, the {project} is the part of the URL between visualstudio.com/ and the subsequent /
  • The {type} should be task if you want to create tasks

Most info is here in the official docs.