More guides

Scripting

JSON output and exit codes#

Terminal
line whoami --json
line contacts --json
line contacts --mid USER_MID --json
line chats --search "Family" --json
line messages CHAT_ID --json
line send CHAT_ID --stdin --json < message.txt
  • Use full chat IDs, and keep message IDs as strings.
  • --json, --error-format=json, and --stdin turn prompts off, so pass every required argument.
  • JSON and help go to stdout; diagnostics go to stderr.
  • Empty result lists are [].
Exit codeMeaning
0Success, or help was shown.
1A CLI or network error.
65–78A storage error; see storage exit codes.
130, 143Stopped by SIGINT or SIGTERM.
CommandUseful JSON fields
whoamiProfile and account ID.
contactsFriend names and IDs.
contacts --mid MIDOne record per unique requested MID, with a lookup status.
contacts --userid HANDLE, contacts --phone +CCNUMBEROne resolved contact lookup object (exits 1 with not_found when unmatched).
contacts --blockedArray of blocked contacts and blocked recommendations.
contacts block, contacts unblockAction (block_contact or unblock_contact), chat_id, and request_sequence.
chatsID, type, unread count, and optional activity time.
messagesID, sender, time, content, encryption, and status.
sendMessage ID, chat ID, encryption, group-key registration, and sequence.
downloadOutput path, byte count, and message ID.
read, react, unsendAction, chat ID, message ID, and sequence.
invitesschema_version: 1 and invitations (chat_id, nullable name, name_status).
invites accept, invites rejectAction (accept_invitation or reject_invitation), chat ID, and sequence.
watchOne JSON event per line.
updateInstalled/latest versions, status, installation method, and next step. Use --check --json to only check.
doctorschema_version: 1, checks (id, status, message, optional next_step and string details), and a summary count per status.

If some messages can't be decrypted, messages --json still writes the full array with a status for each message, then exits 1. It never prints encrypted chunks or raw server responses.

Structured errors#

Put --error-format=json before the command to get one structured error on stderr, while success and partial results still go to stdout as JSON:

Terminal
line --error-format=json send CHAT_ID --stdin --json < message.txt

It can go before or after --read-only, and it turns prompts off. It works with the core commands and auth status. Login, logout, migration, watch, and update reject it before doing anything; use their normal diagnostics instead.

Each error has a stable code and stage. Message actions also report the chat and message IDs they know, the request sequence, whether the action was attempted, its outcome, and any preparation or upload steps. A file message can be confirmed even if its upload fails, and a send stays confirmed if writing the result fails.

Never retry an unknown action automatically, even after a network error: check LINE first. Storage and signal exit codes don't change. See the error fields, codes, and examples.

Read-only mode#

Put --read-only before the command, or set LINE_CLI_READ_ONLY=1, when a script or agent should only read:

Terminal
line --read-only messages CHAT_ID --json
LINE_CLI_READ_ONLY=1 line chats --json
line --read-only --error-format=json send CHAT_ID --text "hi"   # refused

Refused: send, read, react, unsend, invites accept, invites reject, contacts block, contacts unblock, login, logout, auth migrate, and installing with update. They stop before prompts, stdin, attachments, the session lock, credential storage, the network, or a request sequence.

Still allowed: reads (including contacts --blocked, --userid, and --phone), watch (its resume position is local), download, auth status, doctor, update --check, help, and version. Reads may still refresh the access token.

LINE_CLI_READ_ONLY accepts 1 or true (on) and 0, false, or unset (off). Any other value fails every command with invalid_arguments, so a typo never quietly turns the guard off. --read-only=false can't override the environment variable. A refused command exits 1 with the JSON error code read_only (stage preparation); message actions report attempted: false and outcome: "not_attempted". Command help still works in read-only mode.

Contact lookup JSON#

contacts --mid MID --json returns an array, even for one ID. Each record has the usual contact fields mid, displayName, displayNameOverridden, statusMessage, and picturePath, plus:

FieldMeaning
effectiveDisplayNameYour custom name, or the profile name if you haven't set one. Empty when no name is available.
statusresolved if LINE returned a profile; unavailable if it left that MID out.

A missing profile still gets a row with its requested mid and empty name and profile fields. A returned profile can also have an empty name, so fall back to the MID when displaying it. Match rows by mid, because duplicate input IDs appear only once.

If LINE returns every profile, the command exits 0. If any are unavailable, it writes the complete array, reports the count on stderr, and exits 1; the array is still usable as a partial result. A network, sign-in, or malformed-response error produces no array, even if an earlier batch succeeded.

Last updated Dec 1, 2026Edit this page