let response = try await client.createCollections(
request: .init(
collections: [
.init(
name: "movies",
id: "lord_of_the_rings",
custom: [
"title": "Lord of the Rings",
"genre": "fantasy",
"rating": 9
]
)
]
)
)Collections
Overview
Collections provide a way to attach data to activities that is shared between these activities and can be updated in a single place.
A typical use case is to track the status of an activity such as started, completed, or failed. Instead of having to update multiple activities when the status changes you can create a collection and add it to the activities that needs this data. When the status changes you only need to update the collection.
A collection consists of a name, an id and some data. You can think of the name as a namespace for the collection. A collection reference is a string that looks like <name>:<id> and is the unique identifier for the collection.
Data stored in collections can not be used in custom ranking or aggregation.
The batch endpoints supports up to 100 collections in a single request. Automatic deduplication will be applied, keeping the last occurrence only.
Creating Collections
The example below shows how to create a collection.
val response: Result<CreateCollectionsResponse> = client.createCollections(
request = CreateCollectionsRequest(
collections = listOf(
CollectionRequest(
name = "movies",
id = "lord_of_the_rings",
custom = mapOf(
"title" to "Lord of the Rings",
"genre" to "fantasy",
"rating" to 9
)
)
)
)
)const response = await client.createCollections({
collections: [
{
name: "movies",
id: "lord_of_the_rings",
custom: {
title: "Lord of the Rings",
genre: "fantasy",
rating: 9,
},
},
],
});const response = await client.feeds.createCollections({
collections: [
{
name: "movies",
id: "lord_of_the_rings",
custom: {
title: "Lord of the Rings",
genre: "fantasy",
rating: 9,
},
},
],
});final response = await client.createCollections(
collections: [
const CollectionRequest(
name: 'movies',
id: 'lord_of_the_rings',
custom: {
'title': 'Lord of the Rings',
'genre': 'fantasy',
'rating': 9,
},
),
],
);response, err := client.Feeds().CreateCollections(context.Background(), &getstream.CreateCollectionsRequest{
Collections: []getstream.CollectionRequest{
{
Name: "movies",
ID: "lord_of_the_rings",
Custom: map[string]any{
"title": "Lord of the Rings",
"genre": "fantasy",
"rating": 9,
},
},
},
})
if err != nil {
log.Fatal("Error creating collections:", err)
}Map<String, Object> customData = new HashMap<>();
customData.put("title", "Lord of the Rings");
customData.put("genre", "fantasy");
customData.put("rating", 9);
CollectionRequest collection = CollectionRequest.builder()
.name("movies")
.id("lord_of_the_rings")
.custom(customData)
.build();
CreateCollectionsRequest request = CreateCollectionsRequest.builder()
.collections(List.of(collection))
.build();
CreateCollectionsResponse response = feeds.createCollections(request).execute().getData();$collection = new GeneratedModels\CollectionRequest(
name: 'movies',
id: 'lord_of_the_rings',
custom: (object)[
'title' => 'Lord of the Rings',
'genre' => 'fantasy',
'rating' => 9,
]
);
$response = $feedsClient->createCollections(
new GeneratedModels\CreateCollectionsRequest(collections: [$collection])
);var collection = new CollectionRequest
{
Name = "movies",
ID = "lord_of_the_rings",
Custom = new Dictionary<string, object>
{
{ "title", "Lord of the Rings" },
{ "genre", "fantasy" },
{ "rating", 9 }
}
};
var response = await _feedsV3Client.CreateCollectionsAsync(
new CreateCollectionsRequest { Collections = new List<CollectionRequest> { collection } }
);response = client.feeds.create_collections(
collections=[
CollectionRequest(
name="movies",
id="lord_of_the_rings",
custom={
"title": "Lord of the Rings",
"genre": "fantasy",
"rating": 9,
}
)
]
)collection = GetStream::Generated::Models::CollectionRequest.new(
name: 'movies',
id: 'lord_of_the_rings',
custom: {
title: 'Lord of the Rings',
genre: 'fantasy',
rating: 9
}
)
request = GetStream::Generated::Models::CreateCollectionsRequest.new(
collections: [collection]
)
response = client.feeds.create_collections(request)Overview of the collection model
CollectionResponse
| Name | Type | Description | Constraints |
|---|---|---|---|
created_at | number | When the collection was created | - |
custom | object | Custom data for the collection | - |
id | string | Unique identifier for the collection within its name | Required |
name | string | Name/type of the collection | Required |
updated_at | number | When the collection was last updated | - |
user_id | string | ID of the user who owns this collection | - |
Updating Collections
The example below shows how to update a collection.
let response = try await client.updateCollections(
request: .init(
collections: [
.init(
name: "movies",
id: "lord_of_the_rings",
custom: [
"title": "Lord of the Rings",
"genre": "fantasy",
"rating": 9.5
]
)
]
)
)val response: Result<UpdateCollectionsResponse> = client.updateCollections(
request = UpdateCollectionsRequest(
collections = listOf(
UpdateCollectionRequest(
name = "movies",
id = "lord_of_the_rings",
custom = mapOf(
"title" to "Lord of the Rings",
"genre" to "fantasy",
"rating" to 9.5
)
)
)
)
)const response = await client.updateCollections({
collections: [
{
name: "movies",
id: "lord_of_the_rings",
custom: {
title: "Lord of the Rings",
genre: "fantasy",
rating: 9.5,
},
},
],
});const response = await client.feeds.updateCollections({
collections: [
{
name: "movies",
id: "lord_of_the_rings",
custom: {
title: "Lord of the Rings",
genre: "fantasy",
rating: 9.5,
},
},
],
});final response = await client.updateCollections(
collections: [
const CollectionRequest(
name: 'movies',
id: 'lord_of_the_rings',
custom: {
'title': 'Lord of the Rings',
'genre': 'fantasy',
'rating': 9.5,
},
),
],
);response, err := client.Feeds().UpdateCollections(context.Background(), &getstream.UpdateCollectionsRequest{
Collections: []getstream.CollectionRequest{
{
Name: "movies",
ID: "lord_of_the_rings",
Custom: map[string]any{
"title": "Lord of the Rings",
"genre": "fantasy",
"rating": 9.5,
},
},
},
})
if err != nil {
log.Fatal("Error updating collections:", err)
}Map<String, Object> customData = new HashMap<>();
customData.put("title", "Lord of the Rings");
customData.put("genre", "fantasy");
customData.put("rating", 9.5);
CollectionRequest collection = CollectionRequest.builder()
.name("movies")
.id("lord_of_the_rings")
.custom(customData)
.build();
UpdateCollectionsRequest request = UpdateCollectionsRequest.builder()
.collections(List.of(collection))
.build();
UpdateCollectionsResponse response = feeds.updateCollections(request).execute().getData();$collection = new GeneratedModels\CollectionRequest(
name: 'movies',
id: 'lord_of_the_rings',
custom: (object)[
'title' => 'Lord of the Rings',
'genre' => 'fantasy',
'rating' => 9.5,
]
);
$response = $feedsClient->updateCollections(
new GeneratedModels\UpdateCollectionsRequest(collections: [$collection])
);var collection = new CollectionRequest
{
Name = "movies",
ID = "lord_of_the_rings",
Custom = new Dictionary<string, object>
{
{ "title", "Lord of the Rings" },
{ "genre", "fantasy" },
{ "rating", 9.5 }
}
};
var response = await _feedsV3Client.UpdateCollectionsAsync(
new UpdateCollectionsRequest { Collections = new List<CollectionRequest> { collection } }
);response = client.feeds.update_collections(
collections=[
CollectionRequest(
name="movies",
id="lord_of_the_rings",
custom={
"title": "Lord of the Rings",
"genre": "fantasy",
"rating": 9.5,
}
)
]
)collection = GetStream::Generated::Models::CollectionRequest.new(
name: 'movies',
id: 'lord_of_the_rings',
custom: {
title: 'Lord of the Rings',
genre: 'fantasy',
rating: 9.5
}
)
request = GetStream::Generated::Models::UpdateCollectionsRequest.new(
collections: [collection]
)
response = client.feeds.update_collections(request)Deleting Collections
The example below shows how to delete a collection.
let response = try await client.deleteCollections(
request: .init(
collectionRefs: ["movies:lord_of_the_rings"]
)
)val response: Result<DeleteCollectionsResponse> = client.deleteCollections(
refs = listOf("movies:lord_of_the_rings")
)const response = await client.deleteCollections({
collection_refs: ["movies:lord_of_the_rings"],
});const response = await client.feeds.deleteCollections({
collection_refs: ["movies:lord_of_the_rings"],
});final response = await client.deleteCollections(
collectionRefs: ['movies:lord_of_the_rings'],
);response, err := client.Feeds().DeleteCollections(context.Background(), &getstream.DeleteCollectionsRequest{
CollectionRefs: []string{"movies:lord_of_the_rings"},
})
if err != nil {
log.Fatal("Error deleting collections:", err)
}DeleteCollectionsRequest request = DeleteCollectionsRequest.builder()
.collectionRefs(List.of("movies:lord_of_the_rings"))
.build();
DeleteCollectionsResponse response = feeds.deleteCollections(request).execute().getData();$response = $feedsClient->deleteCollections(
new GeneratedModels\DeleteCollectionsRequest(
collectionRefs: ['movies:lord_of_the_rings']
)
);var response = await _feedsV3Client.DeleteCollectionsAsync(
new DeleteCollectionsRequest { CollectionRefs = new List<string> { "movies:lord_of_the_rings" } }
);response = client.feeds.delete_collections(
collection_refs=["movies:lord_of_the_rings"]
)request = GetStream::Generated::Models::DeleteCollectionsRequest.new(
collection_refs: ['movies:lord_of_the_rings']
)
response = client.feeds.delete_collections(request)Reading Collections
The example below shows how to read a collection.
let response = try await client.readCollections(
request: .init(
collectionRefs: ["movies:lord_of_the_rings"]
)
)val response: Result<ReadCollectionsResponse> = client.readCollections(
refs = listOf("movies:lord_of_the_rings")
)const response = await client.readCollections({
collection_refs: ["movies:lord_of_the_rings"],
});const response = await client.feeds.readCollections({
collection_refs: ["movies:lord_of_the_rings"],
});final response = await client.readCollections(
collectionRefs: ['movies:lord_of_the_rings'],
);response, err := client.Feeds().ReadCollections(context.Background(), &getstream.ReadCollectionsRequest{
CollectionRefs: []string{"movies:lord_of_the_rings"},
})
if err != nil {
log.Fatal("Error reading collections:", err)
}ReadCollectionsRequest request = ReadCollectionsRequest.builder()
.collectionRefs(List.of("movies:lord_of_the_rings"))
.build();
ReadCollectionsResponse response = feeds.readCollections(request).execute().getData();$response = $feedsClient->readCollections(
new GeneratedModels\ReadCollectionsRequest(
collectionRefs: ['movies:lord_of_the_rings']
)
);var response = await _feedsV3Client.ReadCollectionsAsync(
new ReadCollectionsRequest { CollectionRefs = new List<string> { "movies:lord_of_the_rings" } }
);response = client.feeds.read_collections(
collection_refs=["movies:lord_of_the_rings"]
)request = GetStream::Generated::Models::ReadCollectionsRequest.new(
collection_refs: ['movies:lord_of_the_rings']
)
response = client.feeds.read_collections(request)Activities and Enrichment
Collections are added to activities in the form of collection references. An activity can reference up to 10 collections.
Support for adding collections directly when creating activities is coming soon.
Adding Collections to an Activity
let response = try await feed.addActivity(
request: .init(
type: "post",
text: "I love this movie!",
collectionRefs: ["movies:lord_of_the_rings"]
)
)val response: Result<ActivityData> = feed.addActivity(
request = FeedAddActivityRequest(
type = "post",
text = "I love this movie!",
collectionRefs = listOf("movies:lord_of_the_rings")
)
)const response = await feed.addActivity({
type: "post",
text: "I love this movie!",
collection_refs: ["movies:lord_of_the_rings"],
});const response = await client.feeds.addActivity({
type: 'post',
feeds: [...],
text: 'I love this movie!',
collection_refs: ['movies:lord_of_the_rings'],
});final response = await feed.addActivity(
request: const FeedAddActivityRequest(
type: 'post',
text: 'I love this movie!',
collectionRefs: ['movies:lord_of_the_rings'],
),
);feedsClient := client.Feeds()
response, err := feedsClient.AddActivity(context.Background(), &getstream.AddActivityRequest{
Type: "post",
Feeds: []string{"user:jack"},
Text: getstream.PtrTo("I love this movie!"),
UserID: getstream.PtrTo("jack"),
CollectionRefs: []string{"movies:lord_of_the_rings"},
})
if err != nil {
log.Fatal("Error adding activity:", err)
}AddActivityRequest activity =
AddActivityRequest.builder()
.type("post")
.feeds(List.of("user:jack"))
.text("I love this movie!")
.userID("jack")
.collectionRefs(List.of("movies:lord_of_the_rings"))
.build();
AddActivityResponse response = feeds.addActivity(activity).execute().getData();$activity = new GeneratedModels\AddActivityRequest(
type: 'post',
feeds: ['user:jack'],
text: 'I love this movie!',
userID: 'jack',
collectionRefs: ['movies:lord_of_the_rings']
);
$response = $feedsClient->addActivity($activity);var activity = new AddActivityRequest
{
Type = "post",
Text = "I love this movie!",
UserID = "jack",
Feeds = new List<string> { "user:jack" },
CollectionRefs = new List<string> { "movies:lord_of_the_rings" }
};
var response = await _feedsV3Client.AddActivityAsync(activity);response = client.feeds.add_activity(
type="post",
feeds=["user:jack"],
text="I love this movie!",
user_id="jack",
collection_refs=["movies:lord_of_the_rings"]
)activity_request = GetStream::Generated::Models::AddActivityRequest.new(
type: 'post',
text: 'I love this movie!',
user_id: 'jack',
feeds: ['user:jack'],
collection_refs: ['movies:lord_of_the_rings']
)
response = client.feeds.add_activity(activity_request)Enrichment
When you have added collection references to your activities these will automatically be enriched with the collection data when reading feeds.
// Create a collection
let createResponse = try await client.createCollections(
request: .init(
collections: [
.init(
name: "movies",
id: "lord_of_the_rings",
custom: [
"title": "Lord of the Rings",
"genre": "fantasy",
"rating": 9
]
)
]
)
)
// Add the reference to an activity
let feed = client.feed(group: "user", id: "jack")
let activityResponse = try await feed.addActivity(
request: .init(
type: "post",
text: "I love this movie!",
collectionRefs: ["movies:lord_of_the_rings"]
)
)
// Read the feed and see the enriched collection data
try await feed.getOrCreate()
let activities = feed.state.activities
// The activities will contain enriched collection data in the collections field
// Example response structure:
// {
// "activities": [
// {
// "type": "post",
// "text": "I love this movie!",
// "collections": {
// "movies:lord_of_the_rings": {
// "name": "movies",
// "id": "lord_of_the_rings",
// "custom": {
// "title": "Lord of the Rings",
// "genre": "fantasy",
// "rating": 9
// },
// "user_id": "jack",
// "created_at": "2025-01-01T00:00:00.000Z",
// "updated_at": "2025-01-01T00:00:00.000Z",
// "status": "ok"
// }
// }
// }
// ],
// ...
// }// Create a collection
val createResponse: Result<CreateCollectionsResponse> = client.createCollections(
request = CreateCollectionsRequest(
collections = listOf(
CollectionRequest(
name = "movies",
id = "lord_of_the_rings",
custom = mapOf(
"title" to "Lord of the Rings",
"genre" to "fantasy",
"rating" to 9
)
)
)
)
)
// Add the reference to an activity
val feed = client.feed(group = "user", id = "jack")
val activityResponse: Result<ActivityData> = feed.addActivity(
request = FeedAddActivityRequest(
type = "post",
text = "I love this movie!",
collectionRefs = listOf("movies:lord_of_the_rings")
)
)
// Read the feed and see the enriched collection data
feed.getOrCreate()
val activities = feed.state.activities
// The activities will contain enriched collection data in the collections field
// Example response structure:
// {
// "activities": [
// {
// "type": "post",
// "text": "I love this movie!",
// "collections": {
// "movies:lord_of_the_rings": {
// "name": "movies",
// "id": "lord_of_the_rings",
// "custom": {
// "title": "Lord of the Rings",
// "genre": "fantasy",
// "rating": 9
// },
// "user_id": "jack",
// "created_at": "2025-01-01T00:00:00.000Z",
// "updated_at": "2025-01-01T00:00:00.000Z",
// "status": "ok"
// }
// }
// }
// ],
// ...
// }// Create a collection
await client.createCollections({
collections: [
{
name: "movies",
id: "lord_of_the_rings",
custom: {
title: "Lord of the Rings",
genre: "fantasy",
rating: 9,
},
},
],
});
// Add the reference to an activity
const feed = client.feed("user", "jack");
await feed.addActivity({
type: "post",
text: "I love this movie!",
collection_refs: ["movies:lord_of_the_rings"],
});
// Read the feed and see the enriched collection data
const response = await feed.getOrCreate({});
console.log(response);
/*
{
"activities": [
{
"type": "post",
"text": "I love this movie!",
"collections": {
"movies:lord_of_the_rings": {
"name": "movies",
"id": "lord_of_the_rings",
"custom": {
"title": "Lord of the Rings",
"genre": "fantasy",
"rating": 9
},
"user_id": "jack",
"created_at": "2025-01-01T00:00:00.000Z",
"updated_at": "2025-01-01T00:00:00.000Z",
"status": "ok"
}
}
}
],
...
}
*/// Create a collection
await client.feeds.createCollections({
collections: [
{
name: "movies",
id: "lord_of_the_rings",
custom: {
title: "Lord of the Rings",
genre: "fantasy",
rating: 9,
},
},
],
});
// Add the reference to an activity
const feed = client.feeds.feed("user", "jack");
await feed.addActivity({
type: "post",
text: "I love this movie!",
collection_refs: ["movies:lord_of_the_rings"],
user_id: "jack",
});
// Read the feed and see the enriched collection data
const response = await feed.getOrCreate({ user_id: "jack" });
console.log(response);
/*
{
"activities": [
{
"type": "post",
"text": "I love this movie!",
"collections": {
"movies:lord_of_the_rings": {
"name": "movies",
"id": "lord_of_the_rings",
"custom": {
"title": "Lord of the Rings",
"genre": "fantasy",
"rating": 9
},
"user_id": "jack",
"created_at": "2025-01-01T00:00:00.000Z",
"updated_at": "2025-01-01T00:00:00.000Z",
"status": "ok"
}
}
}
],
...
}
*/// Create a collection
final createResponse = await client.createCollections(
collections: [
const CollectionRequest(
name: 'movies',
id: 'lord_of_the_rings',
custom: {
'title': 'Lord of the Rings',
'genre': 'fantasy',
'rating': 9,
},
),
],
);
// Add the reference to an activity
final feed = client.feed(group: 'user', id: 'jack');
final activityResponse = await feed.addActivity(
request: const FeedAddActivityRequest(
type: 'post',
text: 'I love this movie!',
collectionRefs: ['movies:lord_of_the_rings'],
),
);
// Read the feed and see the enriched collection data
await feed.getOrCreate();
final activities = feed.state.activities;
// The activities will contain enriched collection data in the collections field
// Example response structure:
// {
// "activities": [
// {
// "type": "post",
// "text": "I love this movie!",
// "collections": {
// "movies:lord_of_the_rings": {
// "name": "movies",
// "id": "lord_of_the_rings",
// "custom": {
// "title": "Lord of the Rings",
// "genre": "fantasy",
// "rating": 9
// },
// "user_id": "jack",
// "created_at": "2025-01-01T00:00:00.000Z",
// "updated_at": "2025-01-01T00:00:00.000Z",
// "status": "ok"
// }
// }
// }
// ],
// ...
// }// Create a collection
_, err := client.Feeds().CreateCollections(context.Background(), &getstream.CreateCollectionsRequest{
Collections: []getstream.CollectionRequest{
{
Name: "movies",
ID: "lord_of_the_rings",
Custom: map[string]any{
"title": "Lord of the Rings",
"genre": "fantasy",
"rating": 9,
},
},
},
})
if err != nil {
log.Fatal("Error creating collections:", err)
}
// Add the reference to an activity
feedsClient := client.Feeds()
feed := feedsClient.Feed("user", "jack")
_, err = feedsClient.AddActivity(context.Background(), &getstream.AddActivityRequest{
Type: "post",
Feeds: []string{"user:jack"},
Text: getstream.PtrTo("I love this movie!"),
UserID: getstream.PtrTo("jack"),
CollectionRefs: []string{"movies:lord_of_the_rings"},
})
if err != nil {
log.Fatal("Error adding activity:", err)
}
// Read the feed and see the enriched collection data
response, err := feed.GetOrCreate(context.Background(), &getstream.GetOrCreateFeedRequest{
UserID: getstream.PtrTo("jack"),
})
if err != nil {
log.Fatal("Error reading feed:", err)
}
activities := response.Data.Activities
// The activities will contain enriched collection data in the collections field
// Example response structure:
// {
// "activities": [
// {
// "type": "post",
// "text": "I love this movie!",
// "collections": {
// "movies:lord_of_the_rings": {
// "name": "movies",
// "id": "lord_of_the_rings",
// "custom": {
// "title": "Lord of the Rings",
// "genre": "fantasy",
// "rating": 9
// },
// "user_id": "jack",
// "created_at": "2025-01-01T00:00:00.000Z",
// "updated_at": "2025-01-01T00:00:00.000Z",
// "status": "ok"
// }
// }
// }
// ],
// ...
// }// Create a collection
Map<String, Object> customData = new HashMap<>();
customData.put("title", "Lord of the Rings");
customData.put("genre", "fantasy");
customData.put("rating", 9);
CollectionRequest collection = CollectionRequest.builder()
.name("movies")
.id("lord_of_the_rings")
.custom(customData)
.build();
CreateCollectionsRequest createRequest = CreateCollectionsRequest.builder()
.collections(List.of(collection))
.build();
feeds.createCollections(createRequest).execute().getData();
// Add the reference to an activity
AddActivityRequest activity =
AddActivityRequest.builder()
.type("post")
.feeds(List.of("user:jack"))
.text("I love this movie!")
.userID("jack")
.collectionRefs(List.of("movies:lord_of_the_rings"))
.build();
feeds.addActivity(activity).execute().getData();
// Read the feed and see the enriched collection data
Feed feed = new Feed("user", "jack", feeds);
GetOrCreateFeedRequest feedRequest = GetOrCreateFeedRequest.builder()
.userID("jack")
.build();
GetOrCreateFeedResponse feedResponse = feed.getOrCreate(feedRequest).getData();
List<Activity> activities = feedResponse.getActivities();
// The activities will contain enriched collection data in the collections field
// Example response structure:
// {
// "activities": [
// {
// "type": "post",
// "text": "I love this movie!",
// "collections": {
// "movies:lord_of_the_rings": {
// "name": "movies",
// "id": "lord_of_the_rings",
// "custom": {
// "title": "Lord of the Rings",
// "genre": "fantasy",
// "rating": 9
// },
// "user_id": "jack",
// "created_at": "2025-01-01T00:00:00.000Z",
// "updated_at": "2025-01-01T00:00:00.000Z",
// "status": "ok"
// }
// }
// }
// ],
// ...
// }// Create a collection
$collection = new GeneratedModels\CollectionRequest(
name: 'movies',
id: 'lord_of_the_rings',
custom: (object)[
'title' => 'Lord of the Rings',
'genre' => 'fantasy',
'rating' => 9,
]
);
$feedsClient->createCollections(
new GeneratedModels\CreateCollectionsRequest(collections: [$collection])
);
// Add the reference to an activity
$activity = new GeneratedModels\AddActivityRequest(
type: 'post',
feeds: ['user:jack'],
text: 'I love this movie!',
userID: 'jack',
collectionRefs: ['movies:lord_of_the_rings']
);
$feedsClient->addActivity($activity);
// Read the feed and see the enriched collection data
$feed = $feedsClient->feed('user', 'jack');
$response = $feed->getOrCreateFeed(
new GeneratedModels\GetOrCreateFeedRequest(userID: 'jack')
);
$activities = $response->getData()->activities;
// The activities will contain enriched collection data in the collections field
// Example response structure:
// {
// "activities": [
// {
// "type": "post",
// "text": "I love this movie!",
// "collections": {
// "movies:lord_of_the_rings": {
// "name": "movies",
// "id": "lord_of_the_rings",
// "custom": {
// "title": "Lord of the Rings",
// "genre": "fantasy",
// "rating": 9
// },
// "user_id": "jack",
// "created_at": "2025-01-01T00:00:00.000Z",
// "updated_at": "2025-01-01T00:00:00.000Z",
// "status": "ok"
// }
// }
// }
// ],
// ...
// }// Create a collection
var collection = new CollectionRequest
{
Name = "movies",
ID = "lord_of_the_rings",
Custom = new Dictionary<string, object>
{
{ "title", "Lord of the Rings" },
{ "genre", "fantasy" },
{ "rating", 9 }
}
};
await _feedsV3Client.CreateCollectionsAsync(
new CreateCollectionsRequest { Collections = new List<CollectionRequest> { collection } }
);
// Add the reference to an activity
var activity = new AddActivityRequest
{
Type = "post",
Text = "I love this movie!",
UserID = "jack",
Feeds = new List<string> { "user:jack" },
CollectionRefs = new List<string> { "movies:lord_of_the_rings" }
};
await _feedsV3Client.AddActivityAsync(activity);
// Read the feed and see the enriched collection data
var feedResponse = await _feedsV3Client.GetOrCreateFeedAsync(
FeedGroupID: "user",
FeedID: "jack",
request: new GetOrCreateFeedRequest { UserID = "jack" }
);
var activities = feedResponse.Activities;
// The activities will contain enriched collection data in the collections field
// Example response structure:
// {
// "activities": [
// {
// "type": "post",
// "text": "I love this movie!",
// "collections": {
// "movies:lord_of_the_rings": {
// "name": "movies",
// "id": "lord_of_the_rings",
// "custom": {
// "title": "Lord of the Rings",
// "genre": "fantasy",
// "rating": 9
// },
// "user_id": "jack",
// "created_at": "2025-01-01T00:00:00.000Z",
// "updated_at": "2025-01-01T00:00:00.000Z",
// "status": "ok"
// }
// }
// }
// ],
// ...
// }# Create a collection
response = client.feeds.create_collections(
collections=[
CollectionRequest(
name="movies",
id="lord_of_the_rings",
custom={
"title": "Lord of the Rings",
"genre": "fantasy",
"rating": 9,
}
)
]
)
# Add the reference to an activity
response = client.feeds.add_activity(
type="post",
feeds=["user:jack"],
text="I love this movie!",
user_id="jack",
collection_refs=["movies:lord_of_the_rings"]
)
# Read the feed and see the enriched collection data
feed = client.feeds.feed("user", "jack")
feed_response = feed.get_or_create(user_id="jack")
activities = feed_response.activities
# The activities will contain enriched collection data in the collections field
# Example response structure:
# {
# "activities": [
# {
# "type": "post",
# "text": "I love this movie!",
# "collections": {
# "movies:lord_of_the_rings": {
# "name": "movies",
# "id": "lord_of_the_rings",
# "custom": {
# "title": "Lord of the Rings",
# "genre": "fantasy",
# "rating": 9
# },
# "user_id": "jack",
# "created_at": "2025-01-01T00:00:00.000Z",
# "updated_at": "2025-01-01T00:00:00.000Z",
# "status": "ok"
# }
# }
# }
# ],
# ...
# }# Create a collection
collection = GetStream::Generated::Models::CollectionRequest.new(
name: 'movies',
id: 'lord_of_the_rings',
custom: {
title: 'Lord of the Rings',
genre: 'fantasy',
rating: 9
}
)
request = GetStream::Generated::Models::CreateCollectionsRequest.new(
collections: [collection]
)
client.feeds.create_collections(request)
# Add the reference to an activity
activity_request = GetStream::Generated::Models::AddActivityRequest.new(
type: 'post',
text: 'I love this movie!',
user_id: 'jack',
feeds: ['user:jack'],
collection_refs: ['movies:lord_of_the_rings']
)
client.feeds.add_activity(activity_request)
# Read the feed and see the enriched collection data
feed = client.feed('user', 'jack')
feed_request = GetStream::Generated::Models::GetOrCreateFeedRequest.new(user_id: 'jack')
feed_response = feed.get_or_create_feed(feed_request)
activities = feed_response.activities
# The activities will contain enriched collection data in the collections field
# Example response structure:
# {
# "activities": [
# {
# "type": "post",
# "text": "I love this movie!",
# "collections": {
# "movies:lord_of_the_rings": {
# "name": "movies",
# "id": "lord_of_the_rings",
# "custom": {
# "title": "Lord of the Rings",
# "genre": "fantasy",
# "rating": 9
# },
# "user_id": "jack",
# "created_at": "2025-01-01T00:00:00.000Z",
# "updated_at": "2025-01-01T00:00:00.000Z",
# "status": "ok"
# }
# }
# }
# ],
# ...
# }The enrichment is a best effort process. Missing or deleted collections will not be enriched but will be retured with a status of notfound