Activities
Confused about "Activities"?
Let us know how we can improve our documentation:
- On This Page:
- Adding Activities: Basic
- Fields
- Custom Fields
- Add Activity Response Data
- Retrieving Activities
- Parameters
- Pagination
- Retrieve Feed Response Data
- Removing Activities
- Updating Activities
- Activity Partial Update
- Parameters
- Batching Partial Updates
- Uniqueness & Foreign IDs
- GDPR-compliant actor discarding
- Automatic Activity Hiding
"In its simplest form, an activity consists of an actor, a verb, and an object. It tells the story of a person performing an action on or with an object."
Activity Streams Specification 1.0
Adding Activities: Basic
Copied!Confused about "Adding Activities: Basic"?
Let us know how we can improve our documentation:
Adding an activity in its simplest form means passing an object with the following basic properties:
Actor
Verb
Object
Recommended:
Foreign Id
Time
Here's an example:
“Erik is pinning Hawaii to his Places to Visit board.”
Let's break the example down:
Actor: "Eric" (User:1)
Verb: "pin"
Object: "Hawaii" (Place:42)
Foreign Id: "Eric's board activity" (Activity:1)
Time: 2017-07-01T20:30:45.123
Now, let's show you how to add an activity to a feed using your Stream API client:
Listed below are the mandatory and recommended fields when adding Activities.
Fields
Copied!Confused about "Fields "?
Let us know how we can improve our documentation:
name | type | description | default | optional |
---|---|---|---|---|
actor | string | the actor performing the activity | - | |
verb | string | The verb of the activity with a maximum length of 255 bytes | - | |
object | string | The object of the activity | - | |
time | string | The time of the activity, iso format (UTC local time). Required to ensure activity uniqueness and also to later update activities by Time + Foreign ID | Current time | ✓ |
to | list | See the documentation on Targeting & "TO" support. | - | ✓ |
foreign_id | string | A unique ID from your application for this activity. IE: pin:1 or like:300. Required to later update activities by Time + Foreign ID. | - | ✓ |
* | string / list / object / point | Add as many custom fields as needed. | - | ✓ |
Custom Fields
Copied!Confused about " Custom Fields"?
Let us know how we can improve our documentation:
In the above example, the course
, location
, participants
and started_at
fields will be stored with the Activity and included whenever the Activity is retrieved.
For performance reasons, activities are limited in size (10KB) and must not contain blob/binary data (e.g. base64 encoded images). Use references and identifiers to facilitate Activity enrichment by your backend or client.
activity_id
, activity
, analytics
, extra_context
, id
, is_read
, is_seen
, origin
, score
, site_id
, to
.Foreign IDs
The example above also specified a foreign_id
.
The foreign id
is a unique identifier for the activity that can be stored and used within the app. Making use of the the foreign id
field is highly recommended as it is needed in order to update Activities.
Add Activity Response Data
Copied!Confused about "Add Activity Response Data"?
Let us know how we can improve our documentation:
When an activity is successfully added, the Stream API includes activity id in the serialized JSON response, like so:
Retrieving Activities
Copied!Confused about "Retrieving Activities"?
Let us know how we can improve our documentation:
The example below shows how to retrieve the Activities in a feed:
Parameters
Copied!Confused about "Parameters"?
Let us know how we can improve our documentation:
name | type | description | default | optional |
---|---|---|---|---|
limit | integer | The number of Activities to retrieve (max: 100) | 25 | ✓ |
id_gte | string | Filter the feed on ids greater than or equal to the given value | - | ✓ |
id_gt | string | Filter the feed on ids greater than the given value | - | ✓ |
id_lte | string | Filter the feed on ids smaller than or equal to the given value | - | ✓ |
id_lt | string | Filter the feed on ids smaller than the given value | - | ✓ |
offset | integer | The offset | 0 | ✓ |
ranking | string | The custom ranking formula used to sort the feed, must be defined in the dashboard | - | ✓ |
enrich | boolean | When using collections, you can request Stream to enrich activities to include them | false | ✓ |
reactions.own | boolean | Include reactions added by current user to all activities (see reaction docs) | false | ✓ |
reactions.recent | boolean | Include recent reactions to activities (see reaction docs) | false | ✓ |
reaction.counts | boolean | Include reaction counts to activities (see reaction docs) | false | ✓ |
reaction.kinds | array | Filter reactions with given kinds (support differs by SDKs, request if missing) | - | ✓ |
Activity reads returns at most 100 Activities. Requests with a limit greater than 100 are automatically capped.
Pagination
Copied!Confused about "Pagination"?
Let us know how we can improve our documentation:
The recommended way to paginate feeds is with offset and limit parameters. Such approach makes for simpler code and it works for all types of feeds.
id_lte
to paginate an aggregated feed, use the ID of the group that is returned from the API. Using an ID of an individual activity within the group will not work and result in an error.Retrieve Feed Response Data
Copied!Confused about "Retrieve Feed Response Data"?
Let us know how we can improve our documentation:
When a feed is successfully retrieved, the Stream API returns the following payload:
The format for results array depends on the type of feed associated with the notification. When a Flat Feed is retrieved, the array contains Activities. Whereas when an Aggregated or Notification Feed is retrieved, the array contains Activity Groups.
The 'next' property in the response contains a URL that may be used to retrieve the next page of activities within the feed.
Removing Activities
Copied!Confused about "Removing Activities"?
Let us know how we can improve our documentation:
There are two ways to remove an activity:
Activity Id - found in the serialized response from server
Foreign Id - optionally specified when adding an activity
Have a look at the section on Using Foreign IDs.
Updating Activities
Copied!Confused about "Updating Activities"?
Let us know how we can improve our documentation:
Activities that have both foreign_id
and time
defined can be updated via the APIs. Changes to activities immediately show up on every feed.
time
& foreign_id
to
field are ignored.This API method works particularly well in combination with the ranked feeds. You can, for instance, issue an update if an activity is promoted or not and use the ranked feeds to show it higher in the feed. Similarly, you could update the like
and comment
counts and use a ranking method based on popularity to sort the activities.
Activity Partial Update
Copied!Confused about "Activity Partial Update"?
Let us know how we can improve our documentation:
It is possible to update only a part of an activity with the partial update request. You can think of it as a quick "patching operation".
The activity to update can be selected by its ID or Foreign ID and Time combination.
A set
and an unset
params can be provided to add, modify, or remove attributes to/from the target activity. The set
and unset
params can be used separately or combined together (see below).
Parameters
Copied!Confused about "Parameters "?
Let us know how we can improve our documentation:
name | type | description | default | optional |
---|---|---|---|---|
id | string | The target activity ID | - | ✓ |
foreign_id | string | The target activity foreign ID | - | ✓ |
time | string | The target activity timestamp | - | ✓ |
set | object | The set operations, max 25 top level keys | - | ✓ |
unset | list | The unset operations. max 25 | - | ✓ |
The set
object contains the insertion updates for the target fields, where the keys are the activity fields to update and the values are the new ones to assign. If the target field does not exist, it's created with the given content. If the target field exists, its content is replaced.
It is possible to quickly reference nested elements using the dotted notation (father.child. ...
), but in this case the whole hierarchy is required to exist and to be valid.
For example, if the target activity looks like the following:
It is possible to update the product's EUR price with the key "product.price.eur"
, or even create a new field with the key "product.price.gbp"
, but it's not possible to reference a non-existing hierarchy like "product.colors.blue"
.
The unset
field contains a list of key strings that will be removed from the activity's payload. They must exist, and, if referenced with the dotted notation, their hierarchy must be valid.
The set
and unset
fields can be combined in the same request, but they must not be conflicting with each other (they must not have operations referencing the same keys or hierarchies).
The following example shows a valid combination of set and unset operations which will update the above example activity:
id
, actor
, verb
, object
, time
, target
, foreign_id
, to
, origin
Batching Partial Updates
Copied!Confused about "Batching Partial Updates"?
Let us know how we can improve our documentation:
It is also possible to partially update activities in batches. The same individual activity restrictions are applied, and there's a limit of 100 activities per batch.
Activities in each batch can be identified either by their ID or by the ForeignID and Time combination:
Uniqueness & Foreign IDs
Copied!Confused about "Uniqueness & Foreign IDs"?
Let us know how we can improve our documentation:
Stream handles uniqueness based on the foreign_id
and time
fields. If you want to be able to update your activities you need to specify both of these fields.
Uniqueness is enforced on the combination of time
and foreign_id
. See the example below for an overview:
foreign_id
and time ensure that both activities are unique and therefore the first_activity_id
!=
second_activity_id
.By default, activity upsert by this uniqueness guarantee is enabled and it can be disabled per application in the server side by contacting to support. Additionally, it's also disabled if a request is using a client side authentication or has disable_activity_upsert
query parameter.
GDPR-compliant actor discarding
Copied!Confused about "GDPR-compliant actor discarding"?
Let us know how we can improve our documentation:
Since the Feeds API doesn't require users there's no user-to-user blocking. However, in order to stay GDPR compliant there's support for discarding actors when reading a feed. This leaves it up to the customer to keep track of which users have blocked other users.
Automatic Activity Hiding
Copied!Confused about "Automatic Activity Hiding"?
Let us know how we can improve our documentation:
It's possible to have the Feeds API automatically hide activities older than X days/months/years. This is an app-level setting, please contact support if you wish to have it enabled.