# Vote or revote

`POST /v1/polls/:pollId/vote`

Votes or replaces the current user's vote. Before writing, validates active questions: each required question needs an answer; a single-choice question accepts at most one answer.

Legacy text answers (`TEXT`/`TEXTAREA`) cannot be selected through the API: `400 INVALID_ANSWERS`. In a legacy question you cannot select more than one radio answer or more than one dropdown answer, even with `multipleChoice: true`: Bitrix24 would keep only the first, so such a ballot is rejected with `400 INVALID_ANSWERS` before recording.

**Scope:** `vote`. Key restrictions: [Polls](/docs/polls).

## Parameters

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `pollId` (path) | number | yes | — | Positive attachment ID: the `id` field from [poll discovery](/docs/polls/list), rather than `voteId` |

## Request body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `answerIds` | number[] | yes | Non-empty array of unique positive integer IDs of active answers from `questions[].answers[].id` |

When revoting in the Feed, a concurrent poll edit may erase the previous vote in Bitrix24, just as in the interface. Check `myVote` after an error.

The write is attempted once, without automatic replay. After an unknown outcome, read the poll and decide whether another write is needed.

## Examples

### curl — personal key

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/polls/7/vote" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"answerIds": [22]}'
```

### curl — OAuth application

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/polls/7/vote" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"answerIds": [22]}'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/polls/7/vote', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({"answerIds": [22]}),
})
const result = await res.json()
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/polls/7/vote', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({"answerIds": [22]}),
})
const result = await res.json()
```

## Response fields

| Field | Type | Description |
| --- | --- | --- |
| `success` | boolean | `true` on success |
| `data` | object | [Poll object](/docs/polls) |

## Response example

Illustrative response based on the normalizer and test fixtures; not a live Bitrix24 response.

```json
{
  "success": true,
  "data": {
    "id": 7,
    "voteId": 8,
    "status": "active",
    "anonymous": true,
    "allowRevote": true,
    "resultsHidden": true,
    "resultsVisible": true,
    "votersCount": 3,
    "questions": [
      {
        "id": 10,
        "text": "First",
        "multipleChoice": false,
        "required": false,
        "votesCount": 0,
        "answers": [
          {
            "id": 11,
            "text": "One",
            "votesCount": 0,
            "percent": 0
          },
          {
            "id": 12,
            "text": "Two",
            "votesCount": 0,
            "percent": 0
          }
        ]
      },
      {
        "id": 20,
        "text": "Second",
        "multipleChoice": true,
        "required": true,
        "votesCount": 2,
        "answers": [
          {
            "id": 22,
            "text": "A",
            "votesCount": 2,
            "percent": 100
          },
          {
            "id": 23,
            "text": "B",
            "votesCount": 0,
            "percent": 0
          }
        ]
      }
    ],
    "myVote": {
      "voted": true,
      "answerIds": [
        22
      ]
    },
    "permissions": {
      "canVote": false,
      "canRevote": true,
      "canManage": true
    }
  }
}
```

## Errors

| HTTP | Code | Cause and action |
| --- | --- | --- |
| 400 | `INVALID_PARAMS` | Invalid ID or request parameter |
| 401 | `TOKEN_MISSING` | No Bitrix24 user session |
| 403 | `SCOPE_DENIED` | Required scope is missing |
| 403 | `COWORK_READONLY` | Operation forbidden for a Cowork portal-readonly key |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key permits reads only |
| 404 | `POLL_NOT_FOUND` | Poll missing or inaccessible |
| 400 | `INVALID_ANSWERS` | Required answers missing, or extra or inactive answers selected |
| 409 | `POLL_FINISHED` | The poll has finished |
| 403 | `POLL_ACCESS_DENIED` | Bitrix24 denied the operation |
| 422 | `BITRIX_ERROR` | Bitrix24 rejected the request, for example because the method is unavailable in this version |
| 502 | `POLL_VOTE_OUTCOME_UNKNOWN` | Outcome unknown: read the poll first |

Other authentication refusals, limits and shared errors: [error codes](/docs/errors).

```json
{
  "success": false,
  "error": {
    "code": "INVALID_PARAMS",
    "message": "Invalid poll parameters."
  }
}
```
