Item CRUD operations
Create an item
You create items using the CreateItem
of the IRestClient
interface.
The following example create a news item with title Sample
title:
You can set a custom field for built-in types using the SetValue
method.
The following code creates a news item with title Sample title
and sets the value of its MyCustomFieldName
field to My custom field value
:
The following code creates a press release item with title Sample title and sets the value of its MyCustomFieldName
field to My custom field value
:
NOTE: You can optionally provide a provider name, which will create the item in a specified provider.
Retrieve a single item
You retrieve items using the GetItem
of the IRestClient
interface.
You can retrieve a single item, using one of the following methods:
NOTE: These methods retrieve all of the fields of the item - both plain and related.
The IRestClient
interface has a method that allows more granular control over the retrieved item’s fields:
The GetItemArgs
argument holds properties that enable more granular control over the fetching of an item like in the following example:
NOTE: the Type property is not required, if the generic argument (in this case <NewsDto>
) is decorated with the MapppedSitefinityContentTypeAttribute
.
EXAMPLE: The following example retrieves a single news item by passing an id only:
restClient.GetItem(Guid.NewGuid().ToString());
Update an item
You update items using the UpdateItem
of the IRestClient
interface.
The following code updates the title of the news item with the specified ID to Sample title
:
You can set a custom field for built-in types using the SetValue method
.
The following code updates the title of the news item with the specified ID to Sample title
and the value of its MyCustomFieldName
field to My custom field value
:
The following code updates the title of the press release with the specified ID to Sample title
and the value of its MyCustomFieldName
field to My custom field value
:
Delete an item
You delete items using the DeleteItem
of the IRestClient
interface.
The following code deletes the news item with the specified ID:
The following code deletes the press release with the specified ID: