Create contacts from data in Shortcuts on iPhone or iPad
You can use data from an API to create calendar events, contacts, notes and more. This example demonstrates how to create contacts from the Typicode API. Creating contacts using the Add to Contacts action requires a first and last name. You will need to use the Split Text action to separate the user’s names in the API data.
Split text into a list
In the Shortcuts app on your iOS or iPadOS device, add a Repeat with Each action after the Get Contents of URL action.
Add a Get Dictionary Value action inside the Repeat with Each action, then set the key to
Add a Split Text action after the Get Dictionary Value action, then set the input to the Dictionary Value and the delimiter to Spaces.
The Split Text action will create a list of items based on the delimiter. In this case, the contact’s first name is the first item in the list and their surname is the last item in the list.
Add two Get Item from List actions. Set the first action to get the First Item and the second action to get the Last Item. For both actions, use a magic variable of the output of the Split Text action.
Create a contact
In the Shortcuts app on your iOS or iPadOS device, add a Get Dictionary Value action after the Split Text actions, then set the key to
phoneand the Dictionary to the Repeat Item.
Add an Add New Contact action after the last Get Dictionary Value action.
At this point you have the following actions:
Get Contents of URL
Repeat with Each
Get Value for name in Repeat Item
Split Dictionary Value by Spaces
Get First Item from Split Text
Get Last Item from Split Text
Get Value for phone in Repeat Item
In the Add Contact action, set the First Name to the Magic Variable of the first Split Text action, and the Last Name to the Magic Variable of the second Split Text action.
From the Show More menu, set Phone Number to the Magic Variable of the Get Value for phone action.
Turn off Show Compose Sheet.
Tap to run the shortcut and create contacts from the API.
WARNING: Running this shortcut will create contacts on your device. Add a note to the contacts to make removing them easier.