// First create a collection entry with upsert api
var collectionObj = new CollectionObject("cheese-burger");
collectionObj.SetData("name", "Cheese Burger");
await client.Collections.UpsertAsync("food", collectionObj);
// Then create a user
var userData = new Dictionary<string, object>
{
{"name", "John Doe"},
{"occupation", "Software Engineer"},
{"gender", "male"},
};
var user = await client.Users.AddAsync("john-doe", userData);
// Since we know their IDs we can create references to both without reading from APIs
var cheeseBurgerRef = client.Collections.Ref("food", "cheese-burger");
var johnDoeRef = client.Users.Ref("john-doe");
// And then add an activity with these references
var activity = new Activity(johnDoeRef, "eat", cheeseBurgerRef);
await client.Feed("user", "john").AddActivityAsync(activity);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", new CollectionData().set("name", "Cheese Burger")).join();
// Then create a user
client.user("john-doe").create(new Data()
.set("name", "John Doe")
.set("occupation", "Software Engineer")
.set("gender", "male")).join();
// Since we know their IDs we can create references to both without reading from APIs
String cheeseBurgerRef = createCollectionReference("food", "cheese-burger");
String johnDoeRef = createUserReference("john-doe");
client.flatFeed("user", "john").addActivity(Activity.builder()
.actor(johnDoeRef)
.verb("eat")
.object(cheeseBurgerRef)
.build()).join();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).