> ## Documentation Index
> Fetch the complete documentation index at: https://docs.opigno.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Get community posts

Opigno Enterprise API provides an endpoint to get the list of all posts related to the given community.

<Note>
  Posts related to the public communities can be viewed even bu the users who are not a community member.

  Posts related to the private communities are accessible only for the users associated with the given community
  (the owner or a member).
</Note>

To get this data, `getCommunityPosts` query should be called. Results will be returned with pagination,
but without possibility to change the order (the newest posts will always be returned first).
Also, it is possible to change the sort key. By default, posts will be sorted by the following rule:
the pinned ones first (both - pinned for community and individually pinned), then descending by the creation time.

The following arguments can be used in the query:

| Argument      | Type          | Description                                                                                                                              | Default  |
| :------------ | :------------ | :--------------------------------------------------------------------------------------------------------------------------------------- | :------- |
| `communityId` | `ID`          | **Required**. ID of the community to get the posts feed for.                                                                             | —        |
| `after`       | `Cursor`      | Returns results that come after the specified cursor. Should be used together with `first` parameter. Cannot be used if `before` is set. | —        |
| `before`      | `Cursor`      | Returns results that come before the specified cursor. Should be used together with `last` parameter. Cannot be used if `after` is set.  | —        |
| `first`       | `Integer`     | Returns up to the first N elements from the list. Required if `after` parameter is set. Cannot be used together with `last`.             | —        |
| `last`        | `Integer`     | Returns up to the first N elements from the list. Required if `before` parameter is set. Cannot be used together with `first`.           | —        |
| `sortKey`     | `PostSortKey` | Sort the underlying list by the given key. Available options: `PINNED` and `CREATED`.                                                    | `PINNED` |

<CodeGroup>
  ```filename GraphQL theme={null}
    query getCommunityPosts {
      getCommunityPosts(communityId: 1, first: 2) {
        edges {
          node {
            id
            text
            created
            commentsNumber
            isLiked
            likesNumber
            authorUserContext {
              id
              uuid
            }
            sharedContent {
              id
              type
              title
              description
              earnedOn
              image {
                alt
                title
                url
              }
            }
            cta {
              actionId
              title
              arguments {
                key
                value
              }
            }
          }
        }
        pageInfo {
          hasNextPage
          hasPreviousPage
          endCursor
        },
        totalItems
      }
    }
  ```

  ```File Query result [expandable] theme={null}
    {
      "data": {
        "getCommunityPosts": {
          "edges": [
            {
              "node": {
                "id": "174",
                "text": "<p>A post with the shared training</p>\n",
                "created": 1751639612,
                "commentsNumber": 0,
                "isLiked": false,
                "likesNumber": 0,
                "authorUserContext": {
                  "id": "915",
                  "uuid": "5acfc440-88e0-4286-b089-c0f03575ed91"
                },
                "sharedContent": {
                  "id": "69",
                  "type": "LEARNING_PATH",
                  "title": "How far would you go for a Nespresso coffee?",
                  "description": "<p>How far would you go for the Unforgettable Taste of a Nespresso coffee? Nespresso reunites George Clooney and Jean Dujardin on screen in new action-comedy commercial.</p>",
                  "earnedOn": null,
                  "image": {
                    "alt": null,
                    "title": "Nespresso - Quiz.jpg",
                    "url": "http://opigno4-project.docksal.site:8080/sites/default/files/2025-02/Nespresso%20-%20Quiz.jpg"
                  }
                },
                "cta": [
                  {
                    "actionId": "COMMENT_POST",
                    "title": "Comment",
                    "arguments": [
                      {
                        "key": "postId",
                        "value": "174"
                      }
                    ]
                  },
                  {
                    "actionId": "PIN_POST",
                    "title": "Pin the post to the top",
                    "arguments": [
                      {
                        "key": "postId",
                        "value": "174"
                      }
                    ]
                  },
                  {
                    "actionId": "EDIT_POST",
                    "title": "Edit the post",
                    "arguments": [
                      {
                        "key": "postId",
                        "value": "174"
                      }
                    ]
                  },
                  {
                    "actionId": "DELETE_POST",
                    "title": "Delete the post",
                    "arguments": [
                      {
                        "key": "postId",
                        "value": "174"
                      }
                    ]
                  },
                  {
                    "actionId": "TOGGLE_LIKE",
                    "title": "Toggle like",
                    "arguments": [
                      {
                        "key": "postId",
                        "value": "174"
                      }
                    ]
                  }
                ]
              }
            },
            {
              "node": {
                "id": "170",
                "text": "<p>Default post from the other user. Without shared content.</p>\n",
                "created": 1751466657,
                "commentsNumber": 0,
                "isLiked": false,
                "likesNumber": 0,
                "authorUserContext": {
                  "id": "3302",
                  "uuid": "fddab9cc-9379-4e39-b058-5709f0915ac1"
                },
                "sharedContent": null,
                "cta": [
                  {
                    "actionId": "COMMENT_POST",
                    "title": "Comment",
                    "arguments": [
                      {
                        "key": "postId",
                        "value": "170"
                      }
                    ]
                  },
                  {
                    "actionId": "PIN_POST",
                    "title": "Pin the post to the top",
                    "arguments": [
                    {
                      "key": "postId",
                      "value": "170"
                    }
                    ]
                  },
                  {
                    "actionId": "DELETE_POST",
                    "title": "Delete the post",
                    "arguments": [
                      {
                        "key": "postId",
                        "value": "170"
                      }
                    ]
                  },
                  {
                    "actionId": "HIDE_POST",
                    "title": "Hide",
                    "arguments": [
                      {
                        "key": "postId",
                        "value": "170"
                      }
                    ]
                  },
                  {
                    "actionId": "TOGGLE_LIKE",
                    "title": "Toggle like",
                    "arguments": [
                      {
                        "key": "postId",
                        "value": "170"
                      }
                    ]
                  },
                  {
                    "actionId": "REMOVE_CONNECTION",
                    "title": "Remove from connections",
                    "arguments": [
                      {
                        "key": "userContextUuid",
                        "value": "fddab9cc-9379-4e39-b058-5709f0915ac1"
                      }
                    ]
                  }
                ]
              }
            }
          ],
          "pageInfo": {
            "hasNextPage": true,
            "hasPreviousPage": false,
            "endCursor": "TzozMzoiRHJ1cGFsXG9waWdub19hcGlcV3JhcHBlcnNcQ3Vyc29yIjo0OntzOjE0OiIAKgBiYWNraW5nVHlwZSI7czoxMToib3BpZ25vX3Bvc3QiO3M6MTI6IgAqAGJhY2tpbmdJZCI7aToxNzA7czoxMDoiACoAc29ydEtleSI7czo3OiJjcmVhdGVkIjtzOjEyOiIAKgBzb3J0VmFsdWUiO2k6MTc1MTQ2NjY1Nzt9"
          },
          "totalItems": 12
        }
      }
    }
  ```
</CodeGroup>

The query returns the list of the `Post` objects. Detailed description and the full list of available properties can be found [here](/OpignoEnterpriseAPI/Post/GetPost).

<Note>
  To get the community posts comments, the same [`getPostComments`](/OpignoEnterpriseAPI/Post/GetPostComments) query should be executed as for any other type of posts.
</Note>
