Update

Updating a content could be achieved by sending an http PATCH or PUT request. You can call it by identifying the content that should be updated (this will be the path where you'll send the request), and adding an object with the fields and values that you want to update (this object will be sent in the request body). Both PATCH and PUT requests will return the updated content object in JSON.

Modifying a field of an entity

First let's change the index of a workspace to 142:

Copy
url: "/OData.svc/Root/Content('IT')",
type: 'PATCH',
data: "models=[" + JSON.stringify({
  'Index': 142
}) + "]",

Modifying multiple fields at once

The following example shows you how you can change a folder's name and index fields at once:

Copy
url: "/OData.svc/Root/Content('IT')",
type: 'PATCH',
data: "models=[" + JSON.stringify({
  'Name': 'NewName',
  'Index': 142
}) + "]",

Update the value of a date field

In the next example you can see how you can update the start date of an event:

Copy
url: "/OData.svc/Root/Content/IT/Calendar('Release')",
type: 'PATCH',
data: "models=[" + JSON.stringify({
  'StartDate': '2020-03-04 09:30:00',
}) + "]",

Update a choice field

Updating choice fields is a tricky one. Let's see how you can change an event's EventType field to choose multiple options:

Copy
url: "/OData.svc/Root/Content/IT/Calendar('Release')",
type: 'PATCH',
data: "models=[" + JSON.stringify({
  'EventType': ['Demo', 'Meeting'],
}) + "]",

Update the value of a reference field

The following example demonstrates how can you modify a reference field of an entity. Let's change the Manager of a workspace:

Copy
url: "/OData.svc/Root/Content('IT')",
type: 'PATCH',
data: "models=[" + JSON.stringify({
  'Manager': 12345,
}) + "]",

You may use either content id or path in case of reference fields. In case of a multiple reference field you should provide an array of ids or paths, as you can see below:

Copy
url: "/OData.svc/Root/Content('IT')",
type: 'PATCH',
data: "models=[" + JSON.stringify({
  'Customers': ['/Root/Customer1', '/Root/Customer2'],
}) + "]",

Setting (resetting) all fields of an entity

Using the PUT http method enables you to set multiple fields of an entity and clear (reset to the default) the rest. Let's set the manager of a workspace to businesscat and clear all other fields.

Copy
url:"/OData.svc/Content('IT')",
type: 'PUT',
data: "models=[" + JSON.stringify({
  'Manager': '/Root/IMS/Public/businesscat'
}) + "]"