Syncing workout data from iOS to Statamic
In my post <activity-graph> (Web) Component I described my New Year's resolution to do some kind of workout 5 times a week and my journey to visualize it with the following graph:
2024 | 2025 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
January | February | March | April | May | June | July | August | September | October | November | December | January | |||||||||||||||||||||||||||||||||||||||||
Monday | 01/01/2024 – Activities: 1 | 01/08/2024 – Activities: 1 | 01/15/2024 – Activities: 1 | 01/22/2024 – Activities: 1 | 01/29/2024 – Activities: 1 | 02/05/2024 – Activities: 0 | 02/12/2024 – Activities: 1 | 02/19/2024 – Activities: 0 | 02/26/2024 – Activities: 0 | 03/04/2024 – Activities: 1 | 03/11/2024 – Activities: 0 | 03/18/2024 – Activities: 0 | 03/25/2024 – Activities: 0 | 04/01/2024 – Activities: 0 | 04/08/2024 – Activities: 1 | 04/15/2024 – Activities: 1 | 04/22/2024 – Activities: 1 | 04/29/2024 – Activities: 0 | 05/06/2024 – Activities: 0 | 05/13/2024 – Activities: 0 | 05/20/2024 – Activities: 0 | 05/27/2024 – Activities: 1 | 06/03/2024 – Activities: 1 | 06/10/2024 – Activities: 0 | 06/17/2024 – Activities: 0 | 06/24/2024 – Activities: 1 | 07/01/2024 – Activities: 0 | 07/08/2024 – Activities: 0 | 07/15/2024 – Activities: 0 | 07/22/2024 – Activities: 0 | 07/29/2024 – Activities: 0 | 08/05/2024 – Activities: 0 | 08/12/2024 – Activities: 0 | 08/19/2024 – Activities: 0 | 08/26/2024 – Activities: 0 | 09/02/2024 – Activities: 0 | 09/09/2024 – Activities: 1 | 09/16/2024 – Activities: 1 | 09/23/2024 – Activities: 1 | 09/30/2024 – Activities: 0 | 10/07/2024 – Activities: 0 | 10/14/2024 – Activities: 0 | 10/21/2024 – Activities: 0 | 10/28/2024 – Activities: 0 | 11/04/2024 – Activities: 0 | 11/11/2024 – Activities: 0 | 11/18/2024 – Activities: 0 | 11/25/2024 – Activities: 0 | 12/02/2024 – Activities: 0 | 12/09/2024 – Activities: 0 | 12/16/2024 – Activities: 0 | 12/23/2024 – Activities: 0 | 12/30/2024 – Activities: 0 |
Tuesday | 01/02/2024 – Activities: 0 | 01/09/2024 – Activities: 1 | 01/16/2024 – Activities: 1 | 01/23/2024 – Activities: 0 | 01/30/2024 – Activities: 1 | 02/06/2024 – Activities: 1 | 02/13/2024 – Activities: 0 | 02/20/2024 – Activities: 2 | 02/27/2024 – Activities: 1 | 03/05/2024 – Activities: 0 | 03/12/2024 – Activities: 2 | 03/19/2024 – Activities: 1 | 03/26/2024 – Activities: 1 | 04/02/2024 – Activities: 1 | 04/09/2024 – Activities: 0 | 04/16/2024 – Activities: 0 | 04/23/2024 – Activities: 0 | 04/30/2024 – Activities: 1 | 05/07/2024 – Activities: 1 | 05/14/2024 – Activities: 0 | 05/21/2024 – Activities: 1 | 05/28/2024 – Activities: 1 | 06/04/2024 – Activities: 0 | 06/11/2024 – Activities: 0 | 06/18/2024 – Activities: 0 | 06/25/2024 – Activities: 0 | 07/02/2024 – Activities: 0 | 07/09/2024 – Activities: 1 | 07/16/2024 – Activities: 0 | 07/23/2024 – Activities: 0 | 07/30/2024 – Activities: 1 | 08/06/2024 – Activities: 1 | 08/13/2024 – Activities: 1 | 08/20/2024 – Activities: 0 | 08/27/2024 – Activities: 1 | 09/03/2024 – Activities: 0 | 09/10/2024 – Activities: 1 | 09/17/2024 – Activities: 1 | 09/24/2024 – Activities: 0 | 10/01/2024 – Activities: 0 | 10/08/2024 – Activities: 0 | 10/15/2024 – Activities: 0 | 10/22/2024 – Activities: 0 | 10/29/2024 – Activities: 0 | 11/05/2024 – Activities: 0 | 11/12/2024 – Activities: 0 | 11/19/2024 – Activities: 0 | 11/26/2024 – Activities: 0 | 12/03/2024 – Activities: 0 | 12/10/2024 – Activities: 0 | 12/17/2024 – Activities: 0 | 12/24/2024 – Activities: 0 | 12/31/2024 – Activities: 0 |
Wednesday | 01/03/2024 – Activities: 0 | 01/10/2024 – Activities: 0 | 01/17/2024 – Activities: 0 | 01/24/2024 – Activities: 2 | 01/31/2024 – Activities: 1 | 02/07/2024 – Activities: 0 | 02/14/2024 – Activities: 1 | 02/21/2024 – Activities: 0 | 02/28/2024 – Activities: 1 | 03/06/2024 – Activities: 0 | 03/13/2024 – Activities: 1 | 03/20/2024 – Activities: 0 | 03/27/2024 – Activities: 0 | 04/03/2024 – Activities: 0 | 04/10/2024 – Activities: 1 | 04/17/2024 – Activities: 1 | 04/24/2024 – Activities: 1 | 05/01/2024 – Activities: 0 | 05/08/2024 – Activities: 1 | 05/15/2024 – Activities: 1 | 05/22/2024 – Activities: 1 | 05/29/2024 – Activities: 1 | 06/05/2024 – Activities: 0 | 06/12/2024 – Activities: 0 | 06/19/2024 – Activities: 0 | 06/26/2024 – Activities: 0 | 07/03/2024 – Activities: 1 | 07/10/2024 – Activities: 1 | 07/17/2024 – Activities: 0 | 07/24/2024 – Activities: 0 | 07/31/2024 – Activities: 0 | 08/07/2024 – Activities: 0 | 08/14/2024 – Activities: 1 | 08/21/2024 – Activities: 0 | 08/28/2024 – Activities: 1 | 09/04/2024 – Activities: 0 | 09/11/2024 – Activities: 1 | 09/18/2024 – Activities: 0 | 09/25/2024 – Activities: 1 | 10/02/2024 – Activities: 1 | 10/09/2024 – Activities: 0 | 10/16/2024 – Activities: 0 | 10/23/2024 – Activities: 0 | 10/30/2024 – Activities: 0 | 11/06/2024 – Activities: 0 | 11/13/2024 – Activities: 0 | 11/20/2024 – Activities: 0 | 11/27/2024 – Activities: 0 | 12/04/2024 – Activities: 0 | 12/11/2024 – Activities: 0 | 12/18/2024 – Activities: 0 | 12/25/2024 – Activities: 0 | 01/01/2025 – Activities: 0 |
Thursday | 01/04/2024 – Activities: 1 | 01/11/2024 – Activities: 1 | 01/18/2024 – Activities: 2 | 01/25/2024 – Activities: 1 | 02/01/2024 – Activities: 0 | 02/08/2024 – Activities: 1 | 02/15/2024 – Activities: 2 | 02/22/2024 – Activities: 0 | 02/29/2024 – Activities: 1 | 03/07/2024 – Activities: 1 | 03/14/2024 – Activities: 0 | 03/21/2024 – Activities: 1 | 03/28/2024 – Activities: 1 | 04/04/2024 – Activities: 0 | 04/11/2024 – Activities: 0 | 04/18/2024 – Activities: 0 | 04/25/2024 – Activities: 0 | 05/02/2024 – Activities: 1 | 05/09/2024 – Activities: 1 | 05/16/2024 – Activities: 0 | 05/23/2024 – Activities: 1 | 05/30/2024 – Activities: 1 | 06/06/2024 – Activities: 1 | 06/13/2024 – Activities: 1 | 06/20/2024 – Activities: 1 | 06/27/2024 – Activities: 1 | 07/04/2024 – Activities: 0 | 07/11/2024 – Activities: 1 | 07/18/2024 – Activities: 0 | 07/25/2024 – Activities: 0 | 08/01/2024 – Activities: 1 | 08/08/2024 – Activities: 0 | 08/15/2024 – Activities: 0 | 08/22/2024 – Activities: 1 | 08/29/2024 – Activities: 0 | 09/05/2024 – Activities: 0 | 09/12/2024 – Activities: 0 | 09/19/2024 – Activities: 1 | 09/26/2024 – Activities: 1 | 10/03/2024 – Activities: 0 | 10/10/2024 – Activities: 0 | 10/17/2024 – Activities: 0 | 10/24/2024 – Activities: 0 | 10/31/2024 – Activities: 0 | 11/07/2024 – Activities: 0 | 11/14/2024 – Activities: 0 | 11/21/2024 – Activities: 0 | 11/28/2024 – Activities: 0 | 12/05/2024 – Activities: 0 | 12/12/2024 – Activities: 0 | 12/19/2024 – Activities: 0 | 12/26/2024 – Activities: 0 | 01/02/2025 – Activities: 0 |
Friday | 01/05/2024 – Activities: 1 | 01/12/2024 – Activities: 1 | 01/19/2024 – Activities: 0 | 01/26/2024 – Activities: 0 | 02/02/2024 – Activities: 1 | 02/09/2024 – Activities: 1 | 02/16/2024 – Activities: 0 | 02/23/2024 – Activities: 1 | 03/01/2024 – Activities: 1 | 03/08/2024 – Activities: 0 | 03/15/2024 – Activities: 1 | 03/22/2024 – Activities: 1 | 03/29/2024 – Activities: 1 | 04/05/2024 – Activities: 1 | 04/12/2024 – Activities: 1 | 04/19/2024 – Activities: 1 | 04/26/2024 – Activities: 1 | 05/03/2024 – Activities: 1 | 05/10/2024 – Activities: 0 | 05/17/2024 – Activities: 1 | 05/24/2024 – Activities: 1 | 05/31/2024 – Activities: 1 | 06/07/2024 – Activities: 1 | 06/14/2024 – Activities: 0 | 06/21/2024 – Activities: 1 | 06/28/2024 – Activities: 0 | 07/05/2024 – Activities: 0 | 07/12/2024 – Activities: 1 | 07/19/2024 – Activities: 0 | 07/26/2024 – Activities: 0 | 08/02/2024 – Activities: 0 | 08/09/2024 – Activities: 1 | 08/16/2024 – Activities: 1 | 08/23/2024 – Activities: 1 | 08/30/2024 – Activities: 1 | 09/06/2024 – Activities: 1 | 09/13/2024 – Activities: 1 | 09/20/2024 – Activities: 0 | 09/27/2024 – Activities: 0 | 10/04/2024 – Activities: 0 | 10/11/2024 – Activities: 0 | 10/18/2024 – Activities: 0 | 10/25/2024 – Activities: 0 | 11/01/2024 – Activities: 0 | 11/08/2024 – Activities: 0 | 11/15/2024 – Activities: 0 | 11/22/2024 – Activities: 0 | 11/29/2024 – Activities: 0 | 12/06/2024 – Activities: 0 | 12/13/2024 – Activities: 0 | 12/20/2024 – Activities: 0 | 12/27/2024 – Activities: 0 | 01/03/2025 – Activities: 0 |
Saturday | 01/06/2024 – Activities: 1 | 01/13/2024 – Activities: 0 | 01/20/2024 – Activities: 1 | 01/27/2024 – Activities: 1 | 02/03/2024 – Activities: 0 | 02/10/2024 – Activities: 0 | 02/17/2024 – Activities: 0 | 02/24/2024 – Activities: 1 | 03/02/2024 – Activities: 1 | 03/09/2024 – Activities: 2 | 03/16/2024 – Activities: 0 | 03/23/2024 – Activities: 1 | 03/30/2024 – Activities: 1 | 04/06/2024 – Activities: 1 | 04/13/2024 – Activities: 1 | 04/20/2024 – Activities: 0 | 04/27/2024 – Activities: 1 | 05/04/2024 – Activities: 1 | 05/11/2024 – Activities: 0 | 05/18/2024 – Activities: 2 | 05/25/2024 – Activities: 1 | 06/01/2024 – Activities: 0 | 06/08/2024 – Activities: 1 | 06/15/2024 – Activities: 2 | 06/22/2024 – Activities: 1 | 06/29/2024 – Activities: 1 | 07/06/2024 – Activities: 2 | 07/13/2024 – Activities: 0 | 07/20/2024 – Activities: 0 | 07/27/2024 – Activities: 0 | 08/03/2024 – Activities: 1 | 08/10/2024 – Activities: 1 | 08/17/2024 – Activities: 1 | 08/24/2024 – Activities: 1 | 08/31/2024 – Activities: 2 | 09/07/2024 – Activities: 2 | 09/14/2024 – Activities: 0 | 09/21/2024 – Activities: 0 | 09/28/2024 – Activities: 0 | 10/05/2024 – Activities: 0 | 10/12/2024 – Activities: 0 | 10/19/2024 – Activities: 0 | 10/26/2024 – Activities: 0 | 11/02/2024 – Activities: 0 | 11/09/2024 – Activities: 0 | 11/16/2024 – Activities: 0 | 11/23/2024 – Activities: 0 | 11/30/2024 – Activities: 0 | 12/07/2024 – Activities: 0 | 12/14/2024 – Activities: 0 | 12/21/2024 – Activities: 0 | 12/28/2024 – Activities: 0 | 01/04/2025 – Activities: 0 |
Sunday | 01/07/2024 – Activities: 1 | 01/14/2024 – Activities: 1 | 01/21/2024 – Activities: 1 | 01/28/2024 – Activities: 0 | 02/04/2024 – Activities: 1 | 02/11/2024 – Activities: 2 | 02/18/2024 – Activities: 1 | 02/25/2024 – Activities: 1 | 03/03/2024 – Activities: 0 | 03/10/2024 – Activities: 1 | 03/17/2024 – Activities: 1 | 03/24/2024 – Activities: 1 | 03/31/2024 – Activities: 1 | 04/07/2024 – Activities: 2 | 04/14/2024 – Activities: 1 | 04/21/2024 – Activities: 2 | 04/28/2024 – Activities: 1 | 05/05/2024 – Activities: 1 | 05/12/2024 – Activities: 2 | 05/19/2024 – Activities: 1 | 05/26/2024 – Activities: 0 | 06/02/2024 – Activities: 0 | 06/09/2024 – Activities: 2 | 06/16/2024 – Activities: 2 | 06/23/2024 – Activities: 2 | 06/30/2024 – Activities: 2 | 07/07/2024 – Activities: 2 | 07/14/2024 – Activities: 1 | 07/21/2024 – Activities: 0 | 07/28/2024 – Activities: 0 | 08/04/2024 – Activities: 2 | 08/11/2024 – Activities: 2 | 08/18/2024 – Activities: 1 | 08/25/2024 – Activities: 2 | 09/01/2024 – Activities: 0 | 09/08/2024 – Activities: 2 | 09/15/2024 – Activities: 1 | 09/22/2024 – Activities: 2 | 09/29/2024 – Activities: 1 | 10/06/2024 – Activities: 0 | 10/13/2024 – Activities: 0 | 10/20/2024 – Activities: 0 | 10/27/2024 – Activities: 0 | 11/03/2024 – Activities: 0 | 11/10/2024 – Activities: 0 | 11/17/2024 – Activities: 0 | 11/24/2024 – Activities: 0 | 12/01/2024 – Activities: 0 | 12/08/2024 – Activities: 0 | 12/15/2024 – Activities: 0 | 12/22/2024 – Activities: 0 | 12/29/2024 – Activities: 0 | 01/05/2025 – Activities: 0 |
While the whole article was about how to create this component, I didn't cover how to get the data into Statamic - but I will now.
Part 1: Finding an appropriate workout app
In my previous attempts to improve my fitness, I enjoyed using "Runtastic Results", which became "Adidas Training", which unfortunately was deprecated earlier this year. I tried Apple Fitness+, but their video format with music drove me crazy. After trying many other apps, I finally settled on [Seven by Perigee] (https://seven.app) for the following reasons
- concept (exercise, pause, exercise, pause...)
- simple, animated instructions
- appropriate training plans + challenges
- customizable workouts
- no built-in music
Part 2: Getting data from Apple Health with Shortcuts
Seven stores all of its training data in Apple Health – and I expected to be able to grab thata data with an iOS Shortcut using the "Find Health Samples" action. Actually, there's a huge list of data you can get from the Health app, from "Abdominal Crimps" to "Dry Skin" to "Zinc". But apparently there's no way to get the training data I need... so I had to buy the app Toolbox Pro, which offers a bunch of new actions – including "Get workouts from Health". 🙈
After some low code wrangling, I was finally able to set up a working filter, populate a dictionary and prepare my final step: POSTing the data to my website. (You can download the final Shortcut from iCloud.)
Part 3: Setting up an API endpoint
My website is powered by Statamic which is based on Laravel. To get my data into it, I did the following:
- Set up a global blueprint (activity.yaml) with a replicator containing a key/value pair, where the key is the date of my workout and the value is its ID.
- Create a
/update-trainings
API route (api.php) that calls the TrainingController. - The
TrainingController
analyzes and optimizes the data (e.g. adjust late night trainings to count for the day before) and calls... - ...RefreshCacheJob, which I set up to refresh the static cache of provided pages in a background job, in this case to refresh the relevant blog articles which contain the component.
This endpoint could now be called from the Shortcut containing the correct data (see screenshot above).
Part 4: Semi-automating the sync
With iOS you can set up automations – and I wanted to synchronize the data on a daily basis. Unfortunately, I was confronted with an unfortunate message:
Apparently Toolbox Pro is not able to get the data when the screen is locked.
Luckily I had a trick: My daughter (3 years old) often does the workout with me in slight variations. She is always in charge of pressing the big button to start the workout - and now I have given her another important task: to press the big red button on the home screen at the end of the workout to start the shortcut. Since kids love any chance to press things on touch devices, I'm 100% sure my data will be synchronized often enough. 👨👧
Conclusion
While I like low code, struggling with the Shortcuts interface, having to buy an additional app to get my workout data AND not being able to fully automate the sync feels weird. In comparison, setting up the Laravel API for my website was really fun and I'm pretty sure more APIs will follow 😊.
By the way: This is the first blog post I'm publishing with my new automated OpenGraph image setup, which I'll be writing about soon – follow me on Mastodon or via RSS to be informed when it's published.