Maker API and Shortcuts app for iOS

bump

I just started messing around with the iOS 12 Shortcuts App. It is a pretty powerful tool for iOS users who have always wanted something like Tasker.

My first shortcut that I am trying to make is one that can issue a http POST to reboot my Hubitat Hub.

This works as expected, but requires the Hub Login security to be disabled. I would like to figure out how to automatically log into the hub and then issue the http POST /hub/reboot command.

I am hoping that some of the iOS users could start working together to figure out some cool iOS Shortcuts for Hubitat. I believe @daronspence is on to something here! If a few of us work together to nail down the basics, we could create some very powerful and interesting shortcuts that could be shared with the entire community.

@daronspence - just wanted you to know that I not trying to hijack your thread. I am hoping to simply drive some additional interest in using the new ShortCuts feature of iOS. I'll see if I can figure out how to parse the response from the Hubitat Maker API in a Shortcut to see if I can lend a hand to your original question. Just don't expect much as I am brand new to these shortcuts myself!

2 Likes

@patrick, @chuck.schwer

Gentlemen,

I am hoping you can lend your expertise to help figure out why the iOS Shortcuts app is interpreting the responses from the Hubitat Maker API as a file, instead of a JSON string. As shown by @daronspence in the original post, the iOS Shotcuts app is simply interpreting the response as "data".

If anyone can explain what additional headers we can try to add to the GET request, I am all ears. I have already tried adding "requestContentType" with value of "application/json", but no change in behavior.

I am currently simply trying to display the response for the simple get Devices using the following Local endpoint command

http://192.168.1.143/apps/api/[my app id]/devices?access_token=[my token]

which returns as follows in my Chrome Browser on my desktop and on Safari on my iPhone.

[
    {
        "id": "492",
        "name": "VirtualPresence",
        "label": "Dan Locative"
    },
    {
        "id": "1195",
        "name": "iOS Shortcut Switch 1",
        "label": "iOS Shortcut Switch 1"
    },
    {
        "id": "1196",
        "name": "iOS Shortcut Switch 2",
        "label": "iOS Shortcut Switch 2"
    }
]

But when I try the same inside the Shortcuts app on my iPhone, I receive the following

instead of something that I believe should look like the following from Apple's guide on using the Shortcuts app into integerate with a web API (Request your first API in Shortcuts - Apple Support)

Any assistance Hubitat can offer would be greatly appreciated!

I'm not sure how helpful this would be but below is the Tasker task that @gparra made to send the reboot with user admin turned on. It first does a HttpGet using the username and password, parses the returned cookie header (#6) to do a HttpPost that reboots the hub.

Sorry forgot to include the details for a few relevant portions.

1 Like

You're trying to use the shortcuts app to get a list of the device's? Or just issue a command to the device? Because I think it's returning the correct info for the command you're issuing. You need to add a command to the string if you want to issue a command to the device.

Right now, I am just trying to get back a JSON response that can be parsed by the Shortcuts Workflow.

Issuing commands will work just fine, as long as you don't care about the response. What we need are the responmses to create more complex Shortcut Workflows.

And when you scroll down in the response you can't tap on the devices or data block or expand it? there looks like more below your screenshot.

This might also be due to the fact that the entire response is wrapped. So, you have to go 2 levels deep before you get any header info.

I just tried it and it is returning the data, just not displaying it. If you click the share icon, you can see that all the data is there.

If you get the contents of the web page, it returns some strange header information:

26-14-12-37

1 Like

I observed this behavior as well, but it doesn't really help us any.

The "get contents of webpage" shortcut action in iOS, returns what safari would render. Since safari can't render JSON, it wraps it in some HTML to make it prettier and spits it out to the browser window (assuming this here, maybe it is being returned HTML?).

We can't really work with that output because it would require building a parser in the shortcuts app, or at least a rudimentary string splitter and then relying out that garbled output. Even then, I haven't tried it to see if after removing the HTML, if iOS can then create the dictionary/object from the remaining string.

What would make the most sense, is to examine the output of different JSON services like darksky or whatever and compare them to Hubitat and figure out why the Hubitat response is not being interpreted like JSON from other services.

My thoughts are it has something to do with a response header or a malformed response due to a user agent potentially?

Whatever it is, I think it's more likely than not to be on the Hubitat side of the equation at this moment. Again, what it is exactly, I don't know.

1 Like

I agree. That’s why I am hoping one of the Hubitat Engineers, like @patrick or @chuck.schwer can take a look to make sure that Hubitat’s Maker API is generating a standards compliant json response to an http GET. There must be some sort of a difference causing iOS’s Shortcuts app to not interpret the response correctly as json, instead of as a file.

Bumpity bump bump

1 Like

Maker API response is text/json and should be application/json and a fix has been submitted for internal testing. This might fix the issue you are seeing.

4 Likes

Thanks Patrick. I look forward to testing it.

iOS Shortcuts now receives a proper json response from the Hubitat Maker API. Thank you Hubitat for v2.0.5. Now we just need to come up with some cool shortcuts to share with each other!

3 Likes

@ogiewon just wondering if you ever figured out how to do this, including the hub login?

Not yet. I haven’t had time to work on this lately.

I would love to be able to setup Siri commands for some of my items, but i cant figure out what i need to do. For example, i have a group called Downstairs lights that I would like to use Siri to turn on and off.

How would i go about doing that with the IOS Shortcuts app or something liek Launcher?

@robert2 I was actually working on this the other day and will attempt to write up a post about this soon. If I get around to it in the next 48 hours, I'll try to tag you in it and post an update in this thread.

1 Like

@robert2 I've created a basic tutorial here: [Tutorial] How to create your own iOS shortcuts using the Maker API

Good luck!

2 Likes

Don't know if this is of help to anyone or not, but discovered something by accident.

Google Assistant is available for Iphone. when you install it it asks if you want to connect it to Siri. Then you can say "Hey Siri OK Google Turn on lights". Or whatever device you want to do. That is then one method without configureing shortcuts.

Then if you go into shortcuts to create a new one what you just did comes up as a suggestion. So just select it, rename it to whatever. Then all you say is "Hey Siri Lights On" Or whatever you named it. No need to say OK Google anymore.

Course you have to do this for all functions you want. But seems easier than trying to use links to Maker. Just my opinion.

2 Likes