Updating the status of a work item using the PATCH method in the DevOps REST API is currently not working

Currently, I am utilizing the DevOps restapi to retrieve certain information. The POST method is functioning perfectly for me.
However, when attempting to update the status of my work item using the PATCH method, it does not seem to be working and no error message is being returned.

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;
};

When trying to utilize the Patch method, despite making necessary modifications, it continues to not display any errors or update my work item. Furthermore, I have verified that my access token is valid and has full permissions.

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

Answer №1

On my end, I have created a basic example using 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>

Please Note: Both contentType and dataType should be set as application/json-patch+json.


I used Fiddler to monitor this operation:

https://i.sstatic.net/oS3co.png

The successful update of the work item status can be observed.

UPDATE:

https://i.sstatic.net/8tQbS.png

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

file system mistakenly saves document in incorrect directory

For some reason when I try to use writefile, it is writing the file outside of the ./events folder. I am attempting to use fs like this: fs.writeFile("./level.json", JSON.stringify(storage), (err) => { console.log(err) xp ...

JavaScript code is being injected into JavaScript files like [ default/base.js ] with the help of Moblink 3G

I am currently using Moblink 3G internet and have noticed a script like this one: <script type = 'text/javascript' id ='1qa2ws' charset='utf-8' src='http://10.227.18.38:8080/www/default/base.js'></script&g ...

MVC error encountered when attempting to pass the parameter '&' results in failure

Encountered an error in MVC while passing '&' as a parameter, which fails to display the desired outcome. How can I address this issue with the following example? public IActionResult Create(int? idTrabalhador, [FromQuery]string GridState{} ...

Tampermonkey script encounters the error message "targetNode.dispatchEvent is not a recognized function"

I am attempting to press a button with Tampermonkey but keep encountering this error: userscript.html?id=2514f475-79e4-4e83-a523-6fef16dceeaa:10617 Uncaught TypeError: targetNode.dispatchEvent is not a function at triggerMouseEvent... Check out my scri ...

Watching the $scope variable using $watch will result in triggering even when ng-if directive is used, displaying

Encountering an unusual behavior in AngularJS that may appear to be a bug, but there could be a logical explanation. A certain value is being passed to a directive as an attribute. Within this directive, the parameter is being watched using $scope.$watch. ...

Tips for adding/removing items in arrays using Ember.js

Is it possible to modify an array within an Ember object using methods like push and pop while still keeping the UI bindings updated? While I can easily display the contents of an array in an Ember object using Handlebars, making changes directly to the ...

Creating multiple countdowns in AngularJS using ng-repeat is a handy feature to have

Currently, I have a small AngularJS application that is designed to search for users and display their upcoming meetings. The data is retrieved from the server in JSON format, with time displayed in UTC for easier calculation to local times. While I have s ...

A step-by-step guide on accessing and displaying local Storage JSON data in the index.html file of an Angular project, showcasing it on the

I am facing an issue with reading JSON data from localStorage in my Angular index.html file and displaying it when viewing the page source. Below is the code I have attempted: Please note that when checking the View page source, only plain HTML is being ...

Converting Callbacks to Promises in Node.js

I am facing a challenge with my node js application as I am attempting to promisify multiple callback functions without success. It has reached a point where I am unsure if it is even feasible. If you can assist me in promisifying the code provided below, ...

Encountered an issue while attempting to make a GET request using the fetch API

Currently, I am attempting to retrieve some data from the server using react.js and the fetch API. However, I keep encountering this error: SyntaxError: Unexpected token < in JSON at position 0. This is the code snippet I am using to fetch the data: ...

Timing of loading values into ng-if directive in AngularJS

While waiting for details to load, I have implemented a few ng-if directives on elements. This way, I can display a loading graphic to the user while the element value is undefined. Once the value is defined, the ng-if evaluates to false and hides itself. ...

the issue of button click events failing to trigger within deeply nested divs

Hey there, I'm currently working on creating three buttons with a shared text area. Each button is supposed to display a different message in the shared text area when clicked. I was able to achieve this functionality in a codepen which you can check ...

Resolving Null DateTime Property in MVC Model Through Ajax Post

While working on an ajax POST request with Model, everything seemed to be functioning well except for one datetime property. Upon inspecting the network tab in the browser, I noticed that all values were being passed in the request payload as expected. How ...

How can I parse URL paths in jQuery for ASP.NET?

I want to incorporate "~/" and have it resolved on the client side. Here is an example of what I am trying to do: <a href="~/page.aspx">website link</a> <img src="~/page.aspx" /> In my ASP.NET code, I have my base URLs set up like this ...

Server side pagination in AngularJS allows for dynamic loading of data

I am currently facing issues with slow application performance when retrieving large data from the database using Spring MVC and REST. I would like to implement server-side pagination in AngularJS to load only a subset of records. Could anyone provide gu ...

What could be causing my AngularJS errors to display like this in the Firefox console and Firebug?

Currently, I am working on an application using angularjs. However, I have encountered an issue with the 'smart-table' plugin not being added to my app modules array. What I'm interested in understanding is why Firefox and Firebug are displa ...

Show rows in the table based on the child nodes retrieved from the backend database

I am facing a minor issue with a table Below is the table <table> <thead> <th>Name</th> <th ng-repeat="value in drilldownReport.columns"> {{ drilldownReport.columnNames[value] }} ...

Navigating through nested JSON objects using JavaScript

Trying to access and display a nested JSON object within the console. This is the JSON data: { "currentUser": { "image": { "png": "./images/avatars/image-juliusomo.png", "webp": "./images/avatars/image-juliusomo.webp" }, "us ...

"Troubleshooting: show() Function Not Functioning Properly

Though this may seem like a straightforward piece of code, I've hit a snag somewhere along the way. It's just evading my grasp. #div { display:none; } JS: function show() { var className = 1; $("#div." + className).show("slow") ...

Updating the route in Express.js/Node.js to redirect form submission from `/page` to `/page/<input>`.Is this fine for you

How can I redirect a user from /page to /page/:nickname in Express after they enter a nickname and click submit? This is my code: // app.js app.get("/page", (request, response) => { response.render("page"); }); app.get("/page/:nickname", (reques ...