DEV Community

Evan Lin
Evan Lin

Posted on • Originally published at evanlin.com on

LINE Bot Developer Guide: Sending API Requests - Notes

title: [Learning Notes] LINE Bot Developer Guide Explained - 3. Notes on Sending API Requests
published: false
date: 2021-06-09 00:00:00 UTC
tags: 
canonical_url: http://www.evanlin.com/line-bot-guide-3/
---

![](http://www.evanlin.com/images/2021/linebot003.jpg)

## Preface:

Hello everyone, I am Evan Lin, a Senior Development Technology Promotion Engineer at LINE Taiwan. Today's article will explain in detail the "LINE Bot Developer Guide" slide document. This document is from the [Development guidelines](https://developers.line.biz/en/docs/partner-docs/development-guidelines/) slides. Considering that it has not been officially announced and localized in Chinese in Taiwan. This time, we are working with the headquarters to prepare the Chinese version, and we are specifically using this series of articles to explain it, hoping to allow more developers to have a better understanding. The [Development guidelines](https://developers.line.biz/en/docs/partner-docs/development-guidelines/) document has a lot of content, and this slide will also be explained in five articles. This article is the third article, mainly explaining the points to note when sending API requests.

## Article Index:

#### Full slide link: [https://speakerdeck.com/line\_developers\_tw2/line-bot-developer-guideline-chinese](https://speakerdeck.com/line_developers_tw2/line-bot-developer-guideline-chinese)

I hope you can continue to pay attention:

1.  [About LINE Bot](https://www.evanlin.com/2021-05-25-line-bot-guide-1/)
2.  [Notes on Receiving Requests Using Webhook URL](https://www.evanlin.com/line-bot-guide-2/)
3.  [Notes on Sending API Requests (this article)](http://www.evanlin.com/line-bot-guide-3/)
4.  LINE Login
5.  Other related functions

This article will focus on the first section, which is Page 20 ~ Page 30.

## Notes on Sending API Requests
<script async="" data-slide="20" data-id="0e9f6182ae864568a5940cbad5ef4bec" data-ratio="1.77777777777778" src="//speakerdeck.com/assets/embed.js"></script>

In this note, the following related items will be brought up.

- 

A. Issuance of Channel Access Token

- B. Channel Access Token automatic update
- C. Channel Access Token valid upper limit
- D. Receiving responses after message sending is complete
- E. API request retry
- F. Related restrictions on requests
- G. Reply messages and push messages
- H. Use of HTTPS content

The following will begin to explain each page in detail:

## A. Issuance of Channel Access Token
<script async="" data-slide="22" data-id="0e9f6182ae864568a5940cbad5ef4bec" data-ratio="1.77777777777778" src="//speakerdeck.com/assets/embed.js"></script>

The Channel Access Token is the most important credential for the entire Channel. Through this credential, you can have many permissions to modify the settings of the LINE Bot. Therefore, you must be careful with authorization. Here are some tips:

-   It is recommended not to use a Channel Access Token that does not have an expiration date. It is recommended to use the API to request it.
-   When using the API to apply for a Channel Access Token, it is recommended to use the v2.1 method to issue the request.

This way, in addition to ensuring the security of the entire channel credentials, you can also revoke the token if necessary.

#### Reference articles:

-   [LINE Dev Doc: Issue channel access tokens v2.1](https://developers.line.biz/en/docs/messaging-api/generate-json-web-token/)

## B. Channel Access Token automatic update
<script async="" data-slide="23" data-id="0e9f6182ae864568a5940cbad5ef4bec" data-ratio="1.77777777777778" src="//speakerdeck.com/assets/embed.js"></script>

Following the previous page, regarding the management of Channel Access Tokens. It is recommended to use a short-term valid Channel Access Token, and issue a new Token when the expiration date is approaching. Please note that there is an upper limit to the number of Access Tokens (explained on the next page), so you need to revoke (Revoke) the extra ones when the number is exceeded.

## C. Channel Access Token valid upper limit
<script async="" data-slide="24" data-id="0e9f6182ae864568a5940cbad5ef4bec" data-ratio="1.77777777777778" src="//speakerdeck.com/assets/embed.js"></script>

This article has detailed descriptions of the number of Channel Access Tokens:

-   Short-lived channel access token:
    -   **Application method**: Through the API, refer to the [documentation](https://developers.line.biz/en/docs/messaging-api/generate-json-web-token/#issue_a_channel_access_token_v2_1).
    -   **Number**: 30
    -   **Expiration date**: 30 days
-   Long-lived channel access token:
    -   **Application method**: LINE Developer Console
    -   **Number**: 1
    -   **Expiration date**: Until reapplication.

#### Related documents:

-   [Issue channel access token v2.1](https://developers.line.biz/en/reference/messaging-api/#issue-channel-access-token-v2-1)
-   [Issue short-lived channel access token](https://developers.line.biz/en/reference/messaging-api/#issue-shortlived-channel-access-token)

## D. Receiving responses after message sending is complete
<script async="" data-slide="25" data-id="0e9f6182ae864568a5940cbad5ef4bec" data-ratio="1.77777777777778" src="//speakerdeck.com/assets/embed.js"></script>

This slide describes the response status of the system server if the developer uses [Send push message](https://developers.line.biz/en/reference/messaging-api/#send-push-message) or [Send reply message](https://developers.line.biz/en/reference/messaging-api/#send-reply-message). Usually, if it is successful, no information will be returned (empty json), and detailed error information will be returned if there is an error.

#### Related documents:

-   [Send push message](https://developers.line.biz/en/reference/messaging-api/#send-push-message)
-   [Send reply message](https://developers.line.biz/en/reference/messaging-api/#send-reply-message)

## E. API request retry
<script async="" data-slide="26" data-id="0e9f6182ae864568a5940cbad5ef4bec" data-ratio="1.77777777777778" src="//speakerdeck.com/assets/embed.js"></script>

Sometimes when sending a large number of API calls, due to some unexpected situations, the API call may fail, or the response may not be received. At this time, in order to confirm whether the previous call was successful, the platform has designed a related retry mechanism to check.

![](https://developers.line.biz/assets/img/retry-key-flowchart-en.df00acef.png)

Through the "Safely retrying" mechanism. Developers can test whether the last message was sent correctly, and can also ensure whether any users were missed. The related usage scenarios are as follows:

-   If you don't know if the last message was sent successfully, calling "Safely retrying" can resend the same message. Those who have received it will not receive duplicate messages, and those who have not received it can ensure that they receive it.
-   If the last sending had an unexpected situation where the platform could not complete the command, you can use "Safely retrying" to confirm the status of the last time with the platform. If the last time was completely sent, there will be no concerns about duplicate charges.

#### Related documents

-   [Retrying a failed API request](https://developers.line.biz/en/docs/messaging-api/retrying-api-request/)

## F. Related restrictions on requests
<script async="" data-slide="27" data-id="0e9f6182ae864568a5940cbad5ef4bec" data-ratio="1.77777777777778" src="//speakerdeck.com/assets/embed.js"></script>

When developers use the API, they should avoid calling a large number of APIs that exceed the set Rate Limit and cause the system to judge it as a malicious call. Among them, [Rate Limits](https://developers.line.biz/en/reference/messaging-api/#rate-limits) can refer to the following related information:

-   API calls that require more resource processing are 60 times per hour.
    -   [Send a narrowcast message](https://developers.line.biz/en/reference/messaging-api/#send-narrowcast-message)
    -   [Send a broadcast message](https://developers.line.biz/en/reference/messaging-api/#send-broadcast-message)
    -   [Get number of sent messages](https://developers.line.biz/en/reference/messaging-api/#get-number-of-delivery-messages)
    -   [Get number of friends](https://developers.line.biz/en/reference/messaging-api/#get-number-of-followers)
    -   [Get friend demographics](https://developers.line.biz/en/reference/messaging-api/#get-demographic)
    -   [Get user interaction statistics](https://developers.line.biz/en/reference/messaging-api/#get-message-event)
    -   [Test webhook endpoint](https://developers.line.biz/en/reference/messaging-api/#test-webhook-endpoint)
-   APIs that handle fewer resources can accept 60 calls per minute.
    -   [Create audience for uploading user IDs (by JSON)](https://developers.line.biz/en/reference/messaging-api/#create-upload-audience-group)
    -   [Create audience for uploading user IDs (by file)](https://developers.line.biz/en/reference/messaging-api/#create-upload-audience-group-by-file)
    -   [Add user IDs or Identifiers for Advertisers (IFAs) to an audience for uploading user IDs (by JSON)](https://developers.line.biz/en/reference/messaging-api/#update-upload-audience-group)
    -   [Add user IDs or Identifiers for Advertisers (IFAs) to an audience for uploading user IDs (by file)](https://developers.line.biz/en/reference/messaging-api/#update-upload-audience-group-by-file)
    -   [Create audience for click-based retargeting](https://developers.line.biz/en/reference/messaging-api/#create-click-audience-group)
    -   [Create audience for impression-based retargeting](https://developers.line.biz/en/reference/messaging-api/#create-imp-audience-group)
    -   [Rename an audience](https://developers.line.biz/en/reference/messaging-api/#set-description-audience-group)
    -   [Delete audience](https://developers.line.biz/en/reference/messaging-api/#delete-audience-group)
    -   [Get audience data](https://developers.line.biz/en/reference/messaging-api/#get-audience-group)
    -   [Get data for multiple audiences](https://developers.line.biz/en/reference/messaging-api/#get-audience-groups)
    -   [Get the authority level of the audience](https://developers.line.biz/en/reference/messaging-api/#get-authority-level)
    -   [Change the authority level of the audience](https://developers.line.biz/en/reference/messaging-api/#change-authority-level)
-   Some testing or inspection types can be even higher, reaching 1000 times per minute.
    -   [Set webhook endpoint URL](https://developers.line.biz/en/reference/messaging-api/#set-webhook-endpoint-url)
    -   [Get webhook endpoint information](https://developers.line.biz/en/reference/messaging-api/#get-webhook-endpoint-information)

If these limits are exceeded, you will receive a `420 Too Many Requests` response. Please pay attention, developers.

#### Related articles:

-   [Rate limits](https://developers.line.biz/en/reference/messaging-api/#rate-limits)
-   [Prohibiting mass requests to the LINE platform](https://developers.line.biz/en/docs/messaging-api/development-guidelines/#prohibiting-mass-requests-to-line-platform)

## G. Reply messages and push messages
<script async="" data-slide="28" data-id="0e9f6182ae864568a5940cbad5ef4bec" data-ratio="1.77777777777778" src="//speakerdeck.com/assets/embed.js"></script>

Here, the difference between Reply Message and Push Message is described in detail:

-   Reply Token is time-sensitive. For more information, please refer to the related notes in "[Ten Things You Must Know Before Developing a LINE Chatbot](https://engineering.linecorp.com/zh-hant/blog/line-device-10/)".
-   The following event objects of the LINE Messaging API's Webhook will have a Reply token: message, follow, join, postback and beacon. When using the Reply token to send messages, please pay attention to the following two points:
    -   The validity period of the Reply token is very short, and it must be used as soon as possible after receiving the Webhook event. The validity period will be adjusted according to the system status, so we are not able to provide an exact number to the outside world. What can be confirmed is that this number will be in seconds, and developers cannot reply to messages that require more than a few minutes of processing time with the Reply token. The purpose of this is to hope that developers can reply to user messages in the shortest time and provide a better user experience.
    -   The Reply token can only be used once. If you need to reply multiple times after receiving the Webhook event, you must use the [Push message](https://devdocs.line.me/en/#push-message) method to send the message.

#### Related documents:

-   [Send push message](https://developers.line.biz/en/reference/messaging-api/#send-push-message)
-   [Send reply message](https://developers.line.biz/en/reference/messaging-api/#send-reply-message)
-   [Ten Things You Must Know Before Developing a LINE Chatbot](https://engineering.linecorp.com/zh-hant/blog/line-device-10/)

## H. Use of HTTPS content
<script async="" data-slide="29" data-id="0e9f6182ae864568a5940cbad5ef4bec" data-ratio="1.77777777777778" src="//speakerdeck.com/assets/embed.js"></script>

If you need to add pictures, videos, audio, etc. related data in the message. Remember that in addition to complying with HTTPS security specifications, you also need to comply with TLS 1.2 or higher security specifications, otherwise it will not be displayed correctly. TLS 1.0 and 1.1 will no longer be supported (refer to [Updated: TLS 1.0 and TLS 1.1 support by the webhook notification source will be discontinued at the end of January 2021](https://developers.line.biz/en/news/2020/10/06/update-webhook-client-a%20nd-root-certificate/))

#### Related documents:

-   [[Updated] TLS 1.0 and TLS 1.1 support by the webhook notification source will be discontinued at the end of January 2021](https://developers.line.biz/en/news/2020/10/06/update-webhook-client-and-root-certificate/)
-   "[Ten Things You Must Know Before Developing a LINE Chatbot](https://engineering.linecorp.com/zh-hant/blog/line-device-10/)"

## Conclusion:

The above is the supplement and sharing of the third part of the "LINE Bot Developer Guide". If you want to know more content, you can check the full slide, or find other articles to understand.

Want to know more about developer events? Join the "LINE Developer Official Community" official account immediately, and you can receive push notifications of first-hand Meetup events or the latest news related to the developer program. ▼

"LINE Developer Official Community" Official Account ID: @line\_tw\_dev ![img](https://www.evanlin.com/images/2020/line-tw-dev-qr.png)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)