0

I need to update the Property bag values in sharepoint Using REST API. I am able to get the Values but not able to update.

Need help on this.

3
  • Are you trying to update SharePoint "site" property bag values? Which property you want to update? Are you trying this for communication site or team site? Commented Apr 19, 2023 at 13:47
  • Yes, We have custom Property bag values, We need to update one propertybag value using REST API Commented Apr 19, 2023 at 13:57
  • check my answer at: sharepoint.stackexchange.com/questions/289984/…. Let me know if it works for you. Commented Apr 19, 2023 at 13:59

2 Answers 2

0

Property bags are read-only when using the REST API. If you want to update a property bag you will need to use the Client Object Model (CSOM) instead.

If you do a search for "sharepoint rest api property bags" you will see similar answers from StackOverflow and other forum sites.

Here is a JavaScript sample:

function setWebProperty() {
    var ctx = new SP.ClientContext.get_current();
    var web = ctx.get_web();
    this.properties = web.get_allProperties();
    this.properties.set_item("myCustomProperty", "myCustomValue");
    ctx.load(web);
    web.update();
    ctx.executeQueryAsync(Function.createDelegate(this, getWebProperty), Function.createDelegate(this, failedGettingProperty));
}

function getWebProperty() {
    alert(this.properties.get_item("myCustomProperty"));
}

function failedGettingProperty() {
    alert("failed");
}
1

Try using SharePoint REST API call like this:

$.ajax({
  url: "http://<site url>/_api/web",
  type: "POST",
  data: "{ '__metadata': { 'type': 'SP.Web' }, 'Description': 'My new description'}",
  headers: { 
    "X-RequestDigest": <form digest value>,
    "accept": "application/json;odata=verbose",
    "content-type": "application/json;odata=verbose",
    "content-length": <length of body data>,
    "X-HTTP-Method": "MERGE",
    "If-Match": "*"
  },
  success: successHandler,
  error: errorHandler
});

In this example I have updated description property of SharePoint online site.

Microsoft documentation: Webs REST API reference

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.