SDK Reference
Methods
GetPosts

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 - string Context for which you want to retrieve the posts
    • did - string Retrieving posts shared by a specific user
    • master - string When querying the comments under a parent post
    • only_master - boolean Use true if you want only master posts to be returned
    • tag - string To query only posts shared with a specific tag
    • term - string Will return posts containing the term, which can be used for search
    • include_child_contexts - boolean Will also return posts shared from child contexts when set to true
    • algorithm - string Returns 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 - int Is 0 by default, increment this to retrieve additional posts
  • limit - int Number of posts returned by the query. Default is 50
  • ascending - boolean ordering 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..."
});