gpt4 book ai didi

node.js - Azure DevOps REST API - 创建工作项 - "A value is required"

转载 作者:行者123 更新时间:2023-12-03 12:13:17 28 4
gpt4 key购买 nike

我正在尝试使用 Azure DevOps REST API 创建一个工作项。我已经能够做其他事情,比如运行 WIQL 查询,但是当我尝试创建一个工作项时,我得到了这个神秘的三重错误:

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


这是完整的回应。
{
"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"
}
}

这是我正在尝试做的,遵循 documentation尽我所能。
注意:正如接受的答案所说,问题是一个错字, &紧接着 ?在网址中。由于这些示例在其他方面有效,为了任何想要复制和粘贴的人的利益,我已经修复了错字。
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 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())
});
我知道它正在读取我的请求,因为如果我将“op”更改为无效值,则会出现不同的错误。我错过了什么?

最佳答案

你的网址有错别字。我在 postman 中复制了该行为并通过修复 URL 来解决它。在 PowerShell 中调用“工作”的大多数其他答案都没有复制您的错字。
您指定了 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

关于node.js - Azure DevOps REST API - 创建工作项 - "A value is required",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64771092/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com