Work with content

Overview

The samples in this section use Sitefinity CMS News items. The samples focus on the data function of the sitefinity object that returns a data object. The data object is the mechanism that enables Sitefinity JS SDK to work with the OData services.

In the following samples, the dataOptions object specifies which content item to query.
It has the following properties:

  • urlName – which content item to query
  • providerName – which data provider is the content item from
  • cultureName – which language version of the content item you want to query

As a result, you get the data object and you can call its various functions, such as:

  • get
  • getSingle
  • create
  • update
  • destroy
  • upload

These functions accept an object, which has the following functions and properties: 

  • successCb and failureCb 
    The successCb, failureCb are callback functions that are executed for the current request, if the request is successful or if it has failed, respectively. 
  • query
    The query is a string that is used to filter data

    EXAMPLE: (endswith(Record, 'Title') or (age ne '15') or (Content eq 'test') 

  • action
    The action is an object that is used for various workflow operations.
    For example, in this object you can specify that you want to publish an item on a specific date and unpublish it on another date:
    EXAMPLE:
  • fallbackProperties
    The fallbackProperties is a string array that specifies which properties to fallback to, if an item is not translated to the currently requested culture.
    For example, if you include the Title in this property, the service returns the title of the non-translated item.

NOTE: There is a limitation in the OData web services that limits the maximum items in a query to 50. To change this limit in Sitefinity CMS backend, navigate to Administration » Settings » Advanced » WebServices » Routes » Frontend » Services » <your service> » <content type>. Change the value of Default page size field.

Query a collection of News items

The following sample demonstrates how to query multiple news items, by using the get function of the data object:

Query a single News item

The following sample demonstrates how to query a single news item, by using the getSingle function of the data object:

Create a News item

The following sample demonstrates how to create a News item, by using the create function of the data object:

Update a News item

The following sample demonstrates how to update a News item, by using the update function of the data object:

Delete a News item

The following sample demonstrates how to delete a News item, by using the destroy function of the data object:

Upload media

A media item upload request requires you to send headers with the request.
This sample demonstrates how to upload an image in JPEG format. Therefore, you must send the following headers with the request:

The following sample sends three requests in a batch request to Sitefinity CMS:

  • The first is a POST request to upload the binary data
  • The second is a PATCH request to update the metadata of the image
  • The third is a POST request to specify the album where the image must be uploaded. All three requests are handled by the data object's upload function.

NOTE: This sample assumes that there is an <input type="file" name="photo" id="photo"> element present in your application.

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

Web Security for Sitefinity Administrators

The free standalone Web Security lesson teaches administrators how to protect your websites and Sitefinity instance from external threats. Learn to 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?

Next article

Create queries