# Connect

Connect a LINE Official Account with its Channel ID and Channel secret, then switch on its webhook.

import { Tab, Tabs } from 'fumadocs-ui/components/tabs';

A LINE account connects with the credentials of its Messaging API channel. Zernio issues the access token and sets the webhook URL; two settings stay on the LINE side.

## Before you start

1. Create a LINE Official Account in [LINE Official Account Manager](https://manager.line.biz/) if you do not have one.
2. In its Settings > Messaging API, enable the Messaging API and pick a provider.
3. The same Settings > Messaging API page now shows the **Channel ID** and the **Channel secret**. The [LINE Developers Console](https://developers.line.biz/console/) shows them too, under the channel's Basic settings.

## Connect the channel

Call `POST /v1/connect/line/credentials` with both values and a `state` of `{userId}-{profileId}`.

<Tabs items={['Node.js', 'Python', 'curl']}>
<Tab value="Node.js">
```typescript
import Zernio from '@zernio/node';

const zernio = new Zernio();

const { data } = await zernio.connect.connectLineCredentials({
  body: {
    channelId: '2001234567',
    channelSecret: '0123456789abcdef0123456789abcdef',
    state: '6507a1b2c3d4e5f6a7b8c9d0-6507a1b2c3d4e5f6a7b8c9d1',
  },
});

console.log(data.account, data.webhook, data.nextSteps);
```
</Tab>
<Tab value="Python">
```python
from zernio import Zernio

client = Zernio()

result = client.connect.connect_line_credentials(
    channel_id="2001234567",
    channel_secret="0123456789abcdef0123456789abcdef",
    state="6507a1b2c3d4e5f6a7b8c9d0-6507a1b2c3d4e5f6a7b8c9d1",
)

print(result["account"], result["webhook"], result["nextSteps"])
```
</Tab>
<Tab value="curl">
```bash
curl -X POST "https://zernio.com/api/v1/connect/line/credentials" \
  -H "Authorization: Bearer $ZERNIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "channelId": "2001234567",
    "channelSecret": "0123456789abcdef0123456789abcdef",
    "state": "6507a1b2c3d4e5f6a7b8c9d0-6507a1b2c3d4e5f6a7b8c9d1"
  }'
```
</Tab>
</Tabs>

Response (`200`):

```json
{
  "message": "LINE Official Account connected. Turn on webhooks and turn off auto-responses in LINE Official Account Manager to start receiving messages.",
  "account": {
    "accountId": "6507a1b2c3d4e5f6a7b8c9e0",
    "platform": "line",
    "username": "@123abcde",
    "displayName": "Acme Store",
    "isActive": true
  },
  "webhook": {
    "url": "https://zernio.com/api/webhook/line/6507a1b2c3d4e5f6a7b8c9e0",
    "configured": true,
    "testSucceeded": true
  },
  "nextSteps": [
    "In LINE Official Account Manager, open Settings > Response settings and turn on Webhooks.",
    "In the same screen, turn off Auto-response messages and Greeting messages so they do not answer before you do."
  ]
}
```

`webhook.configured` is `false` when LINE refused the webhook URL. Paste `webhook.url` into the LINE Developers Console > Messaging API > Webhook URL yourself, and turn on Use webhook there.

A channel has one webhook URL. If it pointed at another tool before you connected, `webhook.previousUrl` names that URL: it stopped receiving events once Zernio set its own, and `nextSteps` opens with the same warning.

## Switch on the webhook

In [LINE Official Account Manager](https://manager.line.biz/), open the account, then Settings > Response settings:

1. Turn on **Webhooks**. Until it is on, LINE delivers no messages to Zernio.
2. Turn off **Auto-response messages** and **Greeting messages**, so LINE's own replies do not answer before yours.

## How it behaves

- Reconnecting the same channel on the same profile updates the existing account instead of adding a second one.
- Zernio stores the Channel secret encrypted.
- Changing the webhook URL in the LINE Developers Console stops messages reaching Zernio. Connect again to set it back.

## If it fails

| Error | Cause | Fix |
|-------|-------|-----|
| `400` on connect | The Channel ID or Channel secret is wrong | Copy both again from the channel's Basic settings tab. |
| `403` on connect | The connect token was issued for another profile | Use a `state` for the profile you are connecting to. |
| Connected, but no messages arrive | Webhooks is off | Turn it on in Settings > Response settings. |

## Related

- [Connect LINE](/connect/connect-line-credentials) - Request and response fields
- [Connecting accounts](/guides/connecting-accounts) - Where `state` comes from