# How to use the web dev module to send a POST to LINE API?

**URL:** <https://forum.inductiveautomation.com/t/how-to-use-the-web-dev-module-to-send-a-post-to-line-api/80705>\
**Category:** General Discussion\
**Tags:** scripting\
**Created:** [October 19, 2023, 4:04pm UTC](https://forum.inductiveautomation.com/t/how-to-use-the-web-dev-module-to-send-a-post-to-line-api/80705 "2023-10-19T16:04:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [October 19, 2023, 4:04pm UTC](https://forum.inductiveautomation.com/t/how-to-use-the-web-dev-module-to-send-a-post-to-line-api/80705/1 "2023-10-19T16:04:02Z")

</div>

I have an Ignition client that wants to send messages to LINE, a freeware app for instant communications on electronic devices. LINE offers an API that I should be able to interface with from the Ignition web dev module. This is a screenshot from the developers page.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/5/85f240972883b1e687bcbbbe5d01693fdb785835.png)

```auto
curl -v -X POST https://api.line.me/v2/bot/message/push \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer {channel access token}' \
-H 'X-Line-Retry-Key: {UUID}' \
-d '{
    "to": "U4af4980629...",
    "messages":[
        {
            "type":"text",
            "text":"Hello, world1"
        },
        {
            "type":"text",
            "text":"Hello, world2"
        }
    ]
}'

```

It seems like I need to setup a bot to deal with incoming messages but **I also need to package the data above into the following function** :

I found this link here.

> [@HTTP GET request scripting](https://forum.inductiveautomation.com/t/http-get-request-scripting/12324):
>
> Hi all, I’m once again pushing my Ignition knowledge limits trying to do HTTP requests via an API for an external website. I have found the resource on Ignition function system.net.httpGet: [https://docs.inductiveautomation.com/display/DOC/system.net.httpGet](https://docs.inductiveautomation.com/display/DOC/system.net.httpGet) And that put me in the right direction, but I’m still not sure how to properly handle the result data. If the server returns an HTTP error status code, how can i extract that and log the appropriate error message? My code so far: [code] …

but I don't see how to put the request body together in the example.

```auto
import system
import urllib2

# Generate URL for API call to read products

url = 'https://api.line.me/v2/bot/message/push'

# Create header with information required by API

urlHeader = {“Content-Type”: “application/json”, “Authorization”: “XXXXX”, “X-Line-Retry-Key”: “XXXXX”}

request = urllib2.Request(url, headers=urlHeader)
contents = urllib2.urlopen(request).read()

data = system.util.jsonDecode(contents)
```

It seems like I should be able to use httpPost but I am not sure how to package the required information into the function.  
[https://docs.inductiveautomation.com/display/DOC81/system.net.httpPost](https://docs.inductiveautomation.com/display/DOC81/system.net.httpPost)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/c/fc8e32e45e1286678ef15c76a080c30703cc4cc6.png)

Any input on this issue is appreciated.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 19, 2023, 5:36pm UTC](https://forum.inductiveautomation.com/t/how-to-use-the-web-dev-module-to-send-a-post-to-line-api/80705/2 "2023-10-19T17:36:18Z")

</div>

Use no python libraries. Use no deprecated functions. Use `system.net.httpClient()`. (Lots of posts here on the forum with examples.)

---

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [October 19, 2023, 5:40pm UTC](https://forum.inductiveautomation.com/t/how-to-use-the-web-dev-module-to-send-a-post-to-line-api/80705/3 "2023-10-19T17:40:30Z")

</div>

Is **system.net.httpPost** deprecated?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 19, 2023, 5:43pm UTC](https://forum.inductiveautomation.com/t/how-to-use-the-web-dev-module-to-send-a-post-to-line-api/80705/4 "2023-10-19T17:43:55Z")

</div>

Technically, no, but it is missing a bunch of modern functionality. Don't use any of the `system.net.http*()` functions other than `httpClient()`.

---

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [October 19, 2023, 5:44pm UTC](https://forum.inductiveautomation.com/t/how-to-use-the-web-dev-module-to-send-a-post-to-line-api/80705/5 "2023-10-19T17:44:53Z")

</div>

Well damn... it feels like every time I talk to you @pturmel I have to go back and "fix" 5+ projects.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 20, 2023, 12:37pm UTC](https://forum.inductiveautomation.com/t/how-to-use-the-web-dev-module-to-send-a-post-to-line-api/80705/6 "2023-10-20T12:37:41Z")

</div>

Why do you want to use web dev ?  
If you're using an external API, you can do that from any script. web dev would be to build the API, not use it.

Or do you need to redirect API calls to another API ?

To answer your question:  
Using `system.net.httpClient` and `client.post()`, you can specify headers and data.

---

<div class="post-metadata">

**Author:** ![bmeyers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmeyers/32/37453_2.png) [@bmeyers](https://forum.inductiveautomation.com/u/bmeyers)\
**Post date:** [October 20, 2023, 1:55pm UTC](https://forum.inductiveautomation.com/t/how-to-use-the-web-dev-module-to-send-a-post-to-line-api/80705/7 "2023-10-20T13:55:28Z")

</div>

You are right. I didn't need web dev module to accomplish this... just a lot of reading.

Final working code:

```auto
headers = {'Authorization': 'Bearer Iyo5Kd_this_is_some_long_string_1cDny'}
data = {"to": "U48_user_id_found_in_webhook_4a4", "messages":[{"type":"text","text":"Hello, world1"}]}
uri = 'https://api.line.me/v2/bot/message/push'
response = system.net.httpClient().post(url = uri, headers=headers, data=data)
print response
```

Steps to get here:

1. Create LINE Developers account.

2. Create an official channel.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/7/e796537d959fecc50a49fb4dac83215cf7c78a71.png)

1. For testing create a RequestBin that will accept a webhook.

> **[Connect APIs, Remarkably Fast - Pipedream](https://pipedream.com/)**
>
> Pipedream is a low code integration platform for developers that allows you to connect APIs remarkably fast. Stop writing boilerplate code, struggling with authentication and managing infrastructure. Start connecting APIs with code-level control when...

1. Enable webook URL created at pipedream in LINE developers account.

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/2/f2bab919452e267dc823cf7aff0a8f741484f17c.png)

1. When a user adds the official LINE account a webhook will be sent to Pipedream where you can identify the userId.

2. Put the UserId from pipedream into the working code above in an Ignition script console and that user will receive the message.

Now my next problem is how do I collect various UserId as people on the floor add the official LINE account but I may just throw that problem back to the official IT department.
