MiK
October 27, 2022, 11:49am
1
Hi!
I wonder if it is possible to do the following… I have a CURL command which retrieves some JSON data:
curl -f -k -H 'Accept: application/json' -H 'Authorization: Bearer MyTokenHere -X GET https://envoy.local/api/v1/production
This gets this response (from my solar panels):
{
"wattHoursToday": xxx,
"wattHoursSevenDays": yyy,
"wattHoursLifetime": zzz,
"wattsNow": abc
}
Now I’d like to have the ‘abc’ number as a variable to use in other flows…
I’m a bit lost cause this is all new to me, but maybe someone can point me in the right direction?
1 Like
MiK
October 27, 2022, 5:25pm
3
Thanks!
Almost works… I get a response "failed, reason: self signed certificate’
With the cURL command, I can use -k to ignore this, no idea if this is possible in Homey?
Jero
October 27, 2022, 6:19pm
4
opened 12:21PM - 21 Feb 21 UTC
closed 03:34PM - 22 Feb 21 UTC
Hello,
First of all, please let me congratulate for Homeyscript, it's simply … clever and solve a lot of thing.
I've some Tesla Powerwall and recently Tesla update their firmware to do a strong authentification. I solved the issue with Postman:
```
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({"username":"customer","password":"XXXXXX","email":"XXXXXXXX","force_sm_off":false});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://192.168.1.XXX/api/login/Basic", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
```
and when I want to implement this in Homeyscript:
```
try
{
response = await fetch("https://192.168.1.XXX/api/login/Basic",{
"method": "POST",
"headers": {
"user-agent": "Homeyscript",
"accept": "*/*",
"accept-encoding": "gzip, deflate, br",
"connection": "keep-alive",
"content-type": "application/json"
},
"body": {
"username": "customer",
"password": "XXXXXX",
"email": "XXXXXXXX",
"force_sm_off": false
},
"insecureHTTPParser": false,
"redirect": "follow"
});
}
catch (err) {console.log(err);return false;}
```
I got the following error:
```
> FetchError: request to https://192.168.1.XXX/api/login/Basic failed, reason: unable to verify the first certificate
> at ClientRequest.<anonymous> (/node_modules/node-fetch/lib/index.js:1461:11)
> at ClientRequest.emit (events.js:311:20)
> at TLSSocket.socketErrorListener (_http_client.js:426:9)
> at TLSSocket.emit (events.js:311:20)
> at emitErrorNT (internal/streams/destroy.js:92:8)
> at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
> at processTicksAndRejections (internal/process/task_queues.js:84:21) {
> message: 'request to https://192.168.1.108/api/login/Basic failed, reason: unable to verify the first certificate',
> type: 'system',
> errno: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE',
> code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'
```
FYI, in Postman, SSL verification is disabled.
Is the option "insecureHTTPParser" from nodde-fetch supported? If not, do you have any idea how to solve this issue?
Thanks in advance.
Kind regards
NB. I did a mistake with insecureHTTPParser , it has been set to true. But, setting to true don't change the result, I got always the smae error: UNABLE_TO_VERIFY_LEAF_SIGNATURE
rejectUnauthorized: false ensures self signed is allowed
You can try it with HomeyScript if you have that installed. There is a Flow card that can run a code snippet and return a text token.
Hard when this is no longer available under Homey Pro 2023
You should tell the developer of the app.
Just use logical en use GET then put in the URL https://envoy.local/api/v1/production header Accept: application/json
Authorization: “Bearer Mytokenhere”
Cache-Control: no-cache
Host: bearer
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Don’t you need to add a variable in the body ?
A body in a GET request doesn’t make a lot of sense. Also, don’t use that particular Accept-Encoding
header since Homey’s Logic card cannot handle compressed responses.