Sending and automating arbitrary HTTP requests with the iOS Shortcuts app
I wrote a shortcut in the iOS beta so that when a device hits 100% charge it sends a Pushover notification to all my devices that it’s charged. Phone almost dead and want to leave when it’s charged? Plug it in and forget about it. you’ll be notified when it’s done. it is awesome.
I was immediately intrigued because in that tweet alone there are 2 things that I didn’t know you could do easily on iOS:
- Detect a fully charged battery and do something (what else can it detect?)
- Send a Pushover notification automatically (what else can it do?)
If you read the app description you may think it requires Siri, but rest assured it doesn’t. You can use the Shortcuts app without having Siri enabled (like myself, I never use Siri).
Arbitrary HTTP Requests
So, before we get to detecting the battery level, we need to figure out how to send HTTP requests. In the Shortcuts app, create a new shortcut and proceed to add an action. For HTTP requests, we’ll need the
Get Contents of URL action.
By the way, to get a sense of all the stuff you can do, just search for
Getand scroll down. It’s a loooong way down.
Once we have the
Get Contents of URL action, we can click on the
URL and fill it in. For this example, we’re using the Pushover API but you can of course use whatever your heart desires.
Then to get to the actual request, clicking
Show More will reveal all the configuration possible. By default the
GET method is selected, but clicking on that will show you all the other methods you’d expect:
DELETE, and even options to prompt the user or accept a shortcut input. For Pushover, we need
If you’re wondering where
HEADis, that uses a separate action called
Get Headers of URL.
We don’t need extra headers, so we’ll skip straight to the JSON request body. Clicking on
Add new field will prompt us for the type of field we want to add, in this example it’s always text.
To send a notification we need at least the
message fields to be present. So we fill those out and then we’re done with creating the HTTP request. Save the shortcut by clicking on
Next, giving it an appropriate name, and testing it out by clicking on it. Bam! HTTP requests done.
Back at the main screen of the Shortcuts app, click on the Automation tab and create a new Personal Automation. Scroll down until you find the
Battery Level one. Select it, set it to
Equals 100% and click
Then, we’re going to add the shortcut we just made as an action. Search for
Run Shortcut and select the custom one we just made. Click on
Next again, and it should give you an overview of what will happen and when.
In here we also want to make sure
Ask Before Running is turned off, otherwise it won’t automatically run whenever the battery reaches 100%. Once that’s all done, we now have an automated system set up to send a Pushover notification when the battery reaches 100%.
Of course, this is only scratching the surface of what’s possible with these shortcuts and automations. I can imagine there are people that have very large and complex things setup,especially once you start adding in other devices.
Thanks for reading! 💗