Send LINE over API

In this article, we cover how to send LINE messages over API. In more details, we'll cover how to configure the LINE Notification Service SMS failover scenario.

Create Scenario

Step 1 – Create an OMNI scenario. In the OMNI scenario configuration, you need to define the OMNI steps which will be sequentially executed. The key parameters are the Channel and From, identifying the communication channels and senders for each communication channel.

For the LINE sender (“channel”: “LINE” flow) you should use the LINE sender provided during the activation process, for example: LINE_INFOBIP.

Request example:

POST /omni/1/scenarios 
HTTP/1.1 Host: {base_url} 
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== 
Content-Type: application/json 
{
 "name":"My LINE-SMS scenario",
 "flow": [
    {
     "from":"Line IB test TW",
     "channel": "LINE"
    },
    {
     "from": "InfoSMS",
     "channel": "SMS"
    } 
   ],
   "default": true
}

Response format:

{
 "key": "CC9F01A5DC7BEE2C2B829D203482A654",
 "name":"My LINE-SMS scenario",
 "flow": [
   {f
     "from": "InfoLine",
     "channel": "LINE"
   },
   {
     "from": "InfoSMS",
     "channel": "SMS"
   }
  ],
  "default": true
}

If successful, the response header HTTP status code will be 200 OK, and the scenario will be created, as shown in the example below. If you try to create the scenario without authorization, you will receive a 401 Unauthorized error.

The key parameter needs to be stored as it will be used when sending the message.

Send LINE Notification Messages (Text)

Step 2 - Send OMNI messages through LINE and SMS communication channels. To activate SMS as a channel, contact your Account manager or contact us.

The LINE message will be sent first to the defined phoneNumber. If for some reason, the message is rejected, the end user doesn’t have LINE app installed or the message doesn't get delivered, the same message will be sent as an SMS.

Parameter

Type

Description

type

constant

Text

text

string

Text of the message that will be sent. Max is 1000 characters.

Request example:

POST /omni/1/advanced HTTP/1.1 
Host: {base_url} 
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== 
Content-Type: application/json 

{
  "messages": [{ 
      "to": {
          "phoneNumber": "41793026731"
      },
      "status": {
         "groupId": 1,
         "groupName": "PENDING",
         "id": 7,
         "name": "PENDING_ENROUTE",
         "description": "Message sent to next instance"
      },
      "messageId": "50c24400-124f-4678-9f4b-309e994a4deb"
    }]
} 

If successful, the response header HTTP status code will be 200 OK, and the scenario will be created, as shown in the example below. If you try to create the scenario without authorization, you will receive a 401 Unauthorized error.

Send LINE Notification Messages (Image)

Here's how to send LINE messages with an image.

Parameters:

Parameter

Type

Description

type

constant

Image

url

string

URL of the image sent in the Line message. Max 1000 characters.

thumbnailUrl

string

Thumbnail of the image sent in the LINE message. Max 1000 characters.

Request example:

POST /omni/1/advanced HTTP/1.1 
Host: {base_url} 
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== 
Content-Type: application/json 

{ 
 "scenarioKey": "CC9F01A5DC7BEE2C2B829D203482A654",
 "destinations": [{ 
     "to": { 
         "phoneNumber": "41793026727"
     }
 }], 
 "line": { 
     "type": "IMAGE",
     "url": "http://www.example-image.com",
     "thumbnailUrl": "http://www.example-image.com"
 },
     "sms": {
     "text": "This text will be received if Line communication channel message is not delivered."
      }
}

Send LINE Notification Messages (Audio)

Here's how to send LINE messages with an audio.

Parameter

Type

Description

type

constant

Audio

url

string

Url of the audio record that will be sent in the LINE message. Max 1000 characters.

duration

long

Duration of the audio file.

Request example:

POST /omni/1/advanced HTTP/1.1 
Host: {base_url} 
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== 
Content-Type: application/json 

{ 
 "scenarioKey": "CC9F01A5DC7BEE2C2B829D203482A654",
 "destinations": [{ 
     "to": { 
         "phoneNumber": "41793026727"
     }
 }], 
 "line": { 
     "type": "AUDIO",
     "url": "https://www.example-audio.com",
     "duration": 4000
 },
 "sms": {
     "text": "This text will be received if Line communication channel message is not delivered."
      }
}

Send LINE Notification Messages (Video)

Here's how to send LINE messages with a video.

Parameter

Type

Description

type

constant

Video

url

string

Url of the video that will be sent in the LINE message. Max 1000 characters.

thumbnailUrl

string

Thumbnail of the video that will be sent in the LINE message. Max 1000 characters.

Request example:

POST /omni/1/advanced HTTP/1.1 
Host: {base_url} 
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== 
Content-Type: application/json 

{ 
 "scenarioKey": "CC9F01A5DC7BEE2C2B829D203482A654",
 "destinations": [{ 
     "to": { 
         "phoneNumber": "41793026727"
     }
 }], 
 "line": { 
    "type": "VIDEO",
    "url": https://www.videoUrl.com,
    "thumbnailUrl": https://www.thumbnailUrl.com
 },
 "sms": {
     "text": "This text will be received if Line communication channel message is not delivered."
      }
}

Send LINE Notification Message (Sticker)

Here's how to send LINE messages contaning a sticker. Find more LINE stickers.

Parameter

Type

Description

type

constant

Sticker

packageId

string

Package ID of sticker that will be sent.

stickerId

string

Sticker ID that will be sent.

Request example:

POST /omni/1/advanced HTTP/1.1 
Host: {base_url} 
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== 
Content-Type: application/json 

{ 
 "scenarioKey": "CC9F01A5DC7BEE2C2B829D203482A654",
 "destinations": [{ 
     "to": { 
         "phoneNumber": "41793026727"
     }
 }], 
 "line": { 
    "type": "STICKER",
    "packageId": "1",
    "stickerId": "1"
 },
 "sms": {
     "text": "This text will be received if Line communication channel message is not delivered."
      }
}

Send LINE Notification Messages (Flex Message)

Here's how to send a LINE Flex Message. You can use the LINE Bot Designer to help you customize your Flex Message.

Request example:

POST /omni/1/advanced HTTP/1.1 
Host: {base_url} 
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== 
Content-Type: application/json 

{ 
"scenarioKey":" CC9F01A5DC7BEE2C2B829D203482A654", 
"destinations":[ 
  { 
  "to":{
     "phoneNumber": "41793026727"
  }
}],
"line":{
   "type": "FLEX",
   "altText": "Order Notificaion",
   "contents": {
      "type": "BUBBLE",
      "direction": "LEFT_TO_RIGHT",
      "header": {
          "type": "BOX",
          "layout": "HORIZONTAL",
          "contents": [
                {
                "type": "TEXT",
                "text": "Order Notificaion",
                "size": "XL",
                "align": "CENTER",
                "gravity": "CENTER",
                "weight": "BOLD",
                "color": "#FFFFFF"
               }
           ]
    },
      "body": {
        "type": "BOX",
        "layout": "VERTICAL",
        "contents": [
              {
              "type": "TEXT",
              "text": "Dear customer, this is a reminder for your that your order has already delivered.",
              "gravity": "TOP",
              "wrap": true
              },
              {
             "type": "TEXT",
             "text": "Product Name",
             "margin": "LG",
             "weight": "BOLD",
             "color": "#7B7B7B"
             },
             {
             "type": "TEXT",
             "text": "Order ID: A12345",
             "margin": "XS",
             "weight": "BOLD",
             "color": "#7B7B7B"
             }
         ]
    },
     "footer": {
         "type": "BOX",
         "layout": "VERTICAL",
         "contents": [       
             {
             "type": "BUTTON",
             "action": {
             "type": "URI",
             "label": "My Order",
             "uri": https://www.infobip.com/
             },
             "color": "#EB532C"
             }
          ]
    },
      "styles": {
        "header": {
        "backgroundColor": "#EB532C"
                  }
                }
              }
        }
},
"sms": {
  "text": " This text will be received if Line communication channel message is not delivered. "
       }
}

Get Delivery Reports

Use the OMNI reports method to check the status of your sent messages.

The simplest way is to use the method without any query parameters. In that case, the response will contain all messages sent to a specific account. 

Request example:

GET /omni/1/reports HTTP/1.1 
Host: {base_url} 
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== 
Accept: application/json

Response format:

{
  "results": [{ 
      "bulkId": "",
      "price": {
         "pricePerMessage": 0.000000,
         "currency": "HRK"
      },
      "status":{
          "id": 5,
          "groupId": 3,
          "groupName": "DELIVERED",
          "name": "DELIVERED_TO_HANDSET",
          "description": "Message delivered to handset"
      }, 
      "error": {
          "id": 0,
          "name": "NO_ERROR",
          "description": "No Error",
          "groupId": 0, "groupName": "OK",
          "permanent": false
      },
      "messageId": "1215f543ab19-345f-adbd-12ad31451ed25f35",
      "doneAt": "2019-01-10T16:27:20.098+0000",
      "messageCount": 1,
      "sentAt": "2019-01-10T16:27:18.497+0000",
      "to": "41793026727",
      "channel": "LINE"
   }]
}