Skip to main content

Overview

The NYTimes API prefab returns data from the Top Stories on the NYT homepage, including their headlines, bylines, and multimedia URLs. Typically, the response values are displayed in text or image elements. Important Note About Using API Keys in Play If you are using any sensitive API keys in your Fetch nodes, these keys are exposed and can be seen by users of your prototypes and apps.
  • For prototypes, make sure you have your App Clip’s password protected and that you are sending to trusted sources.
  • For Export to Xcode, we recommend you store your keys server side using services like Firebase Cloud Functions, Supabase Edge Functions, or AWS Lambda for secure request handling.

Prefab Controls

Fetch Onload

Choose if the Fetch API should occur immediately when the page loads.

API Key

Enter your API key for the NYT API. You can create an API key here.

API Loading

Add actions to fire while the API loads.

API Response

Add actions to fire when the API responds (loads successfully).

API Error

Add actions to fire if the API fails to load.

Spinner

Target an activity indicator element to communicate the API’s loading status.

Get API Data

To get specific data values from the NYTimes API, use the API’s associated keys. Read the API documentation for more information on keys. Get API Data
Loop.item.asComponent(Cell).#title = #response.key("results").key(Loop.index).key("title")
  • Variable Expression:
    • Loop.item—Loop through each item in the Loop action
    • asComponent—Casts item as a component to access component variables
    • .#title—The component variable for title
  • Value Expression:
    • #response—The dictionary variable for the API response
    • .key(“results”)—The API key to access the results list of top stories
    • .key(“results”)—The API key to loop through all articles in the results list
    • .key(“title”)—The API key to access an individual story’s title

Populate Data

To display the API’s data, you can output the saved component variable (title, by, caption, etc.) to a text or images element. Populate Data

Resources

NYTimes API Learn Project

I