Sending and automating arbitrary HTTP requests with the iOS Shortcuts app


The other day I saw a tweet by kvanh that mentioned sending a Pushover notification when their device was fully charged.

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:

Unfortunately kvanh doesn’t mention exactly what they used to do this, but that’s okay since after some searching around I found the Shortcuts app. Which can do the aforementioned things, and a ton more (like seriously, there is so much stuff you can do in it. Like run JavaScript or even connect to a server via SSH and run a script, crazy).

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 Get and 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: POST, PUT, PATCH, DELETE, and even options to prompt the user or accept a shortcut input. For Pushover, we need POST.

If you’re wondering where HEAD is, 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 token, user and 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.

Creating the shortcut

Automating It

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 Next.

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%.

Creating the automation

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.

Discuss this post on Tildes or on Mastodon.

Thanks for reading! 💗