iOS 12 Shortcuts: Fetch Data with GET and POST APIs

The iOS 12 Shortcuts app fully supports fetching data from web APIs using both GET and POST requests. By leveraging the built-in "Get Contents of URL" action, users can interact with RESTful APIs, authenticate with services, pass parameters, and parse returned data directly on an iPhone or iPad. This guide explains how iOS 12 Shortcuts handles these network requests and how to configure them for API integration.

The "Get Contents of URL" Action

The foundation for web requests in iOS 12 Shortcuts is the "Get Contents of URL" action. Found under the Web category, this action transforms the Shortcuts app from a basic task runner into a capable API client. When added to a workflow, it automatically detects the input URL and expands to offer advanced configuration options for HTTP methods, headers, and request payloads.

Configuring a GET Request

GET requests are used to retrieve data from an API without modifying the server's state. To set up a GET request in iOS 12:

  1. Add a URL action to your shortcut and enter the target API endpoint. If the endpoint requires query parameters, append them directly to the URL string (for example, https://api.example.com/data?user=123).
  2. Add the Get Contents of URL action immediately following the URL action.
  3. Tap Advanced (or the details arrow).
  4. Ensure the Method is set to GET.
  5. If the API requires authentication or custom headers (such as an Authorization bearer token or Accept: application/json), tap Headers and add the required key-value pairs.

When executed, the action sends the request and passes the server's response to the next step in the shortcut.

Configuring a POST Request

POST requests are used to send data to an API, such as submitting a form, uploading data, or triggering a remote webhook. To configure a POST request:

  1. Add a URL action containing the API endpoint.
  2. Add the Get Contents of URL action and expand its advanced options.
  3. Change the Method from GET to POST.
  4. In the Headers section, define any necessary headers (such as Content-Type).
  5. Choose the Request Body format:
    • JSON: Allows you to build structured key-value pairs (strings, numbers, booleans, arrays, or nested dictionaries) directly inside the action. Shortcuts automatically formats the payload and sets the appropriate JSON headers.
    • Form: Sends data as standard form-encoded key-value pairs (application/x-www-form-urlencoded).
    • File: Allows you to attach an image, document, or raw data passed from a previous step in the shortcut.

Handling and Parsing API Responses

iOS 12 Shortcuts natively understands JSON responses. Once the "Get Contents of URL" action finishes executing:

  • Get Dictionary from Input: If the API returns a JSON object, use this action to evaluate the response as structured data.
  • Get Dictionary Value: Use this action to extract specific fields by key name. You can chain multiple dictionary actions together to traverse nested JSON objects or arrays.
  • Display Results: The parsed data can then be passed to native iOS actions, such as Show Alert, Quick Look, Create Note, or sent via Messages.

Through these features, iOS 12 provides a robust environment for communicating with modern web services without requiring third-party networking tools.