## Get card layout

`GET /v1/crm/card-config/:entityTypeId`

Returns the current layout of card sections and fields for the given CRM object type and scope. The response contains an array of sections, or `null` if no explicit configuration exists yet.

## Path parameter

| Parameter | Type | Description |
|----------|-----|---------|
| `entityTypeId` | number | CRM object type:<br>`1` — lead<br>`2` — deal<br>`3` — contact<br>`4` — company<br>`7` — quote<br>`31` — invoice<br>smart process — numeric type ID from [`GET /v1/smart-processes`](/docs/entities/smart-processes), field `entityTypeId` |

## Query parameters

| Parameter | Type | Description |
|----------|-----|---------|
| `scope` | string | Layout scope: `P` — personal (default), `C` — common |
| `userId` | number | Employee whose personal layout to read. Defaults to the API key owner. Only meaningful with `scope=P`. Source: [`GET /v1/users`](/docs/entities/users) |
| `dealCategoryId` | number | Deal pipeline, deals only (`entityTypeId=2`). Source: [`GET /v1/categories/2`](/docs/entities/categories) |
| `categoryId` | number | Smart process pipeline, smart processes only. Source: [`GET /v1/categories/:entityTypeId`](/docs/entities/categories) |
| `leadCustomerType` | number | Lead type, leads only (`entityTypeId=1`): `1` — simple, `2` — repeat |

## Examples

### curl — personal key

```bash
curl "https://vibecode.bitrix24.com/v1/crm/card-config/2?scope=C&dealCategoryId=9" \
  -H "X-Api-Key: YOUR_API_KEY"
```

### curl — OAuth application

```bash
curl "https://vibecode.bitrix24.com/v1/crm/card-config/2?scope=C&dealCategoryId=9" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN"
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/crm/card-config/2?scope=C&dealCategoryId=9', {
  headers: { 'X-Api-Key': 'YOUR_API_KEY' },
})

const { success, data } = await res.json()
if (data === null) {
  console.log('No explicit layout — the default layout is used')
} else {
  console.log('Sections in the layout:', data.length)
}
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/crm/card-config/2?scope=C&dealCategoryId=9', {
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
  },
})

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

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | Always `true` on success |
| `data` | array \| null | Array of layout sections. `null` — no explicit configuration exists yet |
| `data[].name` | string | Internal section name |
| `data[].title` | string | Displayed section title |
| `data[].type` | string | Always `section` |
| `data[].elements` | array | Section fields in display order. May be absent for an empty section |
| `data[].elements[].name` | string | CRM field name in Bitrix24 format |
| `data[].elements[].optionFlags` | number \| string | Field flag: `0` — regular, `1` — customer field. Returned in the type it was written with |
| `data[].elements[].options` | object | Field-specific options, if set |

## Response example

Layout set explicitly:

```json
{
  "success": true,
  "data": [
    {
      "name": "main",
      "title": "About the deal",
      "type": "section",
      "elements": [
        { "name": "TITLE", "optionFlags": "0" },
        { "name": "STAGE_ID", "optionFlags": "0" },
        { "name": "OPPORTUNITY_WITH_CURRENCY", "optionFlags": "0" }
      ]
    }
  ]
}
```

No explicit configuration for the scope yet:

```json
{
  "success": true,
  "data": null
}
```

## Error response example

400 — invalid `scope` value:

```json
{
  "success": false,
  "error": {
    "code": "INVALID_SCOPE",
    "message": "scope must be \"P\" (personal) or \"C\" (common)."
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `INVALID_ENTITY_TYPE_ID` | `entityTypeId` in the path is not a positive integer |
| 400 | `INVALID_SCOPE` | `scope` is not `P` or `C` |
| 400 | `INVALID_USER_ID` | `userId` is not a positive integer |
| 400 | `INVALID_DEAL_CATEGORY_ID` | `dealCategoryId` is not a positive integer |
| 400 | `INVALID_CATEGORY_ID` | `categoryId` is not a positive integer |
| 400 | `INVALID_LEAD_CUSTOMER_TYPE` | `leadCustomerType` is not `1` or `2` |
| 422 | `BITRIX_ERROR` | Bitrix24 did not recognize the object type — for example, for a nonexistent `entityTypeId`. The message is in `error.message` |
| 403 | `SCOPE_DENIED` | The API key does not have the `crm` scope |
| 401 | `TOKEN_MISSING` | The API key has no configured tokens |

For the full list of common API errors, see [Errors](/docs/errors).

## Known specifics

**`data: null` differs from an empty layout.** `null` means no explicit configuration exists for the given scope yet, and the card is rendered with the built-in default layout. An empty array `[]` means an explicitly saved empty layout. Handle the `data === null` branch separately in your code.

**`optionFlags` comes back as a number or a string.** The flag is returned in the type it was written with: one sent to [`PUT`](./set.md) as a number comes back as a number, one sent as a string comes back as the string `"0"` or `"1"`. The type depends on how the layout was written, so convert the flag to a number before comparing.

**After a write, the layout reads back in a different shape.** Sections and fields, their order, flag values, and non-empty `options` are preserved, but the response differs from the [`PUT`](./set.md) body: section keys come back in a different order, a section without `type` gains `type: "section"`, an empty section is returned with `elements: []` even if the body omitted `elements`, and an empty `options` object comes back as an empty array `[]`. To confirm that a layout was written, compare the names and order of sections and fields, the flags converted to numbers, and non-empty `options`, rather than the JSON text or its hash.

## See also

- [Set layout](/docs/entities/crm-card-config/set)
- [Reset layout](/docs/entities/crm-card-config/reset)
- [Smart processes](/docs/entities/smart-processes)
- [Pipelines](/docs/entities/categories)
- [User fields](/docs/userfields)
