Receiving events

Table of contents

To receive events related to LINE Things, create a bot, and associate the bot with the channel for the Messaging API. For more information about how to create a bot, see the Messaging API documentation.

Note: A channel for the Messaging API and a bot have a one-to-one relationship.

Note: The Channel Secret and access token (long-lived) are checked at the end of the procedure for Issuing an access token (long-lived).

Receiving a LINE Things event

In LINE Things, the following two events are notified to the specified webhook URL:

  • Device link event
  • Device unlink event

This means you can send a message when the user links or unlinks a device.

Note: Learn more about setting a webhook URL in the channel for LINE Things from Setting the webhook URL.

Note: To confirm that the notified event has been sent from the LINE Platform, verify the signature. You need the Channel Secret to verify the signature. For more information, see Building a bot in the Messaging API documentation.

When a user links a LINE Things-compatible device to LINE, a device link event is notified to the webhook URL.

The JSON object sent to the webhook URL by the device link event looks like this:

{
    "events": [
        {
            "type": "things",
            "timestamp": 1462629479859,
            "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
            "source": {
                "type": "user",
                "userId": "U91eeaf62d..."
            },
            "things": {
                "deviceId": "t2c449c9d1...",
                "type": "link"
            }
        }
    ]
}
Item Description
events.replyToken Token for replying to the event.
events.source.userId User ID of the user for which the LINE Things-compatible device has been linked with LINE.
events.things.deviceId Device ID of the LINE Things-compatible device linked with LINE.

For more information about the JSON objects sent by a webhook event, see Webhook event objects in the Messaging API reference.

If the PSDI was retrieved from the API as described in Acquiring unique values on a product basis, the device that the user has linked can be identified.

If a user unlinks a LINE Things-compatible device from LINE, a device unlink event is notified to the webhook URL.

The JSON object sent to the webhook URL by the device unlink event looks like this:

{
    "events": [
        {
            "type": "things",
            "timestamp": 1462629479859,
            "replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
            "source": {
                "type": "user",
                "userId": "U91eeaf62d..."
            },
            "things": {
                "deviceId": "t2c449c9d1...",
                "type": "unlink"
            }
        }
    ]
}
Item Description
events.replyToken Token for replying to the event.
events.source.userId User ID of the user for which the LINE Things-compatible device has been unlinked from LINE.
events.things.deviceId Device ID of the LINE Things-compatible device that was unlinked from LINE.

For more information about the JSON objects sent by a webhook event, see Webhook event objects in the Messaging API reference.

If the PSDI is acquired by using the API described in Acquiring unique values on a product basis, the device that the user has unlinked can be identified.

Acquiring unique values on a product basis

To acquire the identifier for each LINE Things-compatible device (Product Specific Device ID (PSDI)), use the following API request.

Note: PSDI is the value read from the characteristics that can be identified by psdiServiceUuid and psdiCharacteristicUuid acquired in Creating a trial product.

curl -X GET https://api.line.me/things/v1/devices/{deviceId} \
-H 'Authorization: Bearer {channel access token}' \
Parameter Description
deviceId Device ID
channel access token Access token (long-lived)

The response contains a product ID (productId) and PSDI (productSpecificDeviceId):

{
    "id": "{deviceId}",
    "productId": {productId},
    "productSpecificDeviceId": "{PSDI}"
}

With the PSDI, the user can identify the linked device.