devops REST API:无法使用PATCH方法更新工作项状态 [英] devops REST API: can not update work item status using PATCH method
问题描述
我正在使用DevOps restapi来获取一些信息.POST方法对我来说很好用.
我想更新我的工作项目的状态.为此,我需要使用PATCH方法.这不起作用,也没有给出任何类型的错误.
您可以看到工作项状态已成功更新.
更新:
I am using DevOps restapi to get some information.
The POST method is working fine for me.
I want to update the status of my work item. For that I need to use the PATCH method. Which is not working, and not giving any kind of error.
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;
};
For Patch method, I am modifying a few things. but it is not giving any error not updating my work item. I have also checked my token access. I have full access.
type: 'PATCH',
contentType: 'application/json-patch+json',
I wrote a simple sample on my side with PATCH
in Ajax:
<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>
Note: Not only contentType
need to set as application/json-patch+json
, but also same in dataType
.
I use Fiddler to catch this operation:
You can see the work item status updated successfully.
UPDATE:
这篇关于devops REST API:无法使用PATCH方法更新工作项状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!