![](https://help.apple.com/assets/645D5D228BE0233D28263F4B/645D5D248BE0233D28263F53/en_US/fbd8d40651fff19a46e7aaedd4cb1b09.png)
Request your first API in Shortcuts on Mac
To request your first API, you create the URL that points at the API “endpoint” that you want to talk to, and then pass that URL to the Get Contents of URL action. When the shortcut is run, this action makes the API request.
![An API request that contains a URL action pointing at the API endpoint, followed by a Get Contents of URL action.](https://help.apple.com/assets/645D5D228BE0233D28263F4B/645D5D248BE0233D28263F53/en_US/a164771b90952f39580c229e8d8765f7.png)
Build the API request
Typicode’s endpoint requires a URL request to be formatted this way:
https://jsonplaceholder.typicode.com/[RESOURCE]
The text in brackets is the resource you would like to access. Typicode provides many different examples for testing requests. This example will be using https://jsonplaceholder.typicode.com/users
to request a list of users.
In the Shortcuts app
on your Mac, add the request to the URL.
The
users
request will return a list of users.You can narrow your search by specifying a specific user by the id:
https://jsonplaceholder.typicode.com/users/6
. This will return the user whose id is 6.Most APIs allow for queries using the following format:
https://jsonplaceholder.typicode.com/users?username=Bret
. The “?” starts the query, which searches for items using key/value pairs. In this example, the query?username=Bret
searches for a user whose username is Bret.Check your API’s documentation for supported searches and queries.
Perform the API request with the Get Contents of URL action
In the Shortcuts app
on your Mac, click Show More in the Get Contents of URL action.
The following options for the types of API requests you can make become available:
GET
allows you to retrieve data.POST
allows you to create new data.PUT
allows you to update data by replacing it.PATCH
allows you to update data by modifying it.DELETE
allows you to remove an object specified in the URL request.
For this example, use a
GET
request to retrieve data from the Typicode API.Now that the URL action has your request and the Get Contents of URL action is set up to
GET
data, you’re ready to make the API request.Note: When the Get Contents of URL action is switched to
POST
,PUT
, orPATCH
, a new parameter called Request Body is added. Request Body allows you to send JSON, a Form, or a File to the API as part of your request. This lets you enter new data manually or by using variables so you can send the data to the API for creating, replacing, or modifying an entry.To test the shortcut, click
.
Upon first look, the API appears to return a mess of text. This data is encoded in JSON, which stands for JavaScript Object Notation.
To learn about working with JSON and to continue with the Typicode API example, see Intro to using JSON in Shortcuts on Mac.