Pat*_*ney 7 rest node.js azure-devops
我正在尝试使用 Azure DevOps REST API 创建一个工作项。我已经能够做其他事情,比如运行 WIQL 查询,但是当我尝试创建一个工作项时,我得到了这个神秘的三重错误:
值是必需的,但在请求中不存在
值是必需的,但在请求中不存在
值是必需的,但在请求中不存在
这是完整的回应。
{
"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"
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我正在尝试做的事情,尽我所能遵循文档。
注意:正如接受的答案所说,问题是一个错字,&紧跟?在 URL 之后。由于这些示例在其他方面有效,为了任何想要复制和粘贴的人的利益,我已经修复了错字。
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())
});
Run Code Online (Sandbox Code Playgroud)
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"}]'
Run Code Online (Sandbox Code Playgroud)
登录到 DevOps,使您的浏览器指向https://dev.azure.com/YourProject/YourOrganization. 然后打开 Dev Tools (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())
});
Run Code Online (Sandbox Code Playgroud)
我知道它正在读取我的请求,因为如果我将“op”更改为无效值,则会收到不同的错误。我错过了什么?
Mat*_*att 10
您的网址有拼写错误。我在邮递员中复制了该行为,并通过修复 URL 解决了该问题。大多数其他在 PowerShell 中调用“working”的答案都没有复制您的拼写错误。
您指定的https://dev.azure.com/${organization}/${project}/_apis/wit/workitems/$Task?&api-version=6.0
api 版本之前不应该有额外的 &https://dev.azure.com/${organization}/${project}/_apis/wit/workitems/$Task?api-version=6.0
| 归档时间: |
|
| 查看次数: |
858 次 |
| 最近记录: |