---
docId: doc_9263a6e63187497ebcb9e52330bd4b49
title: 'Web chat'
description: "Create a chat for your site or a page hosted by Platica."
---

<script>
  import { Ways } from '$lib/components';
</script>

# Web chat

Create a chat for your site or a page hosted by Platica. Creating it publishes it and returns the installation code. Its conversations reach your inbox.

Assign an agent for automatic replies, or receive messages through your [webhooks](/api-reference/webhooks) to integrate them with your product. You can create the chat without an agent.

## Quick example

<Ways tabs="api,sdk">
<Ways.Way name="api">

```bash
# 1. Create the web chat (it is born published)
curl -X POST https://api.platic.ai/v1/webchats \
  -H "Authorization: Bearer $PLATIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "Site support", "agentId": "'"$AGENT_ID"'", "allowedDomains": ["example.com"]}'

# 2. Update the config (it stays as a draft) and publish
curl -X PATCH https://api.platic.ai/v1/webchats/$WEBCHAT_ID \
  -H "Authorization: Bearer $PLATIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"config": {"appearance": {"primary": "#E4572E"}}}'

curl -X POST https://api.platic.ai/v1/webchats/$WEBCHAT_ID/publish \
  -H "Authorization: Bearer $PLATIC_API_KEY"
```

</Ways.Way>
<Ways.Way name="sdk">

```ts
// 1. Create the web chat (it is born published with embed.script and embed.pageUrl)
const webchat = await platic.webchats.create({
  name: 'Site support',
  agentId,
  allowedDomains: ['example.com', '*.example.com']
});
console.log(webchat.embed.script);

// 2. Change appearance/texts (draft) and publish
await platic.webchats.update(webchat.id, {
  config: { appearance: { primary: '#E4572E' }, content: { assistantName: 'Support' } }
});
await platic.webchats.publish(webchat.id);
```

</Ways.Way>
</Ways>

## What you need to know

- **Live vs draft:** `name`, `agentId`, `allowedDomains`, and `mode` apply right away. Changes in `config` are saved as a draft (`hasUnpublishedChanges: true`) until you [publish](/api-reference/web-chats/publish); the script pasted on your site does not change.
- **Allowed domains:** the chat only opens on `allowedDomains` (it accepts subdomains like `*.example.com` and `localhost:5173`). Without domains, it does not load on any site.
- **Turning off and on:** to turn it off instantly use [disconnect the channel](/api-reference/channels/disconnect) (`health: disconnected`); to turn it on again, [publish it](/api-reference/web-chats/publish). To pause it through the draft, send `config.enabled: false` and publish (`health: paused`).
- **Permissions:** requires **Integrations** (write access and `platica:write` with OAuth to create, edit, publish, or delete).

## The configuration

Send only the parts of `config` you want to change:

- Objects merge with the saved values.
- Arrays, such as `prechat.fields` or `suggestedMessages.cards`, are replaced in full.
- `null` clears an optional field.

Its sections are `enabled`, `interactiveResponses`, `attachments`, `launcher`, `window`, `inline`, `appearance`, `content`, `suggestedMessages`, `prechat`, `availability`, and `behavior`. Read the structure and current values with [get a web chat](/api-reference/web-chats/get).

## Endpoints

| Method | Endpoint | What it does |
|--------|----------|--------------|
| `GET` | [`/v1/webchats`](/api-reference/web-chats/list) | List the workspace's web chats |
| `POST` | [`/v1/webchats`](/api-reference/web-chats/create) | Create a web chat (it is born published) |
| `GET` | [`/v1/webchats/{webchatId}`](/api-reference/web-chats/get) | Get the full configuration and the `embed` code |
| `PATCH` | [`/v1/webchats/{webchatId}`](/api-reference/web-chats/update) | Update the data or the `config` as a draft |
| `POST` | [`/v1/webchats/{webchatId}/publish`](/api-reference/web-chats/publish) | Publish the `config` or turn it on if it was off |
| `DELETE` | [`/v1/webchats/{webchatId}`](/api-reference/web-chats/delete) | Delete the web chat for good |

The full guide is in [Put a chat on your site](/guides/web-chat), how to paste it in [Embed it on your site](/api-reference/web-chats/embed), errors in [Errors](/api-reference/errors), and AI tools in [Web chat MCP](/mcp/tools#web-chats).
