Unable to update the list item in the list using REST API in Sharepoint 2016

I’ve been working with this problem from one month but unable to solve this. I’m able to retrieve the list using GET method rest api. But I’m not able to update the items in the list using POST method in rest api. For clear picture, our idea is to get number of clicks count clicked on a link and it should update the count automatically in the list for that link name. So, previous developers had created two lists already named ‘a’ and ‘b’.

  • ‘a’ list contains the pdfs, docx.
  • ‘b’ list contains the pdf links of ‘a’ list, name and other columns.
  • I have created an other list ‘c’ where it contains the name of ‘b’ list and count.

So, I am trying to update the count column in ‘c’ list. But am unable to update the count from the code itself. The code below is one of the methods I tried. Please help me resolve this problem where am clueless even after trying many methods from sharepoint blogs and tutors from last month.

function getItems() {  
    var resturl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('c')/items"; 
        $.ajax({  
            url: resturl,  
            type: "GET",  
            headers: {  
                "accept": "application/json;odata=verbose",  
            },  
            success: function(data) {  
                //console.log(data.d.results);  
                var items = data.d.results; 
                for (var i = 0; i < items.length; i++) {                
                console.log("From C List -> Name: " + items[i].Title + ", Count: " + items[i].Count);                 
                }  
            },  
            error: function(error) {  
            alert(JSON.stringify(error));  
            }  
        });  
 }  

var prevcount = 0;
function updateItems() {  
   
       var resturl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('c')/items";
       prevcount = prevcount + 1;
   
       $.ajax({
           url: resturl,
           method: "POST",
           headers: {
               "accept": "application/json;odata=verbose",
               "X-RequestDigest": $("#__REQUESTDIGEST").val(),
               "content-Type": "application/json;odata=verbose",
               "IF-MATCH": "*",
               "X-HTTPS-Method": "MERGE"
           },
           data: "{__metadata:{'type':'SP.Data.cListItem'}, Count: prevcount}",
      
           async: false, success: function (data) {              
           console.log(data.d.results);   
           },
     
           error: function (data) {   
           console.log(data.responseJSON.error);   
           }   
       });
   }

15 thoughts on “Unable to update the list item in the list using REST API in Sharepoint 2016”

  1. 737884 282812I found your weblog website on google and check a couple of of your early posts. Proceed to preserve up the extremely great operate. I just extra up your RSS feed to my MSN News Reader. Seeking for ahead to reading extra from you later on! 635198

    Reply