> ## 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 associated communities

Opigno Enterprise API provides an endpoint to get all communities associated with the current API user (created by or joined).

To retrieve this data, `getCommunities` query should be called. Results will be returned with the pagination and possibility
to change the order (default sorting is by the title, ascending).

The following arguments can be used in the query:

| Argument    | Type                 | Description                                                                                                                                                                                                                                           | Default |
| :---------- | :------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------ |
| `queryType` | `CommunityQueryType` | Allows to filter the query results to get only communities that are managed or joined by the current API user. Leave empty to get all communities associated with the current API user. Available options can be found [here](#community-query-types) | —       |
| `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`.                                                                                                                        | —       |
| `reverse`   | `Boolean`            | Allows to reverse the order of the underlying list (default order is ascending).                                                                                                                                                                      | `false` |
| `sortKey`   | `CommunitySortKey`   | Sort the underlying list by the given key. By default communities will be sorted by the title. Available options can be found [here](#community-sort-keys).                                                                                           | `TITLE` |
| `title`     | `String`             | Allows to search by the community title.                                                                                                                                                                                                              | —       |

## Community query types

* `MANAGED` - allows to filter the query results to return only communities created by the current API user.
* `JOINED` - allows to filter the query results to return only communities the current API user is a member of.

## Community sort keys

Community queries can be sorted with the following keys:

* `TITLE` - allows sorting by the community title. This is the default sort key for the most of the community queries.
* `CREATED` - sorting by the community creation date.
* `LAST_POST` - sorting by the time of the latest related post creation.

<CodeGroup>
  ```filename GraphQL theme={null}
    query getCommunities {
      getCommunities(first: 2) {
        edges {
          node {
            id
            title
            visibility
            description
            cta {
              actionId
              arguments {
                key
                value
              }
            }
            ownerUserContext {
              displayName
              id
              uuid
            }
          }
        }
      }
    }
  ```

  ```File Query result [expandable] theme={null}
  {
    "data": {
      "getCommunities": {
        "edges": [
          {
            "node": {
              "id": "2",
              "title": "The updated community title",
              "visibility": "PRIVATE",
              "description": "<p>The updated community description.</p>\n",
              "cta": [
                {
                  "actionId": "EDIT_COMMUNITY",
                  "arguments": [
                    {
                      "key": "communityId",
                      "value": "2"
                    }
                  ]
                },
                {
                  "actionId": "VIEW_MEMBERS",
                  "arguments": [
                    {
                      "key": "communityId",
                      "value": "2"
                    }
                  ]
                },
                {
                  "actionId": "VIEW_SENT_INVITATIONS",
                  "arguments": [
                    {
                      "key": "communityId",
                      "value": "2"
                    }
                  ]
                },
                {
                  "actionId": "DELETE_COMMUNITY",
                  "arguments": [
                    {
                      "key": "communityId",
                      "value": "2"
                    }
                  ]
                },
                {
                  "actionId": "INVITE_TO_COMMUNITY",
                  "arguments": [
                    {
                      "key": "communityId",
                      "value": "2"
                    }
                  ]
                },
                {
                  "actionId": "CREATE_POST",
                  "arguments": [
                    {
                      "key": "communityId",
                      "value": "2"
                    }
                  ]
                }
              ],
              "ownerUserContext": {
                "displayName": "John Doe",
                "id": "1",
                "uuid": "b004e1a8-ec3d-40ec-bf05-8b54a98873a1"
              }
            }
          }
        ]
      }
    }
  }
  ```
</CodeGroup>

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