Setting URL input for JSON

Posted on
Sun Mar 31, 2019 5:36 am
WouterK offline
Posts: 167
Joined: Aug 19, 2015

Setting URL input for JSON

Hi,

I am trying to read some json information from a app which contains the values of my electric and gas usage.
Using the URL in a commandline it looks like:

Code: Select all
'http://192.168.1.54/api/v2/datalogger/dsmrreading?ordering=-timestamp&limit=1'


/usr/bin/curl -vsk -H 'X-AUTHKEY: 5ZMCOBBXQGKLGJZD3TZZZJYXEMRURXDQABV89HN8HMUPS4P5M56PMZ4A5JRSYSHA' 'http://192.168.1.54/api/v2/datalogger/dsmrreading?ordering=-timestamp&limit=1'
* Trying 192.168.1.54...
* TCP_NODELAY set
* Connected to 192.168.1.54 (192.168.1.54) port 80 (#0)
> GET /api/v2/datalogger/dsmrreading?ordering=-timestamp&limit=1 HTTP/1.1
> Host: 192.168.1.54
> User-Agent: curl/7.54.0
> Accept: */*
> X-AUTHKEY: 5ZMCOBBXQGKLGJZD3TZZZJYXEMRURXDQABV89HN8HMUPS4P5M56PMZ4A5JRSYSHA
>
< HTTP/1.1 200 OK



And this is works.
I am not able to use the single quotes in URL field of the GhostXML device config. Without the single quotes the URL gets the value :

Code: Select all
GET /api/v2/datalogger/dsmrreading?ordering=-timestamp HTTP/1.1


/usr/bin/curl -vsk -H 'X-AUTHKEY: 5ZMCOBBXQGKLGJZD3TZZZJYXEMRURXDQABV89HN8HMUPS4P5M56PMZ4A5JRSYSHA' http://192.168.1.54/api/v2/datalogger/d ... mp&limit=1
[1] 18256
MacBook-Pro:~ wey3$ * Trying 192.168.1.54...
* TCP_NODELAY set
* Connected to 192.168.1.54 (192.168.1.54) port 80 (#0)
> GET /api/v2/datalogger/dsmrreading?ordering=-timestamp HTTP/1.1
> Host: 192.168.1.54
> User-Agent: curl/7.54.0
> Accept: */*
> X-AUTHKEY: 5ZMCOBBXQGKLGJZD3TZZZJYXEMRURXDQABV89HN8HMUPS4P5M56PMZ4A5JRSYSHA
>
< HTTP/1.1 200 OK


It is possible in some way to use the single quotes in the URL field or can/should I use another notation of the URL?

Thanks

Regards,

Wouter

Posted on
Sun Mar 31, 2019 6:17 am
DaveL17 offline
User avatar
Posts: 6753
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Setting URL input for JSON

You shouldn't put quotes around the URL in the GhostXML plugin, so you might first try it without the quotes.

If you need to use single quotes *within* the URL, you could try encoding them like this:

Code: Select all
http://192.168.1.54/api/v2/datalogger/dsmrreading?ordering=-timestamp&limit='1'

would become this:
Code: Select all
http://192.168.1.54/api/v2/datalogger/dsmrreading?ordering=-timestamp&limit=&#39;1&#39;


Although, that's untested. I'll add a note to the TODO list for the plugin to take a look at handling single quotes natively.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sun Mar 31, 2019 6:36 am
WouterK offline
Posts: 167
Joined: Aug 19, 2015

Re: Setting URL input for JSON

Thanks for the (quick) suggestion.

Without the quotes the url used becomes : http://192.168.1.54/'api/v2/datalogger/ ... -timestamp
After the "&" is not used.

Based on your suggestion I played with the position of the single quotes within the URL and found something that works :

Code: Select all
http://192.168.1.54/'api/v2/datalogger/dsmrreading?ordering=-timestamp&limit=1'


Thanks!

Regards,

Wouter

Posted on
Sun Mar 31, 2019 12:58 pm
DaveL17 offline
User avatar
Posts: 6753
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Setting URL input for JSON

That seems odd that the parameters following the '&' wouldn't go through. I'll do some digging and see what I can find.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Mon Apr 01, 2019 12:24 pm
WouterK offline
Posts: 167
Joined: Aug 19, 2015

Re: Setting URL input for JSON

Great, thanks.

However, the notation you suggested is working.

Regards,

Wouter

Posted on
Mon Apr 01, 2019 12:29 pm
DaveL17 offline
User avatar
Posts: 6753
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Setting URL input for JSON

Glad to hear it's working for you. Thanks for letting me know.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest