Dynamic content and custom fields

Overview

For overall information about all the modules and their properties you can use the sfmeta request in the following way:

{baseurl}/api/default/sfmeta

Sample request

GET http://mysite.com/api/default/sfmeta

Working with dynamic contents or custom fields is similar to all other modules and their default properties. The following examples use the dynamic content module Press releases with various custom fields:

Create a dynamic content item with custom fields

To create a dynamic item, you must execute a POST request to the following endpoint:

{baseurl}/api/default/{entity}

Where {entity} is the name of the dynamic module that you are working with.

You must specify all the properties of the item in JSON format inside the request body.

Sample request

POST http://mysite.com/api/default/pressreleases

Sample response

Get a dynamic content item with custom fields

To get a single item, you must execute a GET request to the following endpoint:

{baseurl}/api/default/{entity}({itemId})

Where:

  • {entity} is the name of the dynamic module that you are working with
  • {itemId} is the ID of the item

Sample request

GET http://mysite.com/api/default/pressreleases(2fba96fb-c69b-4cab-8741-12d78da207cd)

Sample response

Update a dynamic content item with custom fields

To update a dynamic item, you must execute a PATCH request with the properties that you want to modify to the following endpoint:

{baseurl}/api/default/{entity}({itemId})

Where:

  • {entity} is the name of the dynamic module that you are working with
  • {itemId} is the ID of the dynamic content item

You must specify all properties that you want to modify in JSON format inside the request body.

Sample request

PATCH http://mysite.com/api/default/pressreleases(f22ba36f-6987-4729-8509-200caf92beb1)

Sample response

No response body

Delete a dynamic content item with custom fields

To delete a dynamic item, execute a DELETE request to the following endpoint:

{baseurl}/api/default/{entity}({itemId})

Where:

  • {entity} is the name of the dynamic module that you are working with
  • {itemId} is the ID of the dynamic content item

Sample request

DELETE http://mysite.com/api/default/pressreleases(f22ba36f-6987-4729-8509-200caf92beb1)

Sample response

No response body

Work with the Choice field

When working with a choice field through the OData web services, instead of the selected textual value of the field, such as Option1 or Option2, the field value is returned as a number – for example, 2 or 4.

The returned value indicates which choice option has been selected. It is returned as two to the power of the position of that choice in the collection of all choices.

EXAMPLE: If you have configured your choice field with 4 options - Option 1, Option 2, Option 3, and Option 4, the value that will be returned by the service is:
  • If the selected option is Option 1, the service returns 1 (2 to the power of 0)
  • If the selected option is Option 2, the service returns 2 (2 to the power of 1)
  • If the selected option is Option 3, the service returns 4 (2 to the power of 2)
  • If the selected option is Option 4, the service returns 8 (2 to the power of 3)
  • If it is a multi-select choice field and the selected options are Option 1, Option 2 and Option 3, the service returns 7 (the sum of the values for Option 1, Option 2 and Option 3)

When you filter a collection by the value of the choice field, have in mind that the CLR type to which a choice field is being resolved in the OData implementation is Enum. To filter by the value of a choice field, you must first use a cast() operation in the query string. This way, you cast the field's type to Edm.String.

To filter a collection by the value of a selected choice, execute a GET request to the following endpoint:

{baseurl}/api/default/{entity}?$filter=cast({relatedDataFieldName}, 'Edm.String') eq {filterValue}

Where:

  • {entity} is the entity of the module you are working with
  • {relatedDataFieldName} is the name of the related choice field
  • {filterValue} is the value that you want to filter the collection by

Sample request (filter by value)

GET http://mysite.comapi/default/pressreleases?$filter=cast(SampleRadioButtonsChoices, 'Edm.String') eq '1'&$count=true

Sample response

Sample request (filter by inequality)

To filter a collection of dynamic items by the value of a choice field not equal to a specific value, use the following GET request:

GET http://mysite.comapi/default/pressreleases?$filter=cast(SampleRadioButtonsChoices, 'Edm.String') ne '1'&$count=true

Sample response

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?