HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunitySubmit a ticketLog In
GitHubNuGetDev CommunitySubmit a ticket


A feed represents a record of the activities occurring within the application. As an activity is added to the system, the platform generates feed items for users subscribed to the entity upon which the activity occurred.

In the Optimizely Community API, feed items can be managed through a service implementing the interface `IFeedService`. This service provides the ability to retrieve feed items generated by the Activity Streams system.

## Manage feeds

In the Optimizely Community API, feed items are retrieved through a service implementing the interface `IFeedService`.

### Access an IFeedService

When the Activity Streams feature is installed to an Optimizely Content Management System (CMS) site, with the feature's site integration package, you can get an instance of the Feed service from the inversion of control (IoC) container.

Example:



When the feature is installed to a non-Optimizely CMS site, you can get an instance of a service from the default factory class provided within the package.

Example:



## Retrieve feed items

To retrieve a collection of feed items, regardless of the type of payload extending the activity, use the `Get(Criteria<FeedItemFilter>)` method. This method accepts an instance of `Criteria<FeedItemFilter>`, which contains the specifications necessary to retrieve the desired feed items.

The Filter property of the `Criteria<FeedItemFilter>` class accepts an instance of the `FeedItemFilter` class. This class contains the specifications that allow you to refine the result set of `FeedItems` that you want to retrieve.

  • `Actor` – Assigning a value (`Reference`) to this property refines the result set to FeedItems representing activities initiated by the identified user.

  • `Subscriber`– Assigning a value (`Reference`) to this property refines the result set to FeedItems representing activities on targets to which the identified user is subscribed.

  • `Target`– Assigning a value (`Reference`) to this property refines the result set to `FeedItems` representing activities targeting the identified entity.

You can apply the specifications of the `FeedItemFilter` in conjunction with one another. Each specification, which is assigned a value in the filter, further refines the result set (that is, a logical AND). In the following example, a page of FeedItems is retrieved for a particular subscriber.



In the previous example, the request to retrieve feed items is invoked synchronously. An example of retrieving feed items asynchronously using the asynchronous overload with C#'s async and await keywords is described below.



The `FeedItemSortFields` class exposes a set of fields upon which a result set of feed items may be ordered. These fields may be applied in the construction of sorting rules that you associate with your criteria. These fields include

  • `FeedItemSortFields.ActivityId`

  • `FeedItemSortFields.ActivityDate`

  • `FeedItemSortFields.Actor`

  • `FeedItemSortFields.Target`

The following example demonstrates how to apply sorting rules to order your result set by `Target` reference, alphabetically in ascending order. A fallback rule, subsequently ordering results with the same Target reference according to when the activity occurred from newest to oldest, is also added.



For details regarding the use of criteria, including information on paging and sorting, see _Criteria_ in [Discover the platform](🔗).

### Retrieve composite feed items

To retrieve a collection of FeedItems with their accompanying extension data, use the `Get<TExtension>(CompositeCriteria\<FeedItemFilter,TExtension>)` method. This method accepts an instance of `CompositeCriteria\<FeedItemFilter,TExtension>`, which contains the specifications necessary to retrieve the desire `FeedItems`.

The Filter property of the `CompositeCriteria\<FeedItemFilter,TExtension>` class accepts an instance of the `FeedItemFilter` class. This class contains the specifications that let you refine the result set of `FeedItems` that you want to retrieve.

The `ExtensionFilter` property of the `CompositeCriteria\<FeedItemFilter,TExtension>` class accepts a `FilterExpression`, which lets you specify a Boolean expression to further refine the result set by values represented within your extension data. For more information on this type of filter, see _Composite Criteria_ and _Filtering Composistes_ oin [Discover the platform](🔗).

In the following example, a page of `FeedItems` composed with the PageRated (a sample class used in earlier examples) is retrieved. The criteria combine a filter native to IFeedService with a custom one targeting a field the PageRated extension data.

More specifically, this sample demonstrates the retrieval of feed items targeting a specific resource (a page, product, etc.), upon which a PageRated activity has occurred where rating of 5 was assigned.



In the previous example, the request to retrieve feed items is invoked synchronously. An example of retrieving feed items asynchronously using the asynchronous overload with C#'s async and await keywords is described below.



The fields of your activity's extension data may also be applied in the sorting of your result set. The example below demonstrates the use of an extension data field in the definition of a sorting rule.



For details regarding the use of criteria, including information on paging and sorting, see _Criteria_ in [Discover the platform](🔗).