I can retrieve existing properties using REST (web/AllProperties) from site collections. As the title states, I would like to add custom property bag values to the property bag on a site collection, using REST. Is this possible?
2 Answers
AllProperties is a SPPropertyValues collection. It has a SetFieldValue method that takes the field name and an object as arguments. This method is not available from REST since the value argument can be anything. REST call arguments can only be primitive types or known EDM types. You can call this method using javascript and JSOM.
The answer NO. You can not update the spweb properties using REST. You can use JSOM as suggested in the first answer and below is the code that I found and tested here: How do you assign SPWeb property bag values in JSOM
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");
}