getPosts
Return an array of posts that match the query.
How to use?
const { data, error } = await orbis.getPosts(options?, page?, limit?, ascending?);Parameters
options- object containing the filters you can use in this query:context-stringContext for which you want to retrieve the postsdid-stringRetrieving posts shared by a specific usermaster-stringWhen querying the comments under a parent postonly_master-booleanUse true if you want only master posts to be returnedtag-stringTo query only posts shared with a specific tagterm-stringWill return posts containing the term, which can be used for searchinclude_child_contexts-booleanWill also return posts shared from child contexts when set to truealgorithm-stringReturns an ordered list of posts shared in the global feed. Can be one of those:recommendations- Posts shared by users being followed by the connected user or on which they reacted.all-posts- Returns all the posts shared by users with an active wallet.all-posts-non-filtered- Returns all the posts shared by users (not filtered with wallet activity).
page-intIs 0 by default, increment this to retrieve additional postslimit-intNumber of posts returned by the query. Default is 50ascending-booleanordering direction for the returned result
Returns
[
{
stream_id: "kjzl6cwe1...e4wvxhiqj",
creator: "did:pkh:...",
creator_details: {
did: "did:pkh:...",
profile: {
username: "Baptiste",
pfp: "https://..."
}
},
content: {
body: "Content of the post itself",
...
},
context: null,
context_details: {
group_id: "...",
group_details: {
...
},
channel_id: "...",
channel_details: {
...
},
},
master: "k...",
reply_to: "k...",
reply_to_details: {
body: "Parent post being replied to...",
...
},
count_likes: 0,
count_haha: 0,
count_downvotes: 0,
count_replies: 0
},
...
]Examples
Query posts from the Global feed
This query will fetch posts from the Global Orbis context with a "recommendations" algorithm.
const { data, error } = await orbis.getPosts({ algorithm: "recommendations" });Query posts from a specified context
const { data, error } = await orbis.getPosts({ context: "k..." });Query posts with a specified tag
This query will fetch posts from a given context that match the specified tag.
const { data, error } = await orbis.getPosts({ context: "k...", tag: "main-category" });Query post's comments
const { data, error } = await orbis.getPosts({ master: "k..." });Query posts from a user
const { data, error } = await orbis.getPosts({ did: "did:pkh:..." });Query master posts from a specified context
This query will fetch master (top-level, non comment/replies) posts from a given context.
const { data, error } = await orbis.getPosts({
algorithm: "all-context-master-posts",
context: "k..."
});