I'm trying to create a work item using the Azure DevOps REST API. I've been able to do other things, like running a WIQL query, but when I try to create a work item I get this mysterious triple-error:
A value is required but was not present in the request
A value is required but was not present in the request
A value is required but was not present in the request
Here's the full response.
{
"count": 1,
"value": {
"Message": "A value is required but was not present in the request.\r\nA value is required but was not present in the request.\r\nA value is required but was not present in the request.\r\n"
}
}
Here's what I'm trying to do, following the documentation as best I can.
Note: as the accepted answer called out, the problem was a typo, an &
immediately following the ?
in the URL. Since these examples otherwise work, for the benefit of anyone who wants to copy and paste, I've fixed the typo.
const fetch = require('node-fetch');
const username = '[username]';
const password = '[personal access token]'
const organization = '[organization]';
const project = '[project]'
const authorizationHeader = `Basic ${Buffer.from(
`${username}:${password}`
).toString('base64')}`
const body = [
{
"op":"add",
"path":"/fields/System.Title",
"value":"TestCreateWI"
}
];
fetch(`https://dev.azure.com/${organization}/${project}/_apis/wit/workitems/$Task?api-version=6.0`, {
method: 'POST',
headers: {
Authorization: authorizationHeader,
'Content-Type': 'application/json-patch+json',
},
body: JSON.stringify(body),
}).then(async (response) => {
console.log(await response.text())
});
curl 'https://dev.azure.com/MyOrganization/MyProject/_apis/wit/workitems/$Task?api-version=6.0' \
-H 'Authorization: Basic [redacted]' \
-H 'Content-Type: application/json-patch+json' \
--data-binary '[{"op":"add","path":"/fields/System.Title","value":"Test"}]'
Log in to DevOps so that your browser is pointing to https://dev.azure.com/YourProject/YourOrganization
. Then open Dev Tools (F5) and paste this code into the JS console.
const body = [
{
"op":"add",
"path":"/fields/System.Title",
"value":"TestCreateWI"
}
];
fetch(`${document.URL}/_apis/wit/workitems/$Task?api-version=6.0`, {
method: 'POST',
headers: {
'Content-Type': 'application/json-patch+json',
},
body: JSON.stringify(body),
}).then(async (response) => {
console.log(await response.text())
});
I know that it's reading my request, because if I change "op" to an invalid value, I get a different error. What am I missing?
You have a typo on your URL. I duplicated the behavior in postman and resolved it by fixing the URL. Most of the other answers with the calls "working" in PowerShell didn't copy your typo.
You specified https://dev.azure.com/${organization}/${project}/_apis/wit/workitems/$Task?&api-version=6.0
It shouldn't have the extra & before the api-version https://dev.azure.com/${organization}/${project}/_apis/wit/workitems/$Task?api-version=6.0
I do not use curl on my tasks, but the following works on my org:
curl -u "":personal_access_token -d "[{\"op\":\"add\",\"path\":\"/fields/System.Title\",\"value\":\"Sample task\"}]" -H "Content-Type: application/json-patch+json" -X POST https://dev.azure.com/<org>/<project>/_apis/wit/workitems/${Task}?api-version=6.0
I`ve tested curl for windows 7.73.0.
Docs to create a personal access token: Use personal access tokens. Additionally, use the work item type in url like ${work item type name}
If I post data with -d '[{"op":"add","path":"/fields/System.Title","value":"Sample task"}]'
the service returns the following answer:
{"$id":"1","innerException":null,"message":"You must pass a valid patch document in the body of the request.","typeName":"Microsoft.VisualStudio.Services.Common.VssPropertyValidationException, Microsoft.VisualStudio.Services.Common","typeKey":"VssPropertyValidationException","errorCode":0,"eventId":3000}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With