[{"data":1,"prerenderedAt":7},["ShallowReactive",2],{"docs-chats\u002Fmanagement\u002Fauto-delete":3,"docs-tabs-chats\u002Fmanagement\u002Fauto-delete":6},{"content":4,"lastmod":5},"## Configure message auto-delete\n\n`PUT \u002Fv1\u002Fchats\u002F:dialogId\u002Fauto-delete`\n\nTurns on auto-delete of chat messages with the chosen delay, or turns it off. The delay is set in hours from a fixed set.\n\n## Parameters\n\n| Parameter | Type | Required | Description |\n|----------|-----|:-----:|---------|\n| `dialogId` (path) | string | yes | Dialog ID: `chatXXX` for a group chat, a numeric user ID for private messages, `me` — the current user's personal dialog. To find a CRM entity chat, use [Find a CRM entity chat](\u002Fdocs\u002Fchats\u002Fdiscovery\u002Ffind) |\n\nThe endpoint takes no query parameters: any parameter in the query string is refused with `400 INVALID_PARAMS`.\n\n## Request fields (body)\n\n| Field | Type | Required | Description |\n|------|-----|:-----:|---------|\n| `hours` | number | yes | The delay in hours, as a JSON number: `1` — an hour, `24` — a day, `168` — a week, `720` — 30 days. `0` turns auto-delete off. Other values and the string `\"24\"` are refused |\n\nOther body fields are refused with `400 INVALID_PARAMS`, and the message names the extra field.\n\n## Examples\n\n### curl — personal key\n\n```bash\ncurl -X PUT https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fchat2741\u002Fauto-delete \\\n  -H \"X-Api-Key: YOUR_API_KEY\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\"hours\": 168}'\n```\n\n### curl — OAuth application\n\n```bash\ncurl -X PUT https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fchat2741\u002Fauto-delete \\\n  -H \"X-Api-Key: YOUR_APP_KEY\" \\\n  -H \"Authorization: Bearer USER_SESSION_TOKEN\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\"hours\": 168}'\n```\n\n### JavaScript — personal key\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fchat2741\u002Fauto-delete', {\n  method: 'PUT',\n  headers: {\n    'X-Api-Key': 'YOUR_API_KEY',\n    'Content-Type': 'application\u002Fjson',\n  },\n  body: JSON.stringify({ hours: 168 }),\n})\n\nconst { data } = await res.json()\nconsole.log('Delay:', data.messagesAutoDeleteConfigs[0].delay)\n```\n\n### JavaScript — OAuth application\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fchat2741\u002Fauto-delete', {\n  method: 'PUT',\n  headers: {\n    'X-Api-Key': 'YOUR_APP_KEY',\n    'Authorization': 'Bearer USER_SESSION_TOKEN',\n    'Content-Type': 'application\u002Fjson',\n  },\n  body: JSON.stringify({ hours: 168 }),\n})\n\nconst { data } = await res.json()\nconsole.log('Delay:', data.messagesAutoDeleteConfigs[0].delay)\n```\n\n## Response fields\n\n| Field | Type | Description |\n|------|-----|---------|\n| `success` | boolean | Always `true` on success |\n| `data.messagesAutoDeleteConfigs` | array | The chat's auto-delete setting, a single item |\n| `data.messagesAutoDeleteConfigs[].chatId` | number | Numeric chat ID |\n| `data.messagesAutoDeleteConfigs[].delay` | number | The delay in hours that Bitrix24 saved. `0` — auto-delete is off |\n\n## Response example\n\n```json\n{\n  \"success\": true,\n  \"data\": {\n    \"messagesAutoDeleteConfigs\": [\n      {\n        \"delay\": 168,\n        \"chatId\": 264427\n      }\n    ]\n  }\n}\n```\n\n## Error response example\n\n400 — the delay is not in the allowed set:\n\n```json\n{\n  \"success\": false,\n  \"error\": {\n    \"code\": \"INVALID_PARAMS\",\n    \"message\": \"Body field `hours` must be one of 0, 1, 24, 168, 720 (a JSON number; 0 switches auto-delete off).\"\n  }\n}\n```\n\n## Errors\n\n| HTTP | Code | Description |\n|------|-----|---------|\n| 400 | `INVALID_PARAMS` | `hours` is missing from the body, is not a JSON number, or is not one of `0`, `1`, `24`, `168`, `720`. Also returned when the body has another field, the body is not a JSON object, or the query string has a parameter. Checked before the Bitrix24 call |\n| 403 | `BITRIX_ACCESS_DENIED` | Bitrix24 refused: the user is not a chat member or has no permission to change auto-delete |\n| 422 | `BITRIX_ERROR` | Bitrix24 returned an error; the portal code is in `error.b24Code`. If the chat does not exist, the code is `CHAT_NOT_FOUND` |\n| 403 | `SCOPE_DENIED` | The API key lacks the `im` scope |\n| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is read-only — setting auto-delete counts as a write |\n| 401 | `TOKEN_MISSING` | The API key has no configured Bitrix24 tokens |\n| 502 | `ME_ALIAS_RESOLUTION_FAILED` | `dialogId=me` — the current user's ID could not be resolved |\n| 502 | `BITRIX_UNAVAILABLE` | Bitrix24 is unavailable or returned a server error |\n\nFull list of common API errors — [Errors](\u002Fdocs\u002Ferrors).\n\n## Known specifics\n\n**Check the delay in the response.** The `delay` field in the response is the value Bitrix24 saved, not an echo of the request. If it differs from `hours` in the request, auto-delete is not set the way you asked.\n\n**A system message about turning auto-delete on.** Turning auto-delete on posts a system message to the chat naming the user on whose behalf the call is made.\n\n## See also\n\n- [Change a chat description](\u002Fdocs\u002Fchats\u002Fmanagement\u002Fdescription)\n- [Dialog details](\u002Fdocs\u002Fchats\u002Fdiscovery\u002Fget)\n","2026-10-05",{},1794739538617]