Using variable in the URL

Posted on
Fri Aug 07, 2020 6:31 pm
philipbasile offline
Posts: 113
Joined: Jan 08, 2015
Location: NJ

Using variable in the URL

Dave,

Thank you so much for this plugin its AWESOME.

I'm hitting a website where I pass in my user name and password and it returns a session key.
I have gotten the session key into an indigo variable and now I need to hit a second webpage that needs me to pass in that session key.
How do I insert the indigo variable (session key) in the Ghost URL.

Thanks

Posted on
Sat Aug 08, 2020 3:56 am
howartp offline
Posts: 4268
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Using variable in the URL

Hi Philip

%%v:1234567%%

If Dave has enabled variable substitution, put that in your URL, changing the 1234567 for your variable ID.

https://wiki.indigodomo.com/doku.php?id ... bstitution

Peter


Sent from my iPhone using Tapatalk Pro

Posted on
Sat Aug 08, 2020 7:32 am
DaveL17 offline
User avatar
Posts: 5909
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Using variable in the URL

I don't recall if substitutions work the way that Peter has described in this instance--I'd have to surf the code to find out. However, if you look at this wiki page in the section "Enable Substitutions", you'll find instructions on how to use the preferred method.

Thanks for the kind words about the plugin. It was a group effort.

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

[My Plugins] - [My Forums]

Posted on
Sat Aug 08, 2020 8:18 am
philipbasile offline
Posts: 113
Joined: Jan 08, 2015
Location: NJ

Re: Using variable in the URL

Peter

Thank you for the suggestion when I went into implement your suggestion I realized that I completely missed a checkbox in the device ‘enable substitution’ that allows you to use variables all good thank you!

Philip

Posted on
Sat Aug 08, 2020 11:16 am
howartp offline
Posts: 4268
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Using variable in the URL

DaveL17 wrote:
I don't recall if substitutions work the way that Peter has described in this instance--I'd have to surf the code to find out. However, if you look at this wiki page in the section "Enable Substitutions", you'll find instructions on how to use the preferred method.

Thanks for the kind words about the plugin. It was a group effort.

I've just checked the latest version of code which I have downloaded on my dev machine (which is NOT current by any means) and we definitely didn't have %% substitution in that code.

Peter

Posted on
Sat Aug 08, 2020 11:42 am
DaveL17 offline
User avatar
Posts: 5909
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Using variable in the URL

Thanks Peter.

Cheers.

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

[My Plugins] - [My Forums]

Posted on
Sat Aug 08, 2020 7:34 pm
philipbasile offline
Posts: 113
Joined: Jan 08, 2015
Location: NJ

Re: Using variable in the URL

David,

***** I'm getting an error that says the returned data is not valid json. can you tell whats not valid ?

Thanks
Philip

GhostXML Debug ReturnCode: 0
Trigger Update OnCue Session Key
GhostXML Debug [Ghost XML OnCue Data] URL: https://api.kohler.com/krm/v1/devices/l ... essionkey=[A]&parameters=[4,11,60,69,102,91,114,115,549]&events=active&showperipheraldetails=true (before substitution)
GhostXML Debug [Ghost XML OnCue Data] URL: https://api.kohler.com/krm/v1/devices/l ... arameters=[4,11,60,69,102,91,114,115,549]&events=active&showperipheraldetails=true (after substitution)
GhostXML Debug HTTPS CURL result:
GhostXML Debug ReturnCode: 3
GhostXML Warning [Ghost XML OnCue Data] curl error . [Return code: 3
GhostXML Debug [Ghost XML OnCue Data] Parse Error: No JSON object could be decoded
GhostXML Debug [Ghost XML OnCue Data] jsonRawData
GhostXML Warning There was a parse error. Will continue to poll.here it is

***** Here is the json that is returned

[
{
"servicecompany": {
"servicecompanytypeid": "3",
"parentid": "1",
"name": "Philip",
"description": "",
"email": "philip@gmail.com",
"address1": "",
"address2": "",
"city": "Jackson",
"state": "NJ",
"postalcode": "",
"phone": "19712345064",
"id": "2608",
"usercreated": "philip",
"usermodified": "philip",
"datecreated": "12-26 11:37 AM",
"datemodified": "12-26 11:37 AM",
"version": "1",
"recordstatus": "1"
},
"parameters": [
{
"parameterdefinitionid": "4",
"pdiid": "1100",
"name": "EngineSpeed",
"displayname": "Engine Speed",
"groupid": "2",
"groupname": "EngineMetering",
"groupdisplayname": "Engine Metering",
"deviceid": "24718",
"value": "0",
"displayvalue": "0 R/min",
"id": "1164903",
"usercreated": "47.16.245.135:12993",
"usermodified": "47.16.240.87:1159",
"datecreated": "12-15 4:41 PM",
"datemodified": "08-08 2:08 AM",
"version": "14647",
"recordstatus": 1
},
{
"parameterdefinitionid": "11",
"pdiid": "1107",
"name": "BatteryVoltage",
"displayname": "Battery Voltage",
"groupid": "2",
"groupname": "EngineMetering",
"groupdisplayname": "Engine Metering",
"deviceid": "24518",
"value": "13.3",
"displayvalue": "13.3 V",
"id": "1164907",
"usercreated": "47.16.245.135:12993",
"usermodified": "47.16.240.87:1159",
"datecreated": "12-15 4:49 PM",
"datemodified": "08-08 8:24 PM",
"version": "4345128",
"recordstatus": 1
}
],
"activealerts": [],
"events": [],
"peripherals": [
{
"parameters": [
{
"deviceid": "24518",
"peripheralid": "7",
"parameterdefinitionid": "549",
"parametervalue": "Source1",
"displayorder": "1",
"datatypename": "SourceSelections",
"displayname": "Ats Contactor Position",
"id": "0",
"usercreated": "unknown",
"usermodified": "unknown",
"datecreated": 1596936300,
"datemodified": 1596936300,
"version": "0",
"recordstatus": "1"
},
{
"deviceid": "24518",
"peripheralid": "7",
"parameterdefinitionid": "550",
"parametervalue": "Source1",
"displayorder": "2",
"datatypename": "SourceSelections",
"displayname": "Ats Sources Available",
"id": "0",
"usercreated": "unknown",
"usermodified": "unknown",
"datecreated": 1596936300,
"datemodified": 1596936300,
"version": "0",
"recordstatus": "1"
},
{
"deviceid": "24518",
"peripheralid": "7",
"parameterdefinitionid": "588",
"parametervalue": "233.7",
"displayorder": "4",
"datatypename": "Int32",
"displayname": "Source1 Voltage Average Line To Line",
"id": "0",
"usercreated": "unknown",
"usermodified": "unknown",
"datecreated": 1596936300,
"datemodified": 1596936300,
"version": "0",
"recordstatus": "1"
},
{
"deviceid": "24518",
"peripheralid": "7",
"parameterdefinitionid": "597",
"parametervalue": "60.0",
"displayorder": "5",
"datatypename": "Int16",
"displayname": "Source1 Frequency",
"id": "0",
"usercreated": "unknown",
"usermodified": "unknown",
"datecreated": 1596936300,
"datemodified": 1596936300,
"version": "0",
"recordstatus": "1"
},
{
"deviceid": "24518",
"peripheralid": "7",
"parameterdefinitionid": "623",
"parametervalue": "0.0",
"displayorder": "8",
"datatypename": "Int32",
"displayname": "Source2 Voltage Average Line To Line",
"id": "0",
"usercreated": "unknown",
"usermodified": "unknown",
"datecreated": 1596936300,
"datemodified": 1596936300,
"version": "0",
"recordstatus": "1"
},
{
"deviceid": "24518",
"peripheralid": "7",
"parameterdefinitionid": "632",
"parametervalue": "0.0",
"displayorder": "9",
"datatypename": "Int16",
"displayname": "Source2 Frequency",
"id": "0",
"usercreated": "unknown",
"usermodified": "unknown",
"datecreated": 1596936300,
"datemodified": 1596936300,
"version": "0",
"recordstatus": "1"
},
{
"deviceid": "24518",
"peripheralid": "7",
"parameterdefinitionid": "748",
"parametervalue": "Every Other Week",
"displayorder": "10",
"datatypename": "CalendarInterval",
"displayname": "Exercise Interval",
"id": "0",
"usercreated": "unknown",
"usermodified": "unknown",
"datecreated": 1596936300,
"datemodified": 1596936300,
"version": "0",
"recordstatus": "1"
},
{
"deviceid": "24518",
"peripheralid": "7",
"parameterdefinitionid": "749",
"parametervalue": "15",
"displayorder": "11",
"datatypename": "Int16",
"displayname": "Exercise Run Duration",
"id": "0",
"usercreated": "unknown",
"usermodified": "unknown",
"datecreated": 1596936300,
"datemodified": 1596936300,
"version": "0",
"recordstatus": "1"
},
{
"deviceid": "24518",
"peripheralid": "7",
"parameterdefinitionid": "750",
"parametervalue": "Loaded Full Speed",
"displayorder": "12",
"datatypename": "ExerciseMode",
"displayname": "Exercise Mode",
"id": "0",
"usercreated": "unknown",
"usermodified": "unknown",
"datecreated": 1596936300,
"datemodified": 1596936300,
"version": "0",
"recordstatus": "1"
},
{
"deviceid": "24518",
"peripheralid": "7",
"parameterdefinitionid": "751",
"parametervalue": "True",
"displayorder": "13",
"datatypename": "Boolean",
"displayname": "Exercise Warning Enabled",
"id": "0",
"usercreated": "unknown",
"usermodified": "unknown",
"datecreated": 1596936300,
"datemodified": 1596936300,
"version": "0",
"recordstatus": "1"
}
],
"deviceid": "24518",
"serialnumber": "SGM326HDW",
"peripheralid": "7",
"peripheralname": "SinglePhaseAts",
"peripheraldisplayname": "Single Phase Ats",
"connected": "True",
"id": "24518000007",
"usercreated": "ko82386",
"usermodified": "ko82386",
"datecreated": 1381357618,
"datemodified": 1381357618,
"version": "1",
"recordstatus": 1
},
{
"parameters": [
{
"deviceid": "24518",
"peripheralid": "3",
"parameterdefinitionid": "1331",
"parametervalue": "False",
"displayorder": "1",
"datatypename": "Boolean",
"displayname": "AC Floor 1",
"id": "1264",
"usercreated": "philip",
"usermodified": "philip",
"datecreated": 1454726517,
"datemodified": 1454726517,
"version": "1",
"recordstatus": "1"
},
{
"deviceid": "24518",
"peripheralid": "3",
"parameterdefinitionid": "1333",
"parametervalue": "False",
"displayorder": "2",
"datatypename": "Boolean",
"displayname": "AC Floor 2",
"id": "1265",
"usercreated": "philip",
"usermodified": "philip",
"datecreated": 1454726526,
"datemodified": 1454726526,
"version": "1",
"recordstatus": "1"
},
{
"deviceid": "24518",
"peripheralid": "3",
"parameterdefinitionid": "1335",
"parametervalue": "False",
"displayorder": "3",
"datatypename": "Boolean",
"displayname": "Digital Output B9 Value",
"id": "0",
"usercreated": "unknown",
"usermodified": "unknown",
"datecreated": 1596936300,
"datemodified": 1596936300,
"version": "0",
"recordstatus": "1"
},
{
"deviceid": "24518",
"peripheralid": "3",
"parameterdefinitionid": "1337",
"parametervalue": "False",
"displayorder": "4",
"datatypename": "Boolean",
"displayname": "Digital Output B10 Value",
"id": "0",
"usercreated": "unknown",
"usermodified": "unknown",
"datecreated": 1596936300,
"datemodified": 1596936300,
"version": "0",
"recordstatus": "1"
},
{
"deviceid": "24518",
"peripheralid": "3",
"parameterdefinitionid": "1339",
"parametervalue": "False",
"displayorder": "5",
"datatypename": "Boolean",
"displayname": "Digital Output B11 Value",
"id": "0",
"usercreated": "unknown",
"usermodified": "unknown",
"datecreated": 1596936300,
"datemodified": 1596936300,
"version": "0",
"recordstatus": "1"
},
{
"deviceid": "24518",
"peripheralid": "3",
"parameterdefinitionid": "1341",
"parametervalue": "False",
"displayorder": "6",
"datatypename": "Boolean",
"displayname": "Digital Output B12 Value",
"id": "0",
"usercreated": "unknown",
"usermodified": "unknown",
"datecreated": 1596936300,
"datemodified": 1596936300,
"version": "0",
"recordstatus": "1"
}
],
"deviceid": "24518",
"serialnumber": "SGM111HDW",
"peripheralid": "3",
"peripheralname": "LoadControl",
"peripheraldisplayname": "Load Control",
"connected": "True",
"id": "24518000003",
"usercreated": "ko82386",
"usermodified": "ko82386",
"datecreated": 1381357618,
"datemodified": 1381357618,
"version": "1",
"recordstatus": 1
}
],
"productid": "28",
"productname": "DC2",
"isauthorized": true,
"isauthenticated": true,
"servicecompanyid": "2608",
"serialnumber": "SGM444HDW",
"displayname": "20/RESAL SGM666HDW",
"password": null,
"children": [],
"parent": null,
"isconnected": true,
"datelastconnected": "08-08 2:08 AM",
"ipaddress": "47.16.240.87:1159",
"devicestate": "Standby",
"lat": "41.0045",
"long": "-73.7849",
"description": "",
"address1": "9 Malibu",
"address2": "",
"city": "",
"state": "",
"postalcode": "",
"country": "",
"recordstatus": 1,
"id": "24518",
"usercreated": "47.16.245.135:12941",
"usermodified": "47.16.240.87:1159",
"datecreated": "12-03 6:13 PM",
"datemodified": "08-08 2:09 AM",
"version": "859"
}
]

Posted on
Sun Aug 09, 2020 2:19 am
howartp offline
Posts: 4268
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Using variable in the URL

The JSON you’ve pasted is valid according to JSONLint.com

I wonder if the [] in the URL are throwing the handling and need encoding, but I’m not at my desk with the code right now.


Sent from my iPhone using Tapatalk Pro

Posted on
Sun Aug 09, 2020 3:58 am
DaveL17 offline
User avatar
Posts: 5909
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Using variable in the URL

Hi Philip - sorry that this is proving a bit challenging. As you can imagine, coding for every possible JSON and XML data source is a tad tricky. :D

These errors usually crop up when there is a JSON node name that doesn't translate smoothly into a python dictionary key name that Indigo will accept. We have a list of characters that we overcome which is why Peter is suggesting that as a possible cause. Another possible cause is that the first-level data structure in the JSON you posted is converted to a python list rather than a dictionary, although it would surprise me that this would be the first time that such a thing would crop up. It would be helpful if you could post any Indigo log messages and plugin log messages in a code block so that BBCode doesn't reformat them.

I don't have time to look into this today unfortunately, but I will get on it as soon as I can.
Dave

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

[My Plugins] - [My Forums]

Posted on
Sun Aug 09, 2020 11:23 am
jay (support) offline
Site Admin
User avatar
Posts: 16820
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Using variable in the URL

I suspect the root issue is actually the error coming from curl - the JSON error is just because curl didn't complete successfully. At least that's my guess. I don't see anything in the JSON that looks wrong/bad.

The cCurl docs indicate that an error code 3 is a malformed URL.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Aug 09, 2020 3:45 pm
philipbasile offline
Posts: 113
Joined: Jan 08, 2015
Location: NJ

Re: Using variable in the URL

Jay is correct curl doesn't like the URL.
Thank You Jay.

The URL contains [ and ]. Curl doesn't like brackets.
I ran it in curl and its complaining about globbing.

I see there is a curl option

-g/--globoff
This option switches off the "URL globbing parser". When you set this option, you can
specify URLs that contain the letters {}[] without having them being interpreted by curl
itself. Note that these letters are not normal legal URL contents but they should be
encoded according to the URI standard.

I tested and it works. But I think this option would need to be added to the plugin.
Dave would you be able to add this option to the plugin ?

Thanks

Philip

Posted on
Sun Aug 09, 2020 4:03 pm
howartp offline
Posts: 4268
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Using variable in the URL

Out of interest, does the url work if you encode them?

%5b for [
%5d for ]

Peter


Sent from my iPhone using Tapatalk Pro

Posted on
Sun Aug 09, 2020 4:07 pm
DaveL17 offline
User avatar
Posts: 5909
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Using variable in the URL

Thanks to all for sleuthing this while I was away. Sounds like you all found a great solution. This seems like something that could be easily added to the plugin--I'll take a look at this soon. We put in a 12 hour day today on some personal business, and there's not a lot of functioning brain cells to spare at the moment. :D

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

[My Plugins] - [My Forums]

Posted on
Mon Aug 10, 2020 4:16 pm
philipbasile offline
Posts: 113
Joined: Jan 08, 2015
Location: NJ

Re: Using variable in the URL

Peter

Encoding worked. Great suggestion!
I'd still like to see the option in the plugin if possible.

Thanks

Philip

Posted on
Tue Aug 11, 2020 3:58 am
DaveL17 offline
User avatar
Posts: 5909
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Using variable in the URL

It's my intention to roll this into the plugin. It will take me a while as I'm crazy swamped IRL.

Watch this channel for further developments on the update to the plugin.

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

[My Plugins] - [My Forums]

Who is online

Users browsing this forum: No registered users and 1 guest