Create

Creating a content is an http POST request under the hood. You can call it by defining the parent content (this will be the path where the actual request will be sent), the required type and a content object with the fields and values that you want to save when the new content is created (these things have to be added to the request body). These POST requests will return the newly created content object in JSON format.

Without defining the content type of the new entity, the first allowed content type of the parent entity will be used. The default content type can be overridden in the posted JSON object with the __ContentType property, as you can see in the example below.

In the following example you can see how you can create a new Folder and set its name:

Copy
POST https://example.com/OData.svc/Root/Content('Cars')

models=[{"Name":"New cars","__ContentType":"Folder"}]

Create a workspace

With the following example you will create a new workspace. The request will return the workspace content object:

Copy
POST https://example.com/OData.svc/Root('Content')

models=[{"Name":"My workspace","__ContentType":"Workspace"}] 

Create a document library

The following example request creates a new document library:

Copy
POST https://example.com/OData.svc/Root('Content')

models=[{"Name":"My Documents","__ContentType":"DocumentLibrary"}]

Create a user

Creating a user works the same way as creating other type of content in the repository. You can see in the following example that it differs only in the __ContentType property:

Copy
POST https://example.com/OData.svc/Root/IMS('Public')

models=[{
  "Name":"jsmith",
  "__ContentType":"User",
  "LoginName":"jsmith",
  "Email":"jsmith@example.com",
  "Password":"I8rRp2c9P0HJZENZcvlz",
  "FullName":"John Smith",
  "Enabled":true
}]

Creating a content by template

sensenet provides you the possibility to create a content by a content template. In the following case the request will create a workspace with an event list under it with the name Calendar and fill its Index field with the value 2. Other field values will be filled by the default values defined on CalendarTemplate template. See the __ContentTemplate parameter:

Copy
POST https://example.com/OData.svc/Root('Content')

models=[{
  "Name":"My Calendar",
  "__ContentType":"EventList",
  "__ContentTemplate":"/Root/ContentTemplates/DemoWorkspace/Demo_Workspace/Calendar",
  "DisplayName":"Calendar",
  "Index":2
}]