## Move an item before another

`POST /v1/tasks/:taskId/checklist/:itemId/move-before`

Moves a task checklist item and places it before another item.

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|----------|
| `taskId` (path) | number | yes | Task ID, a positive integer. List: [`GET /v1/tasks`](/docs/entities/tasks/list) |
| `itemId` (path) | number | yes | ID of the item being moved, a positive integer. List: [`GET /v1/tasks/:taskId/checklist`](/docs/entities/tasks/checklist/list) |

## Request fields (body)

| Field | Type | Required | Description |
|------|-----|:-----:|----------|
| `beforeItemId` | number | yes | ID of the item that the `itemId` item will be placed before, a positive integer. List: [`GET /v1/tasks/:taskId/checklist`](/docs/entities/tasks/checklist/list) — it returns the ID as a string, such as `"276"`, while this field needs a number |

## Examples

### curl — personal key

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/tasks/4218/checklist/274/move-before" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"beforeItemId": 276}'
```

### curl — OAuth application

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/tasks/4218/checklist/274/move-before" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"beforeItemId": 276}'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/tasks/4218/checklist/274/move-before', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ beforeItemId: 276 }),
})

const { success, data } = await res.json()
console.log('New item position:', data?.checkListItem?.sortIndex)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/tasks/4218/checklist/274/move-before', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ beforeItemId: 276 }),
})

const { success, data } = await res.json()
```

## Response fields

| Field | Type | Description |
|------|-----|----------|
| `success` | boolean | `true` if the request succeeded |
| `data` | object | Result with a single field, `checkListItem` |
| `data.checkListItem` | object | The moved item |
| `data.checkListItem.id` | number | Item ID |
| `data.checkListItem.taskId` | number | Task ID |
| `data.checkListItem.parentId` | number | Parent item ID. `0` means a top-level item, which is also the checklist name |
| `data.checkListItem.title` | string | Item text |
| `data.checkListItem.sortIndex` | number | New position of the item among items with the same parent. The smaller the value, the higher the item |
| `data.checkListItem.displaySortIndex` | string | Display number of the item. An empty string in the response |
| `data.checkListItem.isComplete` | boolean | Whether the item is complete |
| `data.checkListItem.isImportant` | boolean | Whether the item is marked important |
| `data.checkListItem.completedCount` | number | Arrives as `0` even when sub-items are complete. To check whether a sub-item is complete, use its `isComplete` in the [item list](/docs/entities/tasks/checklist/list) |
| `data.checkListItem.members` | array | Item members. An empty array if there are none. For member roles, see [Key fields](/docs/entities/tasks/checklist-actions#key-fields) |
| `data.checkListItem.attachments` | array \| object | Item attachments. An empty array if there are none. For the object format, see [Key fields](/docs/entities/tasks/checklist-actions#key-fields) |
| `data.checkListItem.createdBy` | number | Item author ID. List: [`GET /v1/users`](/docs/entities/users/list) |
| `data.checkListItem.userId` | number | ID of the employee on whose behalf the call is made. List: [`GET /v1/users`](/docs/entities/users/list) |
| `data.checkListItem.copiedId` | number \| null | ID of the source item if the item was created by copying. Otherwise `null` |
| `data.checkListItem.nodeId` | string \| null | Internal node key. `null` in the response |

## Response example

```json
{
  "success": true,
  "data": {
    "checkListItem": {
      "id": 274,
      "copiedId": null,
      "userId": 1295,
      "createdBy": 1295,
      "parentId": 268,
      "title": "Agree on the date",
      "sortIndex": 0,
      "displaySortIndex": "",
      "isComplete": false,
      "isImportant": false,
      "completedCount": 0,
      "members": [],
      "attachments": [],
      "nodeId": null,
      "taskId": 4218
    }
  }
}
```

## Error response example

422 — no item with the ID from `beforeItemId`:

```json
{
  "success": false,
  "error": {
    "code": "BITRIX_ERROR",
    "message": "Move item: action unavailable",
    "b24Code": "0"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|----------|
| 400 | `INVALID_PARAMS` | `taskId` is not a positive integer. Message `taskId must be a positive integer` |
| 400 | `INVALID_PARAMS` | `itemId` is not a positive integer. Message `itemId must be a positive integer` |
| 400 | `INVALID_PARAMS` | The body is not a JSON object, for example an array. Message `JSON object body is required` |
| 400 | `INVALID_PARAMS` | `beforeItemId` is missing, passed as a string, or is not a positive integer. Message `beforeItemId must be a positive integer` |
| 401 | `MISSING_API_KEY` | `X-Api-Key` is not passed |
| 401 | `TOKEN_MISSING` | The key has no Bitrix24 tokens |
| 403 | `SCOPE_DENIED` | The key lacks the `task` scope |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is in read-only mode. `error.details.switchUrl` contains the URL of the section where the mode is changed |
| 415 | `FST_ERR_CTP_INVALID_MEDIA_TYPE` | A body with a `Content-Type` the API does not parse, such as `application/xml` |
| 422 | `BITRIX_ERROR` | The task or the `itemId` item does not exist, or the employee on whose behalf the call is made cannot see the task. The message is in the Bitrix24 account language; on an English-language account it is `Access to task was denied`. The API specification declares `404 TASK_NOT_FOUND` and `404 NOT_FOUND` for this case, but the Bitrix24 accounts we tested return this response instead |
| 422 | `BITRIX_ERROR` | No item with the ID from `beforeItemId`. The message is in the Bitrix24 account language, for example "Move item: action unavailable" |
| 422 | `BITRIX_ERROR` | `beforeItemId` is a sub-item of the item being moved. The message is in the Bitrix24 account language, for example "Parent item cannot be a subitem of itself" |
| 429 | `RATE_LIMITED` | Request rate exceeded. The effective cap is in the `x-ratelimit-limit` header |

Full list of common API errors — [Errors](/docs/errors).

## Known specifics

**The target item's number changes too.** The moved item takes the `sortIndex` number of the `beforeItemId` item, and the number of the `beforeItemId` item increases by one. The response shows only the moved item; the new order of the other items is returned by [`GET /v1/tasks/:taskId/checklist`](/docs/entities/tasks/checklist/list).

## See also

- [Checklist actions and task file](/docs/entities/tasks/checklist-actions)
- [Move an item after another](/docs/entities/tasks/checklist-actions/move-after)
- [Save a task checklist](/docs/entities/tasks/checklist-actions/tree)
- [Mark an item complete with its sub-items](/docs/entities/tasks/checklist-actions/complete-all)
- [Update a checklist item](/docs/entities/tasks/checklist/update)
- [List checklist items](/docs/entities/tasks/checklist/list)
- [Task checklist](/docs/entities/tasks/checklist)
