How to Call a Serverless Function Or Web API Periodically With iOS Shortcuts
Automate your tasks using the power of shortcuts in iOS

đ Tech Lead / Lead Developer đ„ Writing about CSS, JavaScript, Typescript, Angular, Vue.js, Nuxt.js, Serverless functions, and a lot more web-related topics. https://byrayray.dev/
Running a Serverless function or Web API every periodically can be done in so many ways. But today, I want to show you a free option if you have an iPhone or iPad. It is the Shortcut app.
The Shortcut app is available to every iPhone, iPad, or iPod touch running iOS 13.1 and higher. If you donât own an Apple device, scroll down to the alternative ways to do the same via a different service.
Running Time-Based Actions
I donât know about you, but I feel the need to run an API or serverless function once a day or an hour every time I work on a side project.
But I donât particularly appreciate setting up a cron job. Since I run all my applications on Netlify, I donât have any place to do that.
So I thought, I saw that I could call a Web API via the iOS Shortcuts app. Letâs automate that!
My use case
Iâm building a dashboard with Angular, Angular Material, Serverless functions, and Upstash (a serverless database for Redis). For that dashboard, Iâm using the data from âOur World In Data,â which is open-source.
Since loading a large amount of data from their repository takes a very long time, I thought letâs save that into Redis via Upstash, so the data loads faster.
Updating the information is going to be time-intensive, so my goal is to create a serverless function for Netlify and call it every day with the Shortcuts app.
PS: Iâm running that for a few days right now, and itâs a total blessing.
For instance, checkout can find my serverless function below, to get an idea of how Iâve created it:
I wonât dive into the creation of serverless functions in this post, but If you want to learn more about serverless functions and how to build them, check the links below.
How To Automatically Call a Web API Periodically
1. Setup Shortcut
First, letâs open the Shortcuts app and tap the + sign to create a new shortcut.

Click on âAdd Actionâ and search for âURLâ, click it and add the API URL you want to call.

Iâve pasted in a URL to an API. To choose what type of request we want to do, we have to tap on âGet Contents of URLâ (if itâs not visible on your device, your can search for it in the input field on the bottom).
You can pick GET, POST, PUT, PATCH, and DELETE. If you want, you can send some headers when needed.
In the meantime, try creating the request by pressing the âPlayâ button on the bottom.

After making the request, we want to have a notification that tells us when itâs done. Tap the bottom input field for searching âShow Notificationâ, when found press it.
You can type here anything you like. For this example, Iâve done âReceived Posts URLâ. URL is, in this case, the URL weâve set at the top.

Letâs test our shortcut by pressing the âPlayâ button at the bottom:

Automate shortcut
Now that we demonstrated that our shortcut works, we can automate it to run it daily, weekly, or anything else.
Open the automation tap, which you can find at the bottom of your home screen of the Shortcuts app, and click âCreate Personal Automationâ.

Click on the âTime of Dayâ and select when you want to run this automation. The choice is yours!

Press âNextâ at the top and click âAdd Actionâ. Now find the âRun Shortcutâ action and press it.

Now we have to select our âCall Web APIâ shortcut we made earlier. Press âShortcutâ and search for your shortcut and press it.

In my case, this automation will be performed daily at 15:10, which is so awesome!

The best thing about using the Shortcuts app is everything runs locally on my device. Just call âHi Siri, Call Web API,â and the shortcut will do it!
Github Actions as Alternative For Automating Web API Calls
If you donât own an Apple device, you canât use the Shortcuts app. Iâm not familiar enough with Android for offering the same functionality, but I think Github Actions is an excellent alternative for automating your Web API or Serverless function call.
Since Github Actions offers so much more than just automating Web API calls, I highly recommend checking the tutorial âRun your Github Actions workflow on a scheduleâ by Jason Etcovitch.
Conclusion
There are probably many other ways to automate Web API or Serverless function calls besides using iOS Shortcuts or Github Actions. But the most important is that you use what you find the easiest to use.
For me, doing it on my device for free is very importantâââthatâs why Iâve used the Shortcuts app. If you have other suggestions, please share them. I love to add them to the post as well
Happy coding and automating.
For more Productivity tips with the Shortcuts app, check âAmazing Productivity Shortcuts for Your iPhoneâ from Manish Jain
Thanks!
I hope you learned something new or are inspired to create something new after reading this story! đ€ If so, consider subscribing via email (scroll to the top of this page) or follow me here on Hashnode.
Did you know that you can create a Developer blog like this one, yourself? It's entirely for free. đđ°đđ„łđ„
If I left you with questions or something to say as a response, scroll down and type me a message. Please send me a DM on Twitter @DevByRayRay when you want to keep it private. My DM's are always open đ






