Maker API and Shortcuts app for iOS

So I'm experimenting with the Maker API and the new(ish) Shortcuts app from iOS 12.

I can make the GET requests to the API but unfortunately, I can't seem to be able to parse the returned data. In a web browser I can see the returned JSON, but in the Shortcuts app it's receiving the data as some kind of file blob?

Is there some sort of header or something I need to add to get it to return in a text format? Maybe it's expecting a certain User Agent?

I'm grasping for straws here.

Any ideas are welcome!

2 Likes

Have you tried "Launcher" app instead? That app also has the ability to use on the watch, which is what I'm using it for, along with Maker, and works very well, even using the cloud API links.

@Royski I haven't tried that app.

And I should also restate, I can make shortcuts that perform the selected actions from a singular URL, but I would like to be able to hit one button and toggle the state of the Hubitat switch/light/group/etc.

To make a toggle, I first need to read the current state but I can't due to the above error.

1 Like

Ah, I did a workaround for this one.

First I created Virtual Buttons in HE, then assigned rules to those buttons to "toggle".
Then used the Virtual Buttons with the API :slight_smile:

Hmm okay. Did you use Rule Machine for those? That's one part of Hubitat that I haven't dived into at all yet.

If someone else happens to know why the above is happening, feel free to add it :grimacing:

No, I used Advanced Button Controller.

Although there's no reason you cant use the inbuilt Button Controllers app either.
I just wanted all my button rules in one place. I think the issue here there is no "toggle" option in the API for switches, so that has to be more rules based. This was my original sticking point until I thought of virtual buttons.

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