> ## 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.

# Respond to the battle

Unlike the initiator's attempt, which is created automatically when the battle is initiated,
the opponent's attempt should be created by executing the `createBattleAttempt` mutation.
The mutation has one required argument - `battleId`.

Here is an example of the mutation execution:

<CodeGroup>
  ```filename GraphQL Battle attempt mutation theme={null}
  mutation createBattleAttempt {
    createBattleAttempt(battleId: 1) {
      errors
      response {
        id
        cta {
          actionId
          title
          arguments {
            key
            value
          }
        }
      }
    }
  }
  ```

  ```File Battle attempt mutation result [expandable] theme={null}
  {
    "data": {
      "errors": {
        "errors": [],
        "response": {
          "id": "2",
          "cta": [
            {
              "actionId": "NEXT_BATTLE_QUESTION",
              "title": "Next question",
              "arguments": [
                {
                  "key": "battleId",
                  "value": "1"
                }
              ]
            }
          ]
        }
      }
    }
  }
  ```
</CodeGroup>

After the mutation is successfully executed, a `BattleAttempt` object will be returned.

## `BattleAttempt` object

The object represents a battle attempt data. Each opponent can have only one attempt, a battle cannot be restarted.

| Argument               | Type                   | Description                                                                                                                                                                                          |
| :--------------------- | :--------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `answers`              | `BattleQuestionAnswer` | **Optional**. The list of user's answers for the battle questions. Answers will be returned only for the attempt created by the current API user; it's impossible to check the other user's answers. |
| `battleStatus`         | `BattleStatus`         | **Required**. The battle attempt status. See the full list of available statuses [below](#battlestatus-options).                                                                                     |
| `completedOn`          | `Int`                  | **Optional**. A timestamp when the attempt has been completed.                                                                                                                                       |
| `correctAnswersNumber` | `Int`                  | **Required**. The general number of correct answers provided by the user in the current battle attempt.                                                                                              |
| `cta`                  | `Cta`                  | **Optional**. The list of available CTA for the battle attempt. See the list of available CTAs [below](#battle-attempt-ctas).                                                                        |
| `id`                   | `ID`                   | **Required**. The battle attempt ID.                                                                                                                                                                 |
| `progress`             | `Int`                  | **Required**. The attempt progress. Indicates the percentage of questions that have been answered so far.                                                                                            |
| `score`                | `Float`                | **Required**. The total number of points that the rival has earned earned for the battle.                                                                                                            |
| `timeSpent`            | `Int`                  | **Required**. The time (in seconds) that the user spent answering the related battle questions.                                                                                                      |

### `BattleStatus` options

The list of available `BattleStatus` options:

1. `COMPLETED` - indicates that the battle has been completed by the current API user; also includes the battles that are not completed by the opponent yet.
2. `DRAW` - indicates a tie, meaning that both opponents have earned the same score and spent the same amount of time;
3. `FINISHED` - indicates that ths battle has been finished by both rivals.
4. `IN_PROGRESS` - indicates that the battle have been started, but not completed by the user yet;
5. `PENDING` - indicates that the battle has not been started by the user yet;
6. `LOST` - indicates that the user has lost the battle;
7. `WAITING_OPPONENT` - indicates that the battle is finished by the initiator, but not completed by the opponent yet.
8. `WON` - indicates that the user has won the battle.

### Battle attempt CTAs

The list of available CTAs can differ depending on the attempt status.

| Action ID              | Description                                                                            | Corresponding mutation/query                                                        |
| :--------------------- | :------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------- |
| `NEXT_BATTLE_QUESTION` | Allows to get the next battle question. Available if the attempt is still in progress. | [`getBattleNextQuestion`](/OpignoEnterpriseAPI/Battle/TakeBattle#get-next-question) |
| `VIEW_BATTLE_RESULTS`  | Allows to view the battle results. Available when the battle attempt is completed.     | [`getBattle`](/OpignoEnterpriseAPI/Battle/GetBattle)                                |
