# \[Unsupported\] Homey v2 REST API

**URL:** <https://community.homey.app/t/unsupported-homey-v2-rest-api/7268>\
**Category:** Developers\
**Created:** [January 18, 2019, 3:07pm UTC](https://community.homey.app/t/unsupported-homey-v2-rest-api/7268 "2019-01-18T15:07:04Z")\
**Posts on this page:** 20\
**Page:** 4

<div class="post-metadata">

**Author:** ![Lammy](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/lammy/32/11436_2.png) [@Lammy](https://community.homey.app/u/Lammy)\
**Post date:** [August 1, 2019, 2:28pm UTC](https://community.homey.app/t/unsupported-homey-v2-rest-api/7268/61 "2019-08-01T14:28:29Z")

</div>

Just noticed I didn’t mention the http headers.  
These are the ones I use in all calls:

- “Connection: keep-alive”
- “Accept-Language: en-us”
- “Accept-Encoding: br, gzip, deflate”
- “Origin: anyname://authorize”
- “Referer: anyname://authorize”
- “User-Agent: Anyname/1.0”  
Add this header if you post form data: “Content-Type: application/x-www-form-urlencoded”  
And this header if you send JSON in the body: Content-Type: application/json  
Notice, I used a fake application url scheme for Origin and Referer.

---

<div class="post-metadata">

**Author:** ![ismar.slomic](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ismar.slomic/32/13411_2.png) [@ismar.slomic](https://community.homey.app/u/ismar.slomic)\
**Post date:** [August 1, 2019, 2:55pm UTC](https://community.homey.app/t/unsupported-homey-v2-rest-api/7268/62 "2019-08-01T14:55:11Z")

</div>

In what context do you use this authentication method, @Lammy? CLI/Web Page/Server Side API? If you are using JavaScript, could you share your code with us/me?

---

<div class="post-metadata">

**Author:** ![Lammy](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/lammy/32/11436_2.png) [@Lammy](https://community.homey.app/u/Lammy)\
**Post date:** [August 1, 2019, 4:44pm UTC](https://community.homey.app/t/unsupported-homey-v2-rest-api/7268/63 "2019-08-01T16:44:18Z")

</div>

It is C/C++ code, running on armgnulinux. Too much to post it all here, but here is for example the function for step 1 (indentation is lost).

> **athomLogin**
>
> bool athomLogin(std::string email, std::string passw, std::string &jwt)  
> {  
> const char \*headers =  
> “Accept: application/json\r\n”  
> “Accept-Language: en-us\r\n”  
> “Connection: keep-alive\r\n”  
> “Accept-Encoding: br, gzip, deflate\r\n”  
> “Origin: domos://authorize\r\n”  
> “Referer: domos://authorize\r\n”  
> “Content-Type: application/x-www-form-urlencoded\r\n”  
> “”;  
> bool res = false;  
> size\_t sz = 512;  
> char buffer[sz], payload[sz];  
> https\_handle\_t hnd = httpsCreateHandle(“[accounts.athom.com](http://accounts.athom.com)”, 443, headers);  
> sprintf(payload, “email=%s&password=%s”, urlencode(email).c\_str(), urlencode(passw).c\_str());  
> headers\_t ret\_headers;  
> if (200 == https(hnd, “”, “POST”, “/login”, payload, strlen(payload), buffer, &sz, &ret\_headers))  
> {  
> //for (size\_t i = 0; i \< ret\_headers.size(); i++)  
> //{  
> // printf("%s\n", ret\_headers[i].c\_str());  
> //}  
> json reply = json::parse(buffer);  
> //printf("%s\n", reply.dump(2).c\_str());  
> jwt = reply[“token”];  
> res = true;  
> }  
> httpsDestroyHandle(hnd);  
> return res;  
> }

---

<div class="post-metadata">

**Author:** ![Bos](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/bos/32/8527_2.png) [@Bos](https://community.homey.app/u/Bos)\
**Post date:** [November 28, 2019, 10:01pm UTC](https://community.homey.app/t/unsupported-homey-v2-rest-api/7268/64 "2019-11-28T22:01:36Z")

</div>

A great topic and I loved to see two methods explained for retrieving the bearer.  
Unfortunate I was not able to retrieve the bearer in the last part on both methods.

I used the following curl command  
curl -d {“token”:“XXXXXXX”} -H ‘Content Type: application/json’ -XPOST [https://192.168.1.17/api/manager/users/login](https://192.168.1.17/api/manager/users/login)  
–\> The result was: _curl: (35) error:14094410:SSL routines:ssl3\_read\_bytes:sslv3 alert handshake failure_

and

curl -d {“token”:“XXXXXXX”} -H ‘Content Type: application/json’ -XPOST [https://YYYYYYY/api/manager/users/login](https://YYYYYYY/api/manager/users/login)  
–\>The result was nothing, not response at all. I needed to kill the process with ^C.

All earlier steps we executed well, I was able to find the right JWT token (XXX) generated and I’m pretty sure I have the right Cloud\_ID (YYYY) aswell.

Can someone shine a little light on a solution direction?

---

<div class="post-metadata">

**Author:** ![Bos](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/bos/32/8527_2.png) [@Bos](https://community.homey.app/u/Bos)\
**Post date:** [December 1, 2019, 7:45pm UTC](https://community.homey.app/t/unsupported-homey-v2-rest-api/7268/65 "2019-12-01T19:45:12Z")

</div>

I saw a small mistake in the header in the commands, after I changed them both it resulted in the curl (35) error with and SSLv3 handshake failure. Any thought on what could cause the problem?

---

<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 1, 2019, 8:20pm UTC](https://community.homey.app/t/unsupported-homey-v2-rest-api/7268/66 "2019-12-01T20:20:15Z")

</div>

You can’t use `https` in combination with the IP-address directly, you’ll need to use `https://192-168-1-17.homey.homeylocal.com`

---

<div class="post-metadata">

**Author:** ![Bos](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/bos/32/8527_2.png) [@Bos](https://community.homey.app/u/Bos)\
**Post date:** [December 2, 2019, 9:09am UTC](https://community.homey.app/t/unsupported-homey-v2-rest-api/7268/67 "2019-12-02T09:09:08Z")

</div>

Thanks for your response. I altered the curl command in :  
curl -H ‘content-type: application/json’ -d {“token”:“xxxx”} -X POST “[https://192-168-1-17.homey.homeylocal.com](https://192-168-1-17.homey.homeylocal.com)”

Just to be sure, I created a new JWT token in xxxx

This is the response from Homey in HTML format:

Error
```
Cannot POST /
```

Any guidance?

---

<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 2, 2019, 9:17am UTC](https://community.homey.app/t/unsupported-homey-v2-rest-api/7268/68 "2019-12-02T09:17:36Z")

</div>

Sorry for the confusion, you still need to add `/api/manager/users/login` after the scheme and hostname in the URL:  
`https://192-168-1-17.homey.homeylocal.com/api/manager/users/login`

---

<div class="post-metadata">

**Author:** ![Bos](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/bos/32/8527_2.png) [@Bos](https://community.homey.app/u/Bos)\
**Post date:** [December 2, 2019, 9:39am UTC](https://community.homey.app/t/unsupported-homey-v2-rest-api/7268/69 "2019-12-02T09:39:58Z")

</div>

I altered the curl command as follows:  
curl -H ‘content-type: application/json’ -d {“token”:“xxxxxxx”} -X POST “[https://192-168-1-17.homey.homeylocal.com/api/manager/users/login](https://192-168-1-17.homey.homeylocal.com/api/manager/users/login)”

This is the response:  
{“code”:400,“error”:“invalid\_json”,“error\_description”:“An unkown error has occured [invalid\_json]”}

---

<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 2, 2019, 11:04am UTC](https://community.homey.app/t/unsupported-homey-v2-rest-api/7268/70 "2019-12-02T11:04:28Z")

</div>

It should (probably, I don’t know how this API works) be this:

```auto
curl -H 'content-type: application/json' -d '{"token":"xxxxxxx"}' -X POST "https://192-168-1-17.homey.homeylocal.com/api/manager/users/login"

```

Note that I’m using simple quote and double-quote characters, not “smart quote” characters.

---

<div class="post-metadata">

**Author:** ![Bos](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/bos/32/8527_2.png) [@Bos](https://community.homey.app/u/Bos)\
**Post date:** [December 2, 2019, 11:37am UTC](https://community.homey.app/t/unsupported-homey-v2-rest-api/7268/71 "2019-12-02T11:37:46Z")

</div>

Thanks, it worked. Really appreciated your help, now let’s see how to build this in a nice javascript runtime environment.

---

<div class="post-metadata">

**Author:** ![ropske](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ropske/32/16716_2.png) [@ropske](https://community.homey.app/u/ropske)\
**Post date:** [January 12, 2020, 10:07pm UTC](https://community.homey.app/t/unsupported-homey-v2-rest-api/7268/72 "2020-01-12T22:07:06Z")

</div>

Hi, can someone please show me/us some fully code how to use these RestAPI’s?  
How do to the auth?

Can someone please share his examples?  
Thank you so much.

---

<div class="post-metadata">

**Author:** ![ropske](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ropske/32/16716_2.png) [@ropske](https://community.homey.app/u/ropske)\
**Post date:** [January 22, 2020, 8:32am UTC](https://community.homey.app/t/unsupported-homey-v2-rest-api/7268/73 "2020-01-22T08:32:08Z")

</div>

Sorry to ask again here, can someone please show me how to use the REST API ?  
How to login using the curl?

Thank you

---

<div class="post-metadata">

**Author:** ![MichielK](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/michielk/32/16839_2.png) [@MichielK](https://community.homey.app/u/MichielK)\
**Post date:** [February 13, 2020, 5:56pm UTC](https://community.homey.app/t/unsupported-homey-v2-rest-api/7268/74 "2020-02-13T17:56:48Z")

</div>

Ropske,

I’ve created a very basic, very small, working (javascript) example and put it on GitHub:

> **[MichielK/homey-web-basic](https://github.com/MichielK/homey-web-basic)**
>
> Very basic and small Homey-web-app-implementation. Contribute to MichielK/homey-web-basic development by creating an account on GitHub.

  
Feel free to fork/clone and reuse.

There is also a readme.md on how to get things working.

I’ve used it myself to create an alternate dashboard (with temperatures from all of my temperature-sensors) and 1 graph of the temperatures of the latest 24 hours (in one graph so more user-friendly then insights)

Credits to homey.ink and robertklep for the examples / steps.

---

<div class="post-metadata">

**Author:** ![Robin\_van\_Kekem](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robin_van_kekem/32/8187_2.png) [@Robin\_van\_Kekem](https://community.homey.app/u/Robin_van_Kekem)\
**Post date:** [February 13, 2020, 8:26pm UTC](https://community.homey.app/t/unsupported-homey-v2-rest-api/7268/75 "2020-02-13T20:26:19Z")

</div>

Did you change your client\_id and client\_secret on GitHub?  
Ok hope so!

---

<div class="post-metadata">

**Author:** ![andreassolberg](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/andreassolberg/32/16983_2.png) [@andreassolberg](https://community.homey.app/u/andreassolberg)\
**Post date:** [September 27, 2020, 11:14am UTC](https://community.homey.app/t/unsupported-homey-v2-rest-api/7268/76 "2020-09-27T11:14:02Z")

</div>

**Homeyscript to regularly fetch a new valid bearer token for using the API**  
The following guide, describes a setup that automatically fetches an updated bearer token for usage with your homey API. It consists of two main parts:

- A homeyscript that returns an updated bearer token as a return tag value
- An example flow that runs the homeyscript regularly and stores an updated bearer token in a logic variable

I’ve only tested it for my own command. I’d be happy to learn if it works for others as well-

[homey.solweb.no/advanced-api-usage/bearertoken](https://homey.solweb.no/advanced-api-usage/bearertoken)

---

<div class="post-metadata">

**Author:** ![Manu\_Eug](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/manu_eug/32/31261_2.png) [@Manu\_Eug](https://community.homey.app/u/Manu_Eug)\
**Post date:** [December 5, 2020, 6:57pm UTC](https://community.homey.app/t/unsupported-homey-v2-rest-api/7268/77 "2020-12-05T18:57:28Z")

</div>

Hi Homey Devs and Friends  
I created a nuget package and a sample app in C# on GitHub:  
[Homey .Net](https://github.com/epsmae/Homey-.Net)

I implemented so far the following commands:

- Get device for id
- Get all devices
- Get devices for zone id
- Get capability time log
- Gel all zones
- Get all flows
- Get flow for flow id
- Get all alarms
- Update alarm
- Get system info
- Set boolean capability
- Enable flow
- Trigger flow

Feel free to have a look at the request or to contribute.  
The login is not that comfortable. 🤨

---

<div class="post-metadata">

**Author:** ![Ton\_T](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ton_t/32/30303_2.png) [@Ton\_T](https://community.homey.app/u/Ton_T)\
**Post date:** [February 28, 2021, 10:04am UTC](https://community.homey.app/t/unsupported-homey-v2-rest-api/7268/78 "2021-02-28T10:04:43Z")

</div>

Hi,

I tried your script but I got an error on line:  
let code = response4.headers[’\_headers’].location[0].split(’=’)[1]

I changed it to:  
let code = body4.split(’=’)[1]

and removed line:  
console.log(" Response from authorization. Redirect to ", response4.headers[’\_headers’].location[0])

And now it works!

Very usefull! Thanks!

---

<div class="post-metadata">

**Author:** ![greenwell](https://avatars.discourse-cdn.com/v4/letter/g/82dd89/32.png) [@greenwell](https://community.homey.app/u/greenwell)\
**Post date:** [July 9, 2021, 3:40pm UTC](https://community.homey.app/t/unsupported-homey-v2-rest-api/7268/79 "2021-07-09T15:40:33Z")

</div>

Hi Andreas,

I have tried your script and I get there error message mentioned by Ton\_T (TypeError: Cannot read property ‘location’ of undefined).

I’ve also tried his suggested change which works but doesnt return anything (Response content {“code”:500,) → Returned: undefined

Any ideas?

---

<div class="post-metadata">

**Author:** ![SossieNL](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sossienl/32/11341_2.png) [@SossieNL](https://community.homey.app/u/SossieNL)\
**Post date:** [September 6, 2021, 6:10pm UTC](https://community.homey.app/t/unsupported-homey-v2-rest-api/7268/80 "2021-09-06T18:10:50Z")

</div>

> [@Ton\_T](#):
>
> let code = body4.split(’=’)[1]

Besides the changes 2 posts before, change  
let rawd = raw[0].split(‘;’) on line 50 to let rawd = raw[2].split(‘;’)

[Previous page](https://community.homey.app/t/unsupported-homey-v2-rest-api/7268.md?page=3)

[Next page](https://community.homey.app/t/unsupported-homey-v2-rest-api/7268.md?page=5)
