devops REST API: can not update work item status using PATCH method

杀马特。学长 韩版系。学妹 提交于 2021-01-05 14:38:04

问题


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.

https://docs.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;
};

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',

回答1:


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:



来源:https://stackoverflow.com/questions/59179390/devops-rest-api-can-not-update-work-item-status-using-patch-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!