// First create a collection entry with upsert api
await client.collections.upsert("food", [
{ id: "cheese-burger", name: "Cheese Burger" },
]);
// Then create a user
await client.user("john-doe").create({
name: "John Doe",
occupation: "Software Engineer",
gender: "male",
});
// Since we know their IDs we can create references to both without reading from APIs
const cheeseBurgerRef = client.collections.entry("food", "cheese-burger");
const johnDoeRef = client.user("john-doe");
// And then add an activity with these references
await client.feed("user", "john").addActivity({
actor: johnDoeRef,
verb: "eat",
object: cheeseBurgerRef,
});You are viewing the Feeds v2 documentation. Feeds v2 is in maintenance mode and no longer receives new features. New projects should use Feeds v3, a major upgrade in performance, capabilities, and developer experience. To move an existing app, follow the migration guide.
References
When you add a user or a collection object to an activity, Stream stores the unique reference and replaces it at read time. In some complex cases, you need to be able to generate a reference to an existing object and embed that inside of an activity.
# First create a collection entry with upsert api
client.collections.upsert(
"food", [{"id": "cheese-burger", "name": "Cheese Burger"}]
)
# Then create a user
client.users.add(
"john-doe",
{"name": "John Doe", "occupation": "Software Engineer", "gender": "male"},
)
# Since we know their IDs we can create references to both without reading from APIs
cheese_burger_ref = client.collections.create_reference("food", "cheese-burger")
john_doe_ref = client.users.create_reference("john-doe")
# And then add an activity with these references
client.feed("user", "john").add_activity(
{"actor": john_doe_ref, "verb": "eat", "object": cheese_burger_ref}
)If you are using the APIs on web / mobile (see auth section) you must set activity.actor to the reference of the current user or otherwise you will get a permission error (see examples above).