# HTTP request flow cards

**URL:** <https://community.homey.app/t/http-request-flow-cards/38876>\
**Category:** Questions & Help\
**Tags:** tools\
**Created:** [December 9, 2020, 12:56pm UTC](https://community.homey.app/t/http-request-flow-cards/38876 "2020-12-09T12:56:01Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Menne\_Talsma](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/menne_talsma/32/8752_2.png) [@Menne\_Talsma](https://community.homey.app/u/Menne_Talsma)\
**Post date:** [December 9, 2020, 12:56pm UTC](https://community.homey.app/t/http-request-flow-cards/38876/1 "2020-12-09T12:56:01Z")

</div>

Who can and will help me? maybe @robertklep ?

I want to operate my Air conditioner with flows, The device has a built-in webserver,

I start with a POST-request to log-on to http:/192.168.x.x/api.cgi:  
{“command”:“login”,“data”:{“username”:“user”,“password”:“welkom”}}

Now that works charming and the response (promise) on this POST-request is:  
{“success”:true,“data”:{“id”:{“sessionID”:“v8uS55b50457Ep7Yl5O94liu2sXY0WE”}}}

Now I need that **SessionID** in a consecutive command to change some values (eg. On/off)  
{“command”:“setdatapointvalue”,“data”:{“sessionID”:" v8uS55b50457Ep7Yl5O94liu2sXY0WE ,“uid”:1,“value”:1}}

I’ve tried my best but I can’t get that response in a variable.

Something similar works fine wit a GET-request in the flow card A22 “GET JSONpath Better Logic”, That’s how I read-out some values of my ancient Homewizard…($.data.id.SessionID)

But there’s no such a card for a POST-request, So I thought maybe the card T30 “Incoming-post’ could do the trick… but I can’t get it to work

I also tried advanced options on the A22 card {“method”:”post” etc… etc…} but I cant get the body-part {“command”: etc.etc.} in there

Help?

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [December 9, 2020, 1:12pm UTC](https://community.homey.app/t/http-request-flow-cards/38876/2 "2020-12-09T13:12:19Z")

</div>

I don’t think it’s possible with the HTTP Request Flow Cards app. Instead, you could use a [Homeyscript](https://homey.app/nl-nl/app/com.athom.homeyscript/HomeyScript/):

```auto
const response = await fetch('http://192.168.x.x/api.cgi', {
    method : 'POST',
    headers: { 'content-type' : 'application/json' },
    body: JSON.stringify({"command":"login","data":{"username":"user","password":"welkom"}})
});
if (! response.ok) throw Error('Invalid response');
const data = await response.json();
if (! data.success) throw Error('No success');
const sessionID = data.data.id.sessionID;
await setTagValue('sessionID', { type: 'string', title : 'Session ID' }, sessionID);
return true;

```

In other cards you should be able to use a tag called `sessionID` for subsequent requests.

---

<div class="post-metadata">

**Author:** ![Menne\_Talsma](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/menne_talsma/32/8752_2.png) [@Menne\_Talsma](https://community.homey.app/u/Menne_Talsma)\
**Post date:** [December 9, 2020, 5:40pm UTC](https://community.homey.app/t/http-request-flow-cards/38876/3 "2020-12-09T17:40:07Z")

</div>

@robertklep

thanks for the reply (so fast!!)  
I was kinda afraid you were gonna say something like that.  
Now I need to get myself familiar with Homeyscript…

I know a thing or two about javascripting (I’ll manage with examples and trial n error.) But I never did any scripting on homey. I Have the app installed but that’s about it

I am starting from absolute zero…  
where do I put (store) the code, how do I call it… that sort of beginners-questions

is there a crash-course Homeyscripting for Dummies somewhere? 'cus I can’t find it on the community

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [December 9, 2020, 6:53pm UTC](https://community.homey.app/t/http-request-flow-cards/38876/4 "2020-12-09T18:53:56Z")

</div>

You can install the script here: [https://homeyscript.homey.app/](https://homeyscript.homey.app/)

When you have installed the app, you can use it in a flow like this:

I called the script ‘HTTP POST test’, which gets executed in the “And…” card, and the action sends me a push notification containing the session ID tag that the script returned.

---

<div class="post-metadata">

**Author:** ![Menne\_Talsma](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/menne_talsma/32/8752_2.png) [@Menne\_Talsma](https://community.homey.app/u/Menne_Talsma)\
**Post date:** [December 9, 2020, 10:05pm UTC](https://community.homey.app/t/http-request-flow-cards/38876/5 "2020-12-09T22:05:32Z")

</div>

pff this homeyscript-language is hard to read

I feel i’m reaching the end of your helping energy, which I can understand  
You wizzards cannot keep educating newbie’s 🙂

but the script is not working  
homey script page consol-windows says: Script error: undefined  
using it in a flow i get a yellow flag saying ‘Invalid response’…  
which is the error message from the script

so i put the error statement in line 6 behind slashes to disable it  
//if (! response.ok) throw Error(‘Invalid response’);  
just to see what happens

now then the flow returns on a yellow flag  
invalid json response body at [http://192.168.x.x/api.cgi](http://192.168.x.x/api.cgi)  
reason: Unexpected token \< in JSON at position 0

this leads me to believe that this method does not return a proper Jason code but returns a Html starting with "\<html’ …

Any ideas?? 🙏

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [December 10, 2020, 6:08am UTC](https://community.homey.app/t/http-request-flow-cards/38876/6 "2020-12-10T06:08:10Z")

</div>

I assume you changed the username and password used in the first step?

You write that you “start with a POST-request”; what method are you using for that? Perhaps the script needs to send particular headers along with the request.

You can add a bit more debugging information by adding this before the `if (! response.ok)` line (which you shouldn’t comment out, because that’s where it’s failing):

```auto
console.log('Response: %j', response);

```

---

<div class="post-metadata">

**Author:** ![Menne\_Talsma](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/menne_talsma/32/8752_2.png) [@Menne\_Talsma](https://community.homey.app/u/Menne_Talsma)\
**Post date:** [December 10, 2020, 5:54pm UTC](https://community.homey.app/t/http-request-flow-cards/38876/7 "2020-12-10T17:54:40Z")

</div>

Yes off course I changed UN/PW to what it should be and also replaced the x-es in the ip-adress 🙂

Thanks so far for your time and energy… really appreciated 🙏

when I insert the extra line of code you provided, the console returns a long line that starts with:

```
    Response: {"url":"http://192.168.x.x/api.cgi","status":500,"status*
    Text":"Internal Server Error","headers"......**

```

an ends with

```
     ...."bodyUsed":false,"size":0,"timeout":0,"_raw":[],"_abort":false}*

```

That’s not the response I am looking for, so something’s wrong

How I started…  
I started by looking at the network traffic in chrome-devtools while loggin in to the internal webserver of the device. i Looked at the api call and found this…

 ![devtools 1](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/c/9/c9eea905d78ad540c4360011f986fb61549b2af4.png)

the json response (devtools Response-tab) is

```
     {"success":true,"data":{"id":{"sessionID":"igCwXt0O369F0rxAy81d3DN27w9bgWa"}}}

```

The second thing I tried was to copy/paste the payload in a Logic-MakeWebRequest actioncard, in a flow and executed the flow… like so:

 ![flow.PNG](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/5/f/5fa2c62686af4016de0947eb73c5d62c529de856.jpeg)  
And it kinda works… the post gets send, and the data is received properly,  
How Do I know so sure that the payload is received ok and is processed properly? Well

Firstly:  
When the flow as shown above is executed, immediately my browser-session get’s kicked out. Appearently the small webserver on the device allowes only for one session at a time (which makes sense)

secondly:  
When I am logged in with a browser and I copy the sessionID from the Devtools window and paste it in the ‘Body’-section of a Logic-MakeWebRequest-Action card like so:

```
    {"command":"setdatapointvalue","data":{"sessionID":"04Ln8vt3w6G5GLh56d5GO2nYPleD2m0","uid":1,"value":1}}

```

The the device turns on! So as long as the sessionID is valid , I can send all kinds of “uid”.values to the server and completely control my device with flow-cards…

So I know that it actually can work,  
Only I just can’t get it to work… So frustrating…

I hope you have some ideas left…  
If not… Thanks for helping anyway!!

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [December 11, 2020, 5:23am UTC](https://community.homey.app/t/http-request-flow-cards/38876/8 "2020-12-11T05:23:28Z")

</div>

Only thing I can think of is to send along the request headers that are shown in your screenshot, starting with `Accept`, `Accept-Language`, `Content-Type`, `Cookie`, `Origin` and `User-Agent`.

---

<div class="post-metadata">

**Author:** ![Menne\_Talsma](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/menne_talsma/32/8752_2.png) [@Menne\_Talsma](https://community.homey.app/u/Menne_Talsma)\
**Post date:** [December 11, 2020, 2:50pm UTC](https://community.homey.app/t/http-request-flow-cards/38876/9 "2020-12-11T14:50:06Z")

</div>

I tried that already (only didn’t know that the order was important) I tried again just now with the order fixed like you suggested but I don’t get theJSON response I want

the JSON response that i get is still:

```
 *Response: {"url":"http://192.168.x.x/api.cgi","status":500,"statusText":"Internal Server Error"

```

also in there are words like

```
  ..."body":{"_readableState":{"objectMode":false,... 

```

And

```
  ..."bodyUsed":false,...

```

When I comment-out the body json.stringify part out, the response is exactly the same the same

I have a feeling that the problem is in the lay-out, the punctuation of the body somewhere.  
The browser sends it as Request-Payload… does that matter?

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [December 11, 2020, 3:22pm UTC](https://community.homey.app/t/http-request-flow-cards/38876/10 "2020-12-11T15:22:37Z")

</div>

Header order doesn’t (or _shouldn’t_) matter. The body-related being logged isn’t relevant because the response fails anyway.

I doubt it’s the punctuation, because from what I can see it’s exactly the same as what the original request is sending.

Did you also try sending the `X-Requested-With` header?

The device seems to have a very small non-compliant HTTP server, so it can be any number of things that it may not accept even though it’s valid according to the HTTP spec. Trial and error, I’m afraid,

---

<div class="post-metadata">

**Author:** ![Menne\_Talsma](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/menne_talsma/32/8752_2.png) [@Menne\_Talsma](https://community.homey.app/u/Menne_Talsma)\
**Post date:** [December 11, 2020, 4:39pm UTC](https://community.homey.app/t/http-request-flow-cards/38876/11 "2020-12-11T16:39:53Z")

</div>

Yeah i did, I copied the whole header-section (with the right punctuation)…didn’t do the trick…

it does accept the JSON if it is send by a flow… any idea why?

Damn this is frustrating 🤬  
the Github intesis-airconwithme-app created by @Ramon works fine,

> **[nlrb/com.intesis.acwm](https://github.com/nlrb/com.intesis.acwm)**
>
> Homey app for Intesis Airconwithme airco control. Contribute to nlrb/com.intesis.acwm development by creating an account on GitHub.

Thing is… the options in flow-action-cards are very limited (just on/off and temp)  
but somehow i can be done… 🥴

Thanks a lot for your help and time so far  
I learnt a lot

Menne

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [December 11, 2020, 4:58pm UTC](https://community.homey.app/t/http-request-flow-cards/38876/12 "2020-12-11T16:58:25Z")

</div>

> [@Menne\_Talsma](#):
>
> it does accept the JSON if it is send by a flow… any idea why?

Not really no. It’s probably a combination of headers and/or their value, or perhaps it doesn’t accept that `fetch` will normalize header names to lowercase. In fact, thinking about it, that might actually be the problem. If so, you can’t use Homeyscript at all because you cannot prevent normalization.

---

<div class="post-metadata">

**Author:** ![Pieke](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/pieke/32/12476_2.png) [@Pieke](https://community.homey.app/u/Pieke)\
**Post date:** [December 12, 2020, 8:38pm UTC](https://community.homey.app/t/http-request-flow-cards/38876/13 "2020-12-12T20:38:16Z")

</div>

Easier way is buying a tado airco controller. Works fine with homey and of course flows. I control two airco’s cooling, heating etc. No scripts less time spent

---

<div class="post-metadata">

**Author:** ![Menne\_Talsma](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/menne_talsma/32/8752_2.png) [@Menne\_Talsma](https://community.homey.app/u/Menne_Talsma)\
**Post date:** [December 15, 2020, 2:52pm UTC](https://community.homey.app/t/http-request-flow-cards/38876/14 "2020-12-15T14:52:49Z")

</div>

@Pieke Thx, I’'ll look into that.  
Does Tado offer Advanced commands with you airco (in a flow) like fan-speed (1-4) , airco-modes (cooling, heating, fan-only) or is it just on/off and target-temperature.

I’d hoped that I could solve it with Homeyscript, and learn some Homeyscript as I go along, but I think I have to admit that Homeyscript is a bit out of my league…

Back in the days I was quite good with Visual basic, but Man… Javascripting is something else.  
I feel Like learning Russian While hoping it’s as easy as learning English… 🥴

---

<div class="post-metadata">

**Author:** ![Raytestrak](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/raytestrak/32/3299_2.png) [@Raytestrak](https://community.homey.app/u/Raytestrak)\
**Post date:** [December 23, 2020, 8:24am UTC](https://community.homey.app/t/http-request-flow-cards/38876/15 "2020-12-23T08:24:07Z")

</div>

I’m wondering if I can accomplish something with a http request. I can read some stats from my thermostat, a web site that displays this info:

{“result”:“ok”, “currentTemp”:“2007”, “currentSetpoint”:“2000”, “currentInternalBoilerSetpoint”:“18”, “programState”:“0”, “activeState”:“1”, “nextProgram”:"-1", “nextState”:"-1", “nextTime”:“0”,“nextSetpoint”:“0”,“randomConfigId”:“1804289383”,“errorFound”:“255”,“connection”:“0”,“burnerInfo”:“0”,“otCommError”:“0”,“currentModulationLevel”:“0”}

burnerInfo is the one I’m trying to read in a flow, it’s basically the one that says my central heating is ‘on’ and I want to use that info in a flow. There’s no other option via Homey at this moment, so I’m hoping to do this with a http request, but it’s out of my area of expertise.

---

<div class="post-metadata">

**Author:** ![Menne\_Talsma](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/menne_talsma/32/8752_2.png) [@Menne\_Talsma](https://community.homey.app/u/Menne_Talsma)\
**Post date:** [December 23, 2020, 1:12pm UTC](https://community.homey.app/t/http-request-flow-cards/38876/16 "2020-12-23T13:12:29Z")

</div>

I you do succeed, please show me the homeyscript…  
I’ve been tinkering with it every other day for a couple of hours, but no succes so far…

---

<div class="post-metadata">

**Author:** ![Raytestrak](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/raytestrak/32/3299_2.png) [@Raytestrak](https://community.homey.app/u/Raytestrak)\
**Post date:** [January 9, 2021, 7:30am UTC](https://community.homey.app/t/http-request-flow-cards/38876/17 "2021-01-09T07:30:12Z")

</div>

My issue should be relatively easy, get the JSON value for burnerInfo from my thermostat and do something in Homey. Couldn’t get it to work the normal way, so I worked around it. I have an OpenWRT router on which I read my thermostat in a bash script on a cron schedule, if the value is 1 I send a POST command to Homey to turn on my pump for the heated floor if it’s zero I turn it off. I’ll see if I can get it to work in Javascript so there’s no extra device/step needed.

Edit: I’m tinkering with the API again and saw my old post. Figured it out in Homey after all, was actually rather obvious. Used a GET JSONPATH card:

[http://thermostat/happ\_thermstat?action=getThermostatInfo](http://thermostat/happ_thermstat?action=getThermostatInfo) {} $.burnerinfo 1

---

<div class="post-metadata">

**Author:** ![Froos](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/froos/32/37707_2.png) [@Froos](https://community.homey.app/u/Froos)\
**Post date:** [March 15, 2021, 2:33pm UTC](https://community.homey.app/t/http-request-flow-cards/38876/18 "2021-03-15T14:33:35Z")

</div>

Hi there, I encouter problems with the Body request parameter ‘’‘grant\_type’’. Can HTTP request flows work with Body request parameters / URLSeachParam? What is the syntax in a flow for this?

This works on a Advance Rest Client:

curl “[https://oauth.cleargrass.com/oauth2/token”](https://oauth.cleargrass.com/oauth2/token%E2%80%9D)  
-X POST  
-d “grant\_type=client\_credentials”  
-H “Authorization: Basic el92ZzI4xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxDZlZDY5”  
-H “Content-Type: application/x-www-form-urlencoded”

Result 200ok  
{“access\_token”:“EuSlSPvfxxxxxxxxxxxnnMqcdiDbP16rQU7ft1QTRss5BR1M”,“expires\_in”:7199,“scope”:"",“token\_type”:“bearer”}

---

<div class="post-metadata">

**Author:** ![Raytestrak](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/raytestrak/32/3299_2.png) [@Raytestrak](https://community.homey.app/u/Raytestrak)\
**Post date:** [July 12, 2023, 10:26am UTC](https://community.homey.app/t/http-request-flow-cards/38876/19 "2023-07-12T10:26:05Z")

</div>

Can I use parameters in an incoming POST card and if so, how?

I use POST commands in HomeAssistant and OpenWRT to start flows on Homey.

for instance curl -X POST [http://homey/api/app/com.internet/whitelist/TEST](http://homey/api/app/com.internet/whitelist/TEST) starts the FLOW TEST, but now I have multiple flows that do the same thing, so a parameter would be better.
