LINE Messaging API
raw JSON → 3.21.0 verified Tue May 12 auth: no python install: verified quickstart: stale
LINE Messaging API enables bot development for LINE, the dominant messaging platform in Japan, Thailand, and Taiwan with 196M+ monthly users. Official SDKs exist for Python and Node.js. Primary documentation is in Japanese — English docs are complete but may lag Japanese versions.
pip install line-bot-sdk Common errors
error InvalidSignatureError: <InvalidSignatureError [Invalid signature. signature=...]> ↓
cause The webhook signature sent by the LINE Platform does not match the signature calculated by your bot server, often due to an incorrect Channel Secret or modifications to the request body before verification.
fix
Ensure the 'Channel Secret' in your bot application exactly matches the one in the LINE Developers Console, and use the raw request body without any modification (e.g., pretty-printing JSON) for signature validation with UTF-8 encoding.
error LineBotApiError [Authentication failed due to the following reason: invalid token. Confirm that the access token in the authorization...] ↓
cause The Channel Access Token used for API requests is invalid, expired, revoked, or incorrectly configured.
fix
Verify that the 'Channel Access Token' in your code is correct and currently valid in the LINE Developers Console. If it's a short-lived token, ensure it hasn't expired, and if it's been reissued or revoked, obtain a new valid token.
error Request failed with status code 400 ↓
cause This error, often accompanied by an 'invalid replyToken', indicates an issue with the request payload sent to the LINE Messaging API, such as using an expired, already used, or incorrectly formatted reply token or message object.
fix
Ensure the 'reply_token' is used immediately after receiving the event and has not been used before, as reply tokens are single-use and time-sensitive. Also, verify that the message objects in your request adhere to the LINE Messaging API specifications.
error ModuleNotFoundError: No module named 'linebot' ↓
cause The 'line-bot-sdk' Python package has not been installed or is not accessible in the current Python environment.
fix
Install the library using pip:
pip install line-bot-sdk. Confirm that your script is being executed within the Python environment where the package was installed. error LineBotSdkDeprecatedIn30: Call to deprecated method ... (Use 'from linebot.v3.messaging import MessagingApi' and 'MessagingApi(...)....' instead. See https://github.com/line/line-bot-sdk-python/blob/master/README.rst for more details.) -- Deprecated since version 3.0.0. ↓
cause Your code is using older modules or methods from the `linebot` (version 2.x) namespace, but a newer version of the SDK (3.x) is installed, which has introduced a `v3` namespace with breaking changes.
fix
Update your imports and code to use the
linebot.v3 modules and classes as specified in the deprecation warning, adapting your code to the new API structure. Warnings
breaking Signature verification is mandatory. Never process webhook events without verifying X-Line-Signature header using HMAC-SHA256 with your channel secret. ↓
fix Always call handler.handle(body, signature) and catch InvalidSignatureError. Abort 400 on failure.
breaking Do not use body parsers (bodyParser.json, express.json) before LINE webhook middleware in Node.js. Pre-parsing the body breaks signature verification. ↓
fix Register LINE middleware before any body parser middleware on the webhook route
breaking Reply tokens are single-use and expire in 30 seconds. Storing and reusing a reply token will fail silently. ↓
fix Use push messages (push_message API) for delayed or async responses instead of reply tokens
gotcha Webhook endpoint must return HTTP 200 within 30 seconds. LINE Platform retries failed webhooks if webhook redelivery is enabled. ↓
fix Process webhook events asynchronously. Return 200 immediately, handle events in background.
gotcha Channel access token and channel secret are different credentials. Confusing them is the most common setup error. ↓
fix Channel secret → WebhookHandler constructor. Channel access token → Configuration/MessagingApi.
gotcha No error is returned when pushing messages to users who have blocked the bot. Delivery silently fails. ↓
fix Track opt-out webhook events to maintain your own block list and avoid unnecessary push API calls.
gotcha Content from user messages (images, video, audio) must be fetched separately via GET /v2/bot/message/{messageId}/content using api-data.line.me domain, not api.line.me. ↓
fix Use https://api-data.line.me/v2/bot/message/{messageId}/content for binary content retrieval
breaking Missing required Python packages (e.g., Flask, Django, etc.) will cause a `ModuleNotFoundError` when the application attempts to import them. This prevents the application from starting or functioning correctly. ↓
fix Ensure all necessary Python packages are installed in the environment where the script is executed. This can be done using `pip install <package_name>` for individual packages or `pip install -r requirements.txt` if a `requirements.txt` file is used to list dependencies.
Install
npm install @line/bot-sdk Install compatibility verified last tested: 2026-05-12
python os / libc status wheel install import disk
3.10 alpine (musl) - - 1.60s 117.1M
3.10 slim (glibc) - - 1.17s 189M
3.11 alpine (musl) - - 2.08s 129.4M
3.11 slim (glibc) - - 1.73s 201M
3.12 alpine (musl) - - 2.13s 119.5M
3.12 slim (glibc) - - 2.11s 191M
3.13 alpine (musl) - - 2.05s 116.0M
3.13 slim (glibc) - - 2.04s 190M
3.9 alpine (musl) - - 1.47s 116.9M
3.9 slim (glibc) - - 1.34s 190M
Imports
- WebhookHandler (Python v3) wrong
from linebot import WebhookHandlercorrectfrom linebot.v3 import WebhookHandler - MessagingApi (Python v3) wrong
from linebot import LineBotApicorrectfrom linebot.v3.messaging import Configuration, ApiClient, MessagingApi
Quickstart stale last tested: 2026-05-12
from flask import Flask, request, abort
from linebot.v3 import WebhookHandler
from linebot.v3.exceptions import InvalidSignatureError
from linebot.v3.messaging import (
Configuration, ApiClient, MessagingApi,
ReplyMessageRequest, TextMessage
)
from linebot.v3.webhooks import MessageEvent, TextMessageContent
app = Flask(__name__)
configuration = Configuration(access_token='YOUR_CHANNEL_ACCESS_TOKEN')
handler = WebhookHandler('YOUR_CHANNEL_SECRET')
@app.route('/callback', methods=['POST'])
def callback():
signature = request.headers['X-Line-Signature']
body = request.get_data(as_text=True)
try:
handler.handle(body, signature)
except InvalidSignatureError:
abort(400)
return 'OK'
@handler.add(MessageEvent, message=TextMessageContent)
def handle_message(event):
with ApiClient(configuration) as api_client:
line_bot_api = MessagingApi(api_client)
line_bot_api.reply_message(
ReplyMessageRequest(
reply_token=event.reply_token,
messages=[TextMessage(text=event.message.text)]
)
)
if __name__ == '__main__':
app.run()