![](https://help.apple.com/assets/5B9014F10946229C37C593B4/5B9014F50946229C37C593C7/en_AU/c10e8a839dc838a25d0feb0e9e428a0a.png)
Request your first API in Shortcuts
To request your first API, you create the URL that points at the API “end point” that you want to talk to, then you pass that URL to the Get Contents of URL action. When the shortcut is run, this action makes the API request.
![A Dark Sky API request that contains a Text action with a secret API key, followed by a URL action pointing at the API end point using a Secret Key variable, followed by a Get Contents of URL action.](https://help.apple.com/assets/5B9014F10946229C37C593B4/5B9014F50946229C37C593C7/en_AU/d4a742722dbbd42f9d384427c726e1c7.png)
Build the API request
Dark Sky’s Forecast end point requires an URL request to be formatted as such:
https://api.darksky.net/forecast/[YOUR_SECRET_KEY]/[LAT],[LONG]
The text in brackets will be filled out with an API key and the location you want forecast data for.
In the Shortcuts app, place your API key from Dark Sky in the first Text action that is passed to the URL action as a variable. The
LAT
andLONG
values are already set to37.8267
and-122.4233
, which are the coordinates for Alcatraz Island in San Francisco. (You can change those values to a different location.)Try using the Get Current Location action and placing it as a Magic Variable set to Latitude and Longitude, in the URL action, to get local weather data whenever you run the shortcut.
Perform the API request with the Get Contents of URL action
In the shortcut editor of the Shortcuts app, set Get Contents of URL to Advanced.
The following options for the types of API requests you can make become available:
GET
allows you to retrieve data from an API to read.POST
allows you to create new data.PUT
andPATCH
allow you to update data by replacing or modifying it, respectively.DELETE
allows you to remove an object specified in the URL request.
For this example, use a
GET
request to retrieve data from the Dark Sky 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.Tap
to test the shortcut (the Quick Look action in the shortcut allows you to preview the data that the API returns).
Congratulations, you’ve made your first API request using Shortcuts.
At first glance, the API appears to return a lot of strangely formatted text. On closer inspection, you can see that text contains weather forecast information. This weather data is encoded in JSON, which stands for JavaScript Object Notation.
To learn about working with JSON and to continue with the Dark Sky API example, see About using JSON in Shortcuts.