请求中需要一个值,但未提供
请求中需要一个值,但未提供
请求中需要一个值,但未提供
以下是完整的响应。
{
"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"
}
}
以下是我尝试做的事情,尽可能地遵循文档。
注意:正如被接受的答案所指出的那样,问题是一个拼写错误,在URL中紧跟着?
的&
。由于这些示例在其他方面均有效,为了使任何想要复制和粘贴的人受益,我已经纠正了这个错误。
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())
});
使用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"}]'
在浏览器中发起相同的请求
登录DevOps,确保您的浏览器指向 https://dev.azure.com/YourProject/YourOrganization
。然后打开Dev工具(F5),并将此代码粘贴到JS控制台中。
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())
});
我知道它正在读取我的请求,因为如果我将“op”更改为无效值,我会收到不同的错误。我错过了什么吗?