# Possible to use JSON respons from a CURL command as a variable?

**URL:** <https://community.homey.app/t/possible-to-use-json-respons-from-a-curl-command-as-a-variable/71259>\
**Category:** Questions & Help\
**Created:** [October 27, 2022, 11:49am UTC](https://community.homey.app/t/possible-to-use-json-respons-from-a-curl-command-as-a-variable/71259 "2022-10-27T11:49:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![MiK](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/mik/32/34271_2.png) [@MiK](https://community.homey.app/u/MiK)\
**Post date:** [October 27, 2022, 11:49am UTC](https://community.homey.app/t/possible-to-use-json-respons-from-a-curl-command-as-a-variable/71259/1 "2022-10-27T11:49:34Z")

</div>

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):

```auto
{
  "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?

---

<div class="post-metadata">

**Author:** ![Jero](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jero/32/17556_2.png) [@Jero](https://community.homey.app/u/Jero)\
**Post date:** [October 27, 2022, 2:51pm UTC](https://community.homey.app/t/possible-to-use-json-respons-from-a-curl-command-as-a-variable/71259/2 "2022-10-27T14:51:55Z")

</div>

> [@MiK](#):
>
> `wattsNow`

Something like this?

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/f/d/fdf1d743cab599cdbc8a30fdec1522f29c291b15.png)

---

<div class="post-metadata">

**Author:** ![MiK](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/mik/32/34271_2.png) [@MiK](https://community.homey.app/u/MiK)\
**Post date:** [October 27, 2022, 5:25pm UTC](https://community.homey.app/t/possible-to-use-json-respons-from-a-curl-command-as-a-variable/71259/3 "2022-10-27T17:25:50Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Jero](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jero/32/17556_2.png) [@Jero](https://community.homey.app/u/Jero)\
**Post date:** [October 27, 2022, 6:19pm UTC](https://community.homey.app/t/possible-to-use-json-respons-from-a-curl-command-as-a-variable/71259/4 "2022-10-27T18:19:44Z")

</div>

> <https://github.com/athombv/com.athom.homeyscript/issues/28#issuecomment-783459556>
>
> 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.

---

<div class="post-metadata">

**Author:** ![ChrisBoer](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/chrisboer/32/1252_2.png) [@ChrisBoer](https://community.homey.app/u/ChrisBoer)\
**Post date:** [December 8, 2023, 6:16pm UTC](https://community.homey.app/t/possible-to-use-json-respons-from-a-curl-command-as-a-variable/71259/5 "2023-12-08T18:16:03Z")

</div>

Hard when this is no longer available under Homey Pro 2023

---

<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 8, 2023, 6:18pm UTC](https://community.homey.app/t/possible-to-use-json-respons-from-a-curl-command-as-a-variable/71259/6 "2023-12-08T18:18:45Z")

</div>

You should tell the developer of the app.

---

<div class="post-metadata">

**Author:** ![ChrisBoer](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/chrisboer/32/1252_2.png) [@ChrisBoer](https://community.homey.app/u/ChrisBoer)\
**Post date:** [December 8, 2023, 7:57pm UTC](https://community.homey.app/t/possible-to-use-json-respons-from-a-curl-command-as-a-variable/71259/8 "2023-12-08T19:57:01Z")

</div>

> [@MiK](#):
>
> curl -f -k -H ‘Accept: application/json’ -H 'Authorization: Bearer MyTokenHere -X GET [https://envoy.local/api/v1/production](https://envoy.local/api/v1/production)

Just use logical en use **GET** then put in the **URL** [https://envoy.local/api/v1/production](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 ?

---

<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, 2023, 7:08am UTC](https://community.homey.app/t/possible-to-use-json-respons-from-a-curl-command-as-a-variable/71259/9 "2023-12-09T07:08:55Z")

</div>

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.
