
## Create a payment

`POST /v1/payments`

Registers a new payment for an existing order. The request body is flat — no `fields` wrapper.

## Request fields (body)

| Parameter | Type | Req. | Description |
|----------|-----|:-----:|---------|
| `orderId` | number | yes | Order identifier. Source: [`GET /v1/orders`](../orders/list.md) |
| `paySystemId` | number | yes | Payment system identifier. Each Bitrix24 account has its own set of systems. You can find the ID from existing payments via [`GET /v1/payments`](./list.md) or [`POST /v1/payments/aggregate`](./aggregate.md) with `groupBy: "paySystemId"` |
| `sum` | number | no | Payment amount. If omitted, Bitrix24 takes the remaining balance of the order total |
| `currency` | string | no | Payment currency. Defaults to the order currency. List: [`GET /v1/currencies`](/docs/entities/currencies) |
| `paid` | boolean | no | Whether the payment is marked as received. Defaults to `false` |
| `datePaid` | datetime | no | Payment marking date (in ISO 8601 format) |
| `dateBill` | datetime | no | Invoice issue date |
| `datePayBefore` | datetime | no | Payment due date. In responses only the date is returned — the time is always midnight in the Bitrix24 account timezone |
| `responsibleId` | number | no | Responsible employee. Source: [`GET /v1/users`](/docs/entities/users) |
| `comments` | string | no | Payment comment |
| `xmlId` | string | no | External identifier (for example, the payment gateway's transaction ID) |

## Examples

### curl — personal key

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/payments" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "orderId": 19,
    "paySystemId": 11,
    "sum": 1500,
    "currency": "USD",
    "paid": true,
    "comments": "Payment via payment gateway",
    "xmlId": "txn_abc123"
  }'
```

### curl — OAuth application

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/payments" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "orderId": 19,
    "paySystemId": 11,
    "sum": 1500,
    "currency": "USD",
    "paid": true,
    "comments": "Payment via payment gateway",
    "xmlId": "txn_abc123"
  }'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/payments', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    orderId: 19,
    paySystemId: 11,
    sum: 1500,
    currency: 'USD',
    paid: true,
    comments: 'Payment via payment gateway',
    xmlId: 'txn_abc123',
  }),
})

const { success, data } = await res.json()
console.log('Payment ID:', data.id)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/payments', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    orderId: 19,
    paySystemId: 11,
    sum: 1500,
    currency: 'USD',
    paid: true,
    comments: 'Payment via payment gateway',
    xmlId: 'txn_abc123',
  }),
})

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

## Response fields

Returns the full object of the created payment.

| Field | Type | Description |
|------|-----|---------|
| `id` | number | Identifier of the created payment |
| `accountNumber` | string | Sequential payment number within the Bitrix24 account (generated automatically) |
| `paySystemName` | string | Payment system name (filled from the payment system card) |

The remaining fields match those passed in the request, plus `datePaid` / `dateBill` may be set automatically.

## Response example

```json
{
  "success": true,
  "data": {
    "id": 217,
    "accountNumber": "98/2",
    "orderId": 19,
    "paySystemId": 11,
    "paySystemName": "Cash",
    "sum": 1500,
    "currency": "USD",
    "paid": true,
    "datePaid": "2026-05-13T11:50:24.000Z",
    "dateBill": "2026-05-13T11:50:24.000Z",
    "responsibleId": 1,
    "comments": "Payment via payment gateway",
    "xmlId": "txn_abc123",
    "isReturn": "N",
    "marked": false
  }
}
```

## Error response example

422 — required fields are missing:

```json
{
  "success": false,
  "error": {
    "code": "BITRIX_ERROR",
    "message": "Required fields: orderId, paySystemId"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 422 | `BITRIX_ERROR` | Required fields are missing — the message contains their list (`Required fields: orderId, paySystemId`) |
| 422 | `BITRIX_ERROR` | Non-existent `orderId` or `paySystemId` |
| 403 | `SCOPE_DENIED` | The API key does not have the `sale` scope |
| 401 | `TOKEN_MISSING` | The API key has no configured tokens |

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

## Known specifics

**The payment number is generated automatically.** The `accountNumber` field is assigned by Bitrix24 on creation in the format `<orderAccount>/<seq>` (for example, `19/1`) and cannot be passed in the request.

**Several payments per order.** A single order can have several payments — for example, a partial prepayment and a balance payment on delivery. Each is registered with a separate `POST /v1/payments` using the same `orderId` and different `paySystemId` or `sum`.

**The order status is not updated automatically.** After a payment is registered, the order status (`orders.payed`, `orders.statusId`) stays the same — update it with a separate [`PATCH /v1/orders/:id`](../orders/update.md) call.

## See also

- [Payment fields](./fields.md)
- [List payments](./list.md)
- [Get a payment](./get.md)
- [Update a payment](./update.md)
- [Update an order](../orders/update.md)
- [Batch](/docs/batch)
- [Limits and optimization](/docs/optimization)
