0

I am facing issues with updating a simple list item using SharePoint REST API. I have gone through all the blogs to get a solution but the result is same. When ever i execute the update list item function using REST API it returns me the body of the particular list item row i am trying to update but it is not updating the listem. Could someone please help me out. Thanks in advance

    function (listTitle, TabId, success, failure) {
     var itemType = GetItemTypeForListName(listTitle);
     var query = appweburl + "_api/SP.AppContextSite(@target)/web/lists/getbytitle('" + listTitle + "')/items(5)?&@target='" + hostweburl + "'";

      var meta_data = {"__metadata": { "type": itemType }};
                    meta_data['DeletedStatus'] = 'Inactive'
      var executor = new SP.RequestExecutor(appweburl);

      executor.executeAsync({
                    url: query,
                    type: "POST",
                    contentType: "application/json;odata=verbose",
                    data: JSON.stringify(meta_data),
                    //body: meta_data,
                    headers: {
                        "Accept": "application/json;odata=verbose",
                        "X-RequestDigest": $("#__REQUESTDIGEST").val(),
                        "X-HTTP-Method": "MERGE",
                        "IF-MATCH": "*"
                        //"content-length": meta_data.length,

                    },
                    success: function (data) {
                        //alert("success: " + JSON.stringify(data));
                        //deferred.resolve(JSON.parse(data.body));
                        console.log(JSON.stringify(data));
                        alert(JSON.stringify(data));
                    },
                    error: function (err) {
                        //alert("error: " + JSON.stringify(err));
                        console.log(JSON.stringify(err));
                    }
                });

}

function GetItemTypeForListName(name) {
                return "SP.Data." + name.charAt(0).toUpperCase() + name.split(" ").join("").slice(1) + "ListItem";
            }
3
  • can you write the exception message? Commented Jan 21, 2016 at 9:30
  • can you try method: "POST" instead of type? Commented Feb 4, 2016 at 9:10
  • did you solve the problem?? I have similar issue. Commented May 27, 2016 at 11:28

1 Answer 1

1

Otherwise just replace below code in your function

executor.executeAsync({
url : query,
method : "POST",
body: JSON.stringify(meta_data),
headers: {
    "Accept": "application/json;odata=verbose",
    "Content-Type" : "application/json;odata=verbose",
    "X-HTTP-Method": "MERGE",
    "IF-MATCH": "*"
},
success: function (data) {
    console.log(JSON.stringify(data));
},
error: function (err) {
    console.log(JSON.stringify(err));
} });

It will also insert the digest for you, so you do not need add

"X-RequestDigest": $("#__REQUESTDIGEST").val(),

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.