# Getting user IDs

When you want to send a message to a specific user using the Messaging API, specify a user ID. This page explains how to get user IDs.

# What is user ID

A user ID is a unique identifier for users. The user ID is different from the user's display name registered by the user on LINE or the LINE ID used to search for friends on LINE. The user ID is a value issued by the LINE Platform and is a string that matches the regular expression U[0-9a-f]{32}, such as U8189cf6745fc0d808977bdb0b9f22995.

The user ID is different from the display name or the LINE ID

User IDs are issued different values for each provider, even for the same user. If the provider is the same, the user ID is the same regardless of the channel type (LINE Login channel or Messaging API channel).

For example, if there is a Messaging API channel and a LINE Login channel under the same provider, the User ID for user A obtained by each channel will be the same value. However, the user ID of user A obtained by the Messaging API channel under a different provider will be a different user ID value, even if it is the same user.

# Getting user IDs

You can get user IDs by using the four methods:

  1. Developer gets their own user ID
  2. Get user IDs included in webhook
  3. Get all friends' user IDs
  4. Get group chat member or multi-person chat member user IDs

# Developer gets their own user ID

Developers can check their own user ID in the Your User ID tab in the Basic settings tab of the channel in the LINE Developers Console. For more information, see Channel roles in the LINE Developers Console documentation. There is no API available for retrieving a developer's own user ID.

# Get user IDs included in webhook

When a user adds a LINE Official Account as a friend or sends a message to a LINE Official Account, a webhook is sent from the LINE Platform to the URL (bot server) specified in the Webhook URL in the LINE Developers Console. The User ID is included in this webhook. The following JSON sample is an example of the Webhook Event Objects sent when a user adds a LINE Official Account as a friend.

{
  "destination": "xxxxxxxxxx",
  "events": [
    {
      "type": "follow",
      "timestamp": 1462629479859,
      "source": { // You can get the user ID from the userId property of the source object
        "type": "user",
        "userId": "U8189cf6745fc0d808977bdb0b9f22995"
      },
      "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
      "mode": "active",
      "webhookEventId": "01FZ74A0TDDPYRVKNK77XKC3ZR",
      "deliveryContext": {
        "isRedelivery": false
      }
    }
  ]
}

However, if the user hasn't consented on getting user profile information, the user ID won't be included in the webhook. For more information, see Consent on getting user profile information.

# Get all friends' user IDs

Note

This feature is available only for verified or premium accounts. For more information about account types, see the Account Types of LINE Official Account (opens new window) page on LINE for Business.

You can get the user IDs of all users who are friends with a LINE Official Account by using the Get a list of users who added your LINE Official Account as a friend endpoint.

# Get group chat member or multi-person chat member user IDs

Note

This feature is available only for verified or premium accounts. For more information about account types, see the Account Types of LINE Official Account (opens new window) page on LINE for Business.

You can get the user IDs of members of group chats or multi-person chats in which LINE Official Accounts are participating by using the following endpoint:

# Checking if a user ID is valid

Even if you know the user ID, you can't send a message specifying the user ID if the user ID isn't valid.

To check if the user ID is valid, use the get profile information endpoint. If the user ID is valid, the HTTP status code 200 is returned. If anything other than 200 is returned, the user ID isn't valid and no message can be sent.

For more information about why a user ID isn't valid, see Consent on getting user profile information.