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.
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.
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");
}
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