Reputation: 353
I'm using the Azure DevOps API to create a new work item. However I get an error
404 page not found
Documentation: Work Items - Create
Things I've tried
Get calls work (e.g. get list of teams, projects, work item types)
Why the 404 error for post?
Below the powershell script
$url= "https://dev.azure.com/my-org/my-project/_apis/wit/workitems/$($witType)?api-version=6.0"
$JSON = @'
[
{
"op": "add",
"path": "/fields/System.Title",
"from": null,
"value": "Sample task"
} ,
{
"op": "add",
"path": "/fields/System.IterationId",
"from": null,
"value": "e5c8d590-5283-4642-8262-716d083bc045"
},
{
"op": "add",
"path": "/fields/System.AreaId",
"from": null,
"value": "138233"
},
{
"op": "add",
"path": "/fields/System.State",
"from": null,
"value": "To Do"
}
]
'@
Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Post -Body $JSON -ContentType application/json-patch+json
Upvotes: 2
Views: 1778
Reputation: 35194
The issue should be related to the Rest API URL.
When you run the Rest API in Postman, you need to add $
before the work item type.
For example:
POST https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/$task?api-version=6.0
When you use the PowerShell to run the Rest API, you need to modify the URL.
https://dev.azure.com/my-org/my-project/_apis/wit/workitems/`$$($witType)?api-version=6.0
Here is an example:
$url= "https://dev.azure.com/my-org/my-project/_apis/wit/workitems/`$$($witType)?api-version=6.0"
$JSON = @'
[
{
"op": "add",
"path": "/fields/System.Title",
"from": null,
"value": "Sample task"
} ,
{
"op": "add",
"path": "/fields/System.IterationId",
"from": null,
"value": "e5c8d590-5283-4642-8262-716d083bc045"
},
{
"op": "add",
"path": "/fields/System.AreaId",
"from": null,
"value": "138233"
},
{
"op": "add",
"path": "/fields/System.State",
"from": null,
"value": "To Do"
}
]
'@
Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Post -Body $JSON -ContentType application/json-patch+json
Refer to this ticket: Azure Devops bulk create Tasks for every Product Backlog Item
Upvotes: 5