LINE Messaging API
Do not answer LINE API questions from memory — LINE updates APIs frequently and training data is unreliable. Always consult the references below.
Reference for building, reviewing, and debugging LINE Bots and LINE Messaging API integrations.
Workflow
Build
- Read references/api-common.md (rate limits, forward compatibility, error handling)
- Load the relevant reference for the feature being implemented
- For architecture or design choices, consult references/experts.md for directional guidance
- Write code following specs and constraints from references
Review / Debug
- Read references/api-common.md (rate limits, error codes)
- Load relevant references for the code being reviewed
- Cross-check code against specs (size limits, token expiry, counting rules, required fields)
- For design pattern concerns, consult references/experts.md
- Report violations with reference to specific constraints
Environment Variables
LINE_CHANNEL_ACCESS_TOKEN=Bot access token
LINE_CHANNEL_SECRET=Channel secret (webhook signature verification)
Common Specifications
Read references/api-common.md before writing any LINE bot code. Contains rules that affect all API interactions: forward compatibility (don't use strict schemas — LINE adds fields without notice), rate limits, error handling, retry policy, and logging recommendations.
Webhook
- Verification:
x-line-signature header (HMAC-SHA256, base64, key = Channel Secret)
- Body:
{"destination": "U...", "events": [...]}
- Bot server must return
200
Signature Verification (pseudocode)
channel_secret = ENV['LINE_CHANNEL_SECRET']
signature = request.headers['x-line-signature']
body = request.body # raw bytes, do NOT parse/reformat before verification
digest = HMAC_SHA256(key = channel_secret, message = body)
expected = Base64.encode(digest)
if signature != expected:
return 403 # reject — not from LINE
events = JSON.parse(body)['events']
for event in events:
handle(event)
return 200
- Never deserialize or re-format the body before verification
- Use UTF-8 encoding exclusively
- Official SDKs handle this automatically — use them when possible
Full event types, properties, and webhook settings → references/webhook-events.md
Message Sending
All require Authorization: Bearer {channel access token}:
| Mode |
Endpoint |
Purpose |
| Reply |
POST /v2/bot/message/reply |
Reply to user (requires one-time replyToken) |
| Push |
POST /v2/bot/message/push |
Send to a specific user/group at any time |
| Multicast |
POST /v2/bot/message/multicast |
Send to multiple users (max 500) |
| Broadcast |
POST /v2/bot/message/broadcast |
Send to all friends |
- Max 5 messages per request
- Domain:
api.line.me (general) / api-data.line.me (content upload)
Message objects → references/message-objects.md
Full sending API (Narrowcast, statistics, validation, etc.) → references/message-sending.md
Flex Message
Three-layer structure:
Container (Bubble / Carousel)
└── Block (Header / Hero / Body / Footer)
└── Component (Box / Button / Image / Video / Icon / Text / Span / Separator)
Minimal Flex Message:
{
"type": "flex", "altText": "Notification",
"contents": {
"type": "bubble",
"body": {
"type": "box", "layout": "vertical",
"contents": [{"type": "text", "text": "Hello Flex!", "weight": "bold"}]
}
}
}
Full component specs, layout, video → references/flex-message.md
Official Flex Message Simulator examples → assets/examples/
Reference Index
| File |
Topic |
| references/api-common.md |
Read first. Rate limits, error handling, forward compatibility |
| references/webhook-events.md |
Webhook event types and JSON structure |
| references/message-objects.md |
Message objects, Quick Reply, sender customization |
| references/action-objects.md |
Action objects (postback, URI, datetimepicker, etc.) |
| references/message-sending.md |
Reply/Push/Multicast/Narrowcast/Broadcast, statistics |
| references/flex-message.md |
Flex Message components, layout, styles |
| references/rich-menu.md |
Rich Menu CRUD, tab switching, display priority |
| references/user-profile.md |
User profile, follower IDs, account link |
| references/group-chat.md |
Group/Room messaging and member APIs |
| references/audience.md |
Audience management (create/add/get/delete) |
| references/insights.md |
Delivery, follower, and interaction insights |
| references/channel-token.md |
Channel access token lifecycle |
| references/coupon.md |
Coupon CRUD, reward types, sending |
| references/url-schemes.md |
LINE URL schemes for deep linking |
| references/experts.md |
Expert domain routing and 17 specialist profiles |
| assets/examples/ |
Flex Message JSON examples (11 showcases) |
SDK
Official SDKs: Python | Node.js | Go | Java | PHP | Ruby
Other languages: use LINE OpenAPI specs with OpenAPI Generator.
1---2name: messaging-api3description: Builds, reviews, and debugs LINE Messaging API integrations — webhook signature verification, reply/push/multicast/narrowcast/broadcast, Flex Message design, Rich Menu CRUD, audience targeting, insights, coupons, mark-as-read, and channel access tokens. Use when the user mentions LINE bot, chatbot, LINE OA, Messaging API, webhook, Flex Message, Rich Menu, push/reply/multicast/narrowcast/broadcast, audience, coupon campaign, channel access token, LINE URL scheme, or any LINE messaging integration — even when they don't say "Messaging API".4---56# LINE Messaging API78**Do not answer LINE API questions from memory — LINE updates APIs frequently and training data is unreliable. Always consult the references below.**910Reference for building, reviewing, and debugging LINE Bots and LINE Messaging API integrations.1112## Workflow1314### Build151. Read [references/api-common.md](references/api-common.md) (rate limits, forward compatibility, error handling)162. Load the relevant reference for the feature being implemented173. For architecture or design choices, consult [references/experts.md](references/experts.md) for directional guidance184. Write code following specs and constraints from references1920### Review / Debug211. Read [references/api-common.md](references/api-common.md) (rate limits, error codes)222. Load relevant references for the code being reviewed233. Cross-check code against specs (size limits, token expiry, counting rules, required fields)244. For design pattern concerns, consult [references/experts.md](references/experts.md)255. Report violations with reference to specific constraints2627## Environment Variables2829```30LINE_CHANNEL_ACCESS_TOKEN=Bot access token31LINE_CHANNEL_SECRET=Channel secret (webhook signature verification)32```3334## Common Specifications3536**Read [references/api-common.md](references/api-common.md) before writing any LINE bot code.** Contains rules that affect all API interactions: forward compatibility (don't use strict schemas — LINE adds fields without notice), rate limits, error handling, retry policy, and logging recommendations.3738## Webhook3940- Verification: `x-line-signature` header (HMAC-SHA256, base64, key = Channel Secret)41- Body: `{"destination": "U...", "events": [...]}`42- Bot server must return `200`4344### Signature Verification (pseudocode)4546```47channel_secret = ENV['LINE_CHANNEL_SECRET']48signature = request.headers['x-line-signature']49body = request.body # raw bytes, do NOT parse/reformat before verification5051digest = HMAC_SHA256(key = channel_secret, message = body)52expected = Base64.encode(digest)5354if signature != expected:55 return 403 # reject — not from LINE5657events = JSON.parse(body)['events']58for event in events:59 handle(event)60return 20061```6263- Never deserialize or re-format the body before verification64- Use UTF-8 encoding exclusively65- Official SDKs handle this automatically — use them when possible6667Full event types, properties, and webhook settings → **[references/webhook-events.md](references/webhook-events.md)**6869## Message Sending7071All require `Authorization: Bearer {channel access token}`:7273| Mode | Endpoint | Purpose |74|------|----------|---------|75| Reply | `POST /v2/bot/message/reply` | Reply to user (requires one-time replyToken) |76| Push | `POST /v2/bot/message/push` | Send to a specific user/group at any time |77| Multicast | `POST /v2/bot/message/multicast` | Send to multiple users (max 500) |78| Broadcast | `POST /v2/bot/message/broadcast` | Send to all friends |7980- Max 5 messages per request81- Domain: `api.line.me` (general) / `api-data.line.me` (content upload)8283Message objects → **[references/message-objects.md](references/message-objects.md)**84Full sending API (Narrowcast, statistics, validation, etc.) → **[references/message-sending.md](references/message-sending.md)**8586## Flex Message8788Three-layer structure:8990```91Container (Bubble / Carousel)92 └── Block (Header / Hero / Body / Footer)93 └── Component (Box / Button / Image / Video / Icon / Text / Span / Separator)94```9596Minimal Flex Message:97```json98{99 "type": "flex", "altText": "Notification",100 "contents": {101 "type": "bubble",102 "body": {103 "type": "box", "layout": "vertical",104 "contents": [{"type": "text", "text": "Hello Flex!", "weight": "bold"}]105 }106 }107}108```109110Full component specs, layout, video → **[references/flex-message.md](references/flex-message.md)**111Official Flex Message Simulator examples → `assets/examples/`112113## Reference Index114115| File | Topic |116|------|-------|117| [references/api-common.md](references/api-common.md) | **Read first.** Rate limits, error handling, forward compatibility |118| [references/webhook-events.md](references/webhook-events.md) | Webhook event types and JSON structure |119| [references/message-objects.md](references/message-objects.md) | Message objects, Quick Reply, sender customization |120| [references/action-objects.md](references/action-objects.md) | Action objects (postback, URI, datetimepicker, etc.) |121| [references/message-sending.md](references/message-sending.md) | Reply/Push/Multicast/Narrowcast/Broadcast, statistics |122| [references/flex-message.md](references/flex-message.md) | Flex Message components, layout, styles |123| [references/rich-menu.md](references/rich-menu.md) | Rich Menu CRUD, tab switching, display priority |124| [references/user-profile.md](references/user-profile.md) | User profile, follower IDs, account link |125| [references/group-chat.md](references/group-chat.md) | Group/Room messaging and member APIs |126| [references/audience.md](references/audience.md) | Audience management (create/add/get/delete) |127| [references/insights.md](references/insights.md) | Delivery, follower, and interaction insights |128| [references/channel-token.md](references/channel-token.md) | Channel access token lifecycle |129| [references/coupon.md](references/coupon.md) | Coupon CRUD, reward types, sending |130| [references/url-schemes.md](references/url-schemes.md) | LINE URL schemes for deep linking |131| [references/experts.md](references/experts.md) | Expert domain routing and 17 specialist profiles |132| assets/examples/ | Flex Message JSON examples (11 showcases) |133134## SDK135136Official SDKs: [Python](https://github.com/line/line-bot-sdk-python) | [Node.js](https://github.com/line/line-bot-sdk-nodejs) | [Go](https://github.com/line/line-bot-sdk-go) | [Java](https://github.com/line/line-bot-sdk-java) | [PHP](https://github.com/line/line-bot-sdk-php) | [Ruby](https://github.com/line/line-bot-sdk-ruby)137138Other languages: use [LINE OpenAPI specs](https://developers.line.biz/en/docs/messaging-api/line-bot-sdk/) with OpenAPI Generator.