Create list items

To create a list item you can use the Native API or the Fluent API.

To create a list item using the Native API, you must use the ListsManager class. For more information, see Creating a list item using Native API.

To create a list item using the Fluent API, you must use the list facade. For more information, see Creating a list item using Fluent API.

Creating a list item using Native API

When creating a list item through the Native API, you must perform the following:

  1. Get the parent list.

    First, you must get the parent list for the list item.

    For more information about querying lists, see For developers: Query lists.

    For more information about finding specific lists, see For developers: Find lists.

  2. Create new list item.

    After you get the parent list, you must create new list item.

  3. Set the parent.

    To set the parent list for the list item, you use the Parent property of the list item.

  4. Set the required properties.

    When creating a new list item, it is recommended to set at least the following properties:

    • Title

    • Content

    • UrlName

    • DateCreated

    You can also set any other properties in this step.

  5. Save the list item.

    Save all changes that you have made to the list item.

  6. Publish the list item.

    Finally, you publish the list item using the workflow manager.

The following code creates a list item with the specified IDParentTitle and Content through the Native API.

NOTE: In the code example below the ID argument is assigned to the master version of the list item.

First, you initialize the ListsManager. You get the parent list using the GetLists method.

For more information about querying lists, see For developers: Query lists.

For more information about finding specific lists, see For developers: Find lists.

You create the list item using the CreateListItem method of the ListsManager class. Note that you can create a list item with either predefined or auto-generated ID depending on which overload of the method you use. The ID argument is assigned to the ID of the master version of the item. Then, you set the parent list and the properties of the list item. It is recommended to set at least the following properties: TitleContentUrlName and DateCreated. Then, you save the changes. Finally, to publish the list item in live state, you call theMessageWorkflow method of the WorkflowManager class and pass the required parameters.

Creating a list item using Fluent API

When creating a list item through the Fluent API, you must perform the following:

  1. Check whether the parent list exists.

    First, you must check whether the specified parent list exists.

  2. Get the parent list.

    If it exists, you must get the parent list.

    For more information about querying lists, see For developers: Query lists.

    For more information about finding specific lists, see For developers: Find lists.

  3. Create new list item.

    After you get the parent list, you must create new list item.

  4. Set the required properties.

    When creating a new list item, it is recommended to set at least the following properties:

    • Title

    • Content

    • UrlName

    • DateCreated

    You can also set any other properties in this step.

  5. Save the list item.

    Save all changes that you have made to the list item.

  6. Publish the list item.

    Finally, you publish the list item using the workflow manager.

The following code creates a list item with the specified ParentTitle and Content through the Fluent API.

First, you check whether the specified parent list exists using the plural facade of the list. If it exists, you get the list using the singular facade.

Then, you create the list item using the CreateListItem method of the facade. Then, you set the properties of the list item by calling the Domethod of the facade. It is recommended to set at least the following properties: TitleContentUrlName and DateCreated. Then, you save the changes. To publish the list item in live state, you call the MessageWorkflow method of the WorkflowManager class and pass the required parameters. Finally, you return the Id of the list item.

Was this article helpful?

Next article

Query list items