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.
Minimal test case in NodeJS
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())
});
Same request using CURL
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"}]'
Same request from a browser
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?


