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?
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.
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.
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.
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!
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
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.
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.
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.
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.
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.
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!