Jump to content

Help with API call Via iOS Shortcuts


FrayAdjacent

Recommended Posts

I have experience using the REST API in the older ISYs, but that was over http, using "http://user:pass@mydomain/rest/vars/set/2/1/1". Of course, that's not encrypted, so I tried to avoid that from outside my local network. Well, I've moved to a new house, got married and have a new HA setup with some new devices. 

I have the Portal URL for my account, so I know how to write up the URL, but how do I end up passing authentication for the http call? In the iOS Shortcuts app you can input the URL, the method (GET will be fine), and there are headers that can be set with KEY/VALUE pairs. I understand the concept, but I don't know what KEY should be used, nor the VALUE. 

Does my username and password need to be base64 encoded and used as the VALUE? How is it formatted?  Just "usernamepassword" or "username/password"?

I've only found a few breadcrumbs on how to set it up, haven't found anything that concisely describes out to configure authorization using a key:value pair in headers, or if that's not the way to do it, how can it be done in iOS Shortcuts?  

Link to comment

Yes you need to use base64 encoded using username: password.

However this format is basically obsolete and most browsers will not even send it anymore.


I don't know anything about iOS. Does it support standard URL formats or is Steve Jobs still around yet? :)

Edited by larryllix
Link to comment

Ha, I'm not sure about what formats it will accept... but I can pretty easily encode the username:password and test it out. I'm just using the API calls to set variables. I have plenty at this point that won't do anything if I change them. I'm just trying to figure out how to get the basics working, then I'll copy the format for various things I want to do. 

(I have a variable for when I'm home and when I'm not home... I use the UD Mobile app Geofence to set that, and it works pretty well... the wifey probably doesn't want to mess around with that, so I figured on setting up a Shortcut, then set an Automation for when she leaves the house and when she arrives to set 'her' home variable) 

Link to comment

GOT IT. I'll post this for posterity, if anyone wants to use the iOS Shortcuts to make simple API calls. 

For the URL, get the URL from the UD Portal and use it as the URL for the API call:

https://my.isy.io/isy/yourlongidstringgoeshere/rest/vars/set/2/1/0

Under Headers, create one with the KEY "authorization" and the VALUE as "basic yourbase64encodeduserpass" 

Where your encoded password is "username:password" encoded to base64. 

 

  • Like 1
Link to comment

This is a timely post as I'm trying to do exactly what the OP wants.

I'm getting seriously stuck on how to generate and use the authorization key. I'm simply trying to get things working with the URL in my Chrome browser before I attempt the shortcut in iOS.

This is on an EISY. If I go to URL http://192.168.0.50:8080/rest/nodes (I'm using simple things to start), I successfully get all of the ISY nodes listed. If I go to URL https://my.isy.io:8443/rest/nodes, I get a timeout. I've attempted to insert my Base64 encoded password (format username:password) using an online base64 encoder (both normal and URL friendly). I put that string here: https://my.isy.io:8443/encoded_credentials/rest/nodes and again, I obviously get nothing since the non-credential URL timed out.

I've tried so many things that I'm now very confused. I concise guide to get this working would be much appreciated.

Finally, I'm confused by this statement: "To create the url get "URL to ISY" from Portal or use your local IP Address, then append the rest command i.e. /rest/nodes/<nodeAddress>/cmd/DON" which came from this thread: https://forum.universal-devices.com/topic/42202-trying-to-pass-variable-between-2-isys-using-the-portal/?do=findComment&comment=373777

Is "URL to ISY" a function I'm not seeing, or am I taking it too literally? I'm not finding anything and the URL when I'm logged into Portal is simply https://my.isy.io/index.htm.

Thanks
Blaine

Link to comment
2 hours ago, blaine said:

This is a timely post as I'm trying to do exactly what the OP wants.

I'm getting seriously stuck on how to generate and use the authorization key. I'm simply trying to get things working with the URL in my Chrome browser before I attempt the shortcut in iOS.

This is on an EISY. If I go to URL http://192.168.0.50:8080/rest/nodes (I'm using simple things to start), I successfully get all of the ISY nodes listed. If I go to URL https://my.isy.io:8443/rest/nodes, I get a timeout. I've attempted to insert my Base64 encoded password (format username:password) using an online base64 encoder (both normal and URL friendly). I put that string here: https://my.isy.io:8443/encoded_credentials/rest/nodes and again, I obviously get nothing since the non-credential URL timed out.

I've tried so many things that I'm now very confused. I concise guide to get this working would be much appreciated.

Finally, I'm confused by this statement: "To create the url get "URL to ISY" from Portal or use your local IP Address, then append the rest command i.e. /rest/nodes/<nodeAddress>/cmd/DON" which came from this thread: https://forum.universal-devices.com/topic/42202-trying-to-pass-variable-between-2-isys-using-the-portal/?do=findComment&comment=373777

Is "URL to ISY" a function I'm not seeing, or am I taking it too literally? I'm not finding anything and the URL when I'm logged into Portal is simply https://my.isy.io/index.htm.

Thanks
Blaine

Again. I think browsers outlawed this password system and will not pass it from the command URL line. Mine only worked from python3 code lines and my browsers stopped allowing it.

It sounds like the iOS system has some special URL sending app, as per a post above.

Link to comment

Try encoding it in this order:

https://admin:admin@my.isy.io:8443/rest/nodes

Replace admin:admin with your own username and password, but in plain text, not base 64 encoded. The base 64 encoding works with a multiline http request.

I just tested this successfully on my own eisy, from a chrome browser on Windows 10 to turn on an Insteon switch:

http://admin:admin@192.168.0.145:8080/rest/nodes/20 88 BE 1/cmd/DON

Edited by Guy Lavoie
Link to comment
12 hours ago, blaine said:

This is a timely post as I'm trying to do exactly what the OP wants.

I'm getting seriously stuck on how to generate and use the authorization key. I'm simply trying to get things working with the URL in my Chrome browser before I attempt the shortcut in iOS.

This is on an EISY. If I go to URL http://192.168.0.50:8080/rest/nodes (I'm using simple things to start), I successfully get all of the ISY nodes listed. If I go to URL https://my.isy.io:8443/rest/nodes, I get a timeout. I've attempted to insert my Base64 encoded password (format username:password) using an online base64 encoder (both normal and URL friendly). I put that string here: https://my.isy.io:8443/encoded_credentials/rest/nodes and again, I obviously get nothing since the non-credential URL timed out.

I've tried so many things that I'm now very confused. I concise guide to get this working would be much appreciated.

Finally, I'm confused by this statement: "To create the url get "URL to ISY" from Portal or use your local IP Address, then append the rest command i.e. /rest/nodes/<nodeAddress>/cmd/DON" which came from this thread: https://forum.universal-devices.com/topic/42202-trying-to-pass-variable-between-2-isys-using-the-portal/?do=findComment&comment=373777

Is "URL to ISY" a function I'm not seeing, or am I taking it too literally? I'm not finding anything and the URL when I'm logged into Portal is simply https://my.isy.io/index.htm.

Thanks
Blaine

 

Blaine, if you're trying to put the URL into a browser tab and get it to do something, you'd need to try the authorization in the URL, like:

http://username:password@192.168.0.100/rest/vars/set/1/2/1  

That should work locally, though adding :8443 tells the request to go to a specific port. Usually 8443 is a local port that will try to use HTTPS. Publicly outside your local network, anything with 'http' will default to 80 and 'https' will default to 443. Since some ISPs block ports 80 and 443 (to prevent you from running public websites), you may have to set up port forwarding if you want to use a URL like the above. 

But then you get into things like Dynamic DNS and all that.

However, when you're using the ISY Portal, you're talking to the Portal's website, not directly to your ISY. The Portal handles the connection on the back end, so if you're able to, for instance, access your ISY via the UD Mobile app, then it should be configured correctly, and you won't need to tell the my.isy.io URL which port to use. 

The tricky part there is that the Portal might not accept authorization in the "https://user:pass@my.isy.io/...." format. 

That's why, when setting up the Shortcut in iOS Shortcuts, you can enter the URL as https://my.isy.io/isy/yourlongidstringgoeshere/rest/vars/set/2/1/0

The "yourlongidstringgoeshere" will be a long string of characters generated specifically for your account. 

Then in the Shortcut, you click "show more" and you can create the header as I mentioned. 

To encode the username and password, you can google "base64 encoder" and put in the text, encode it and copy it. Once you have that, copy it to your notepad, or somewhere secure. You'll need it for every Shortcut you create. 

 

I hope this is helpful 

Link to comment

Thank you larryllix, Guy Lavoie and FrayAdjacent. You've cleared up the most confusing aspects of this challenge for me.

I misunderstood the part about browsers not supporting this method of passing credentials and I suspect that was my main hurdle to moving forward.

FrayAdjacent... I'm using an EISY, so the ports can't be modified. Regardless, your post was helpful. I tried using one of my DDNS entries to no avail, but it really comes back to what Larry clarified.

I'll get back to this later this weekend. I'm confident that I'll get there.

This is a great group of people! I'm surprised how quickly tips came in.

Cheers,
Blaine

Link to comment

The screenshot is from the Desktop version of Shortcuts, but it's pretty much identical to what you're gonna see on an iOS device. 

When you create a new Shortcut, go to Web under Actions, then Get Contents of URL. 

Paste in your personal URL at my.isy.io. You don't need to use a port if your eISY uses a custom port, as long as the ISY Portal is configured to reach it on that port, or if you have external port 443 forwarded to your internal IP and port. Basically as long as you can talk to your eISY from the Portal, your URL should work, and you shouldn't need to add any port number. 

Set the Method to Get. It works for REST API calls to set variables, so I haven't bothered to test others, however if you use POST, it will pop up another field. POST is for sending data to a web host, and technically the REST API requests aren't sending anything, you're just requesting a URL, and the request itself is interpreted as an action. With the variables, at least, you can use 'set' and 'get', and the response will be different. When you're setting a variable, the response can be ignored. 

Add a header by clicking +, then click the field under Key and enter "authentication". Click under Value and enter the string for your base64 encoded username and password, so the field looks like

"basic fnasdf329fmasd2390iasdfnsadg" 

(this is not a real username and password, don't go trying to decode it!"

(to get the base64 encoded string, find an encoder online, or google around. I could have done it from Terminal on my Mac with the right commands. You input "username:password" and encode it, and you'll get a string of characters. Copy and save it somewhere secure, you'll need it for every request. 

If you have Shortcuts syncing with iCloud, new Shortcuts should show up on your iPhone and iPad. You could then add automations (now the location and "connect to WiFi" stuff can work without interaction)

 

Screenshot 2024-11-02 at 7.08.24 PM.png

Link to comment

EDIT: I'll leave this post here, but I think my problem is in the "Get contents of URL" command. I'm testing with the format used in the previous post by FrayAdjacent, but so far I'm getting the same resultes.

-------------------------------------------------------------

I *think* I'm getting closer, but I'm getting "Authorization missing" when I attempt to run the shortcut from my Mac. Any help is appreciated.

I should note that if I run the following command from my browser, it works as expected and turns on the device:
https://192.168.0.50:8443/rest/nodes/ZY010_1/cmd/DON/

For clarity, I'm using EISY where the default ports are 8080 and 8443... I have no control over that.

The blanked out portion in the image is solely my ISY credentials converted to Base64. The format I used as input to the encoder was "username:password". I entered these same ISY credentials when prompted by my browser to run the REST command within my LAN, so I know they're working.

screenshot2.thumb.jpg.3f97f0bb029657c4d3b1e71ae86f5f37.jpg

Edited by blaine
Link to comment

Additional info. For the URL, I just discovered the "URL to ISY" within Portal. It wasn't clear where that came from initially. I'm now using that as my URL with the added REST commands.

Regardless, I'm now getting "User authorization not valid" returned from the shortcut. Here's what my current shortcut looks like. The first redacted portion is the key from the "URL to ISY" and the second one is my "username:password" encoded in Base64. I feel like I'm doing everything correctly.

EDIT: I used this post from Javi as my template for setting this up:
https://forum.universal-devices.com/topic/39832-siri-shortcuts-interface-to-ud-mobile/?do=findComment&comment=356700

screenshot3.thumb.jpg.0b9ff453e9a3886a59409181fae707d2.jpg

Edited by blaine
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing

    • No registered users viewing this page.
  • Forum Statistics

    • Total Topics
      37k
    • Total Posts
      371k
×
×
  • Create New...