gpt4 book ai didi

javascript - 开发运营 REST API : can not update work item status using PATCH method

转载 作者:行者123 更新时间:2023-12-02 22:22:43 25 4
gpt4 key购买 nike

我正在使用 DevOps Restapi 来获取一些信息。POST 方法对我来说效果很好。
我想更新我的工作项目的状态。为此,我需要使用 PATCH 方法。这不起作用,并且没有给出任何类型的错误。

https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/work%20items/update?view=azure-devops-rest-5.1

function postApiData(ApiUrl, responseBody) {
var res = '';
try {

$.ajax({
type: 'POST',
async: false,
url: ApiUrl,
contentType: 'application/json',
data: JSON.stringify(responseBody),
cache: false,
dataType: 'json',
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa("" + ":" + _token));
},
}).done(function (data) {
res = data;
}).fail(function (e) {

});
} catch (error) {
var x = error;
throw x;
}
return res;
};

对于 Patch 方法,我正在修改一些内容。但它没有给出任何不更新我的工作项目的错误。我还检查了我的 token 访问权限。我拥有完全访问权限。

type: 'PATCH',
contentType: 'application/json-patch+json',

最佳答案

我在 Ajax 中使用 PATCH 编写了一个简单的示例:

<script type="text/javascript">
$(document).ready(function () {
$("#SelectWIT").on("click", function () {
var json= [{
"op": "add",
"path": "/fields/System.State",
"value": "Closed"
}];
$.ajax({
type: 'PATCH',
url: 'https://dev.azure.com/{org name}/_apis/wit/workitems/{WIT id}?api-version=5.1',
contentType: 'application/json-patch+json',
data: JSON.stringify(json),
cache: false,
dataType: 'application/json-patch+json',
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa("" + ":" + "{PAT token}"));
},
}).error(function (e) {
var s = "error error error";
});
})
});
</script>

注意:不仅contentType需要设置为application/json-patch+json,而且dataType<也需要设置为application/json-patch+json/.

<小时/>

我使用Fiddler来捕获这个操作:

enter image description here

您可以看到工作项状态已成功更新。

更新:

enter image description here

关于javascript - 开发运营 REST API : can not update work item status using PATCH method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59179390/

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