> ## 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 user battles

Use query `getBattles` to retrieve the list of all battles related to the user.

In a response it returns a list of [`Battle`](/OpignoEnterpriseAPI/Battle/GetBattle#battle-object) objects
that fit the applied filters.

Results will be returned with the pagination and possibility to change the order and sorting key
(default sorting is by the battle creation date, ascending).

The following arguments can be used in the query:

| Argument          | Type            | Description                                                                                                                                                            | Default   |
| :---------------- | :-------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------- |
| `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`           | `Int`           | Returns up to the first N elements from the list. Required if `after` parameter is set. Cannot be used together with `last`.                                           | —         |
| `last`            | `Int`           | 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`         | `BattleSortKey` | Allows to change the results sorting. Available options: `CREATED` (default), `FINISHED`                                                                               | `CREATED` |
| `status`          | `BattleStatus`  | Provides the possibility to filter by the [battle status](/OpignoEnterpriseAPI/Battle/RespondToBattle#battlestatus-options). Leave empty to get all available battles. | —         |
| `userContextUuid` | `ID`            | The user context UUID to get the list of battles for. If omitted, the results will be retrieved for the current API user context.                                      | —         |

<Note>
  Only user contexts associated with the `ADMINISTRATOR` scope can access the list of other users' battles.
</Note>

Here is an example of the query execution:

<CodeGroup>
  ```filename GraphQL theme={null}
  query getBattles {
    getBattles(first: 10, status: "WON") {
      edges {
        node {
          domain {
            name
          }
          initiatorAttempt {
            score
            timeSpent
          }
          opponentAttempt {
            score
            timeSpent
          }
        }
      }
      totalItems
    }
  }
  ```

  ```File Query result [expandable] theme={null}
  {
    "data": {
      "getBattles": {
        "edges": [
          {
            "node": {
              "domain": {
                "name": "Geography",
              },
              "initiatorAttempt": {
                "score": 15,
                "timeSpent": 46
              }
              "opponentAttempt": {
                "score": 11,
                "timeSpent": 34
              }
            },
            "node": {
              "domain": {
                "name": "History",
              },
              "initiatorAttempt": {
                "score": 18,
                "timeSpent": 50
              }
              "opponentAttempt": {
                "score": 18,
                "timeSpent": 58
              }
            }
          ]
        }
        "totalItems": 2
      }
    }
  }
  ```
</CodeGroup>

## Related Features

<CardGroup cols={2}>
  <Card title="Pagination" icon="arrow-right" href="/OpignoEnterpriseAPI/PaginatingCatalogItems">
    Learn how to efficiently navigate through large sets of items using cursor-based pagination.
  </Card>
</CardGroup>
