Home Manual Tools Resources About Contact

Using the NPR API

Web managers, this guide walks you through implementing the NPR API. Possible uses for the NPR API:

  • Use NPR reports as related stories within your local reports
  • Use crisis headlines and story summaries within a crisis information page
  • Display NPR headlines on your homepage sidebar

What is it?

Last year, National Public Radio introduced their API, or Application Programming Interface. NPR describes the API as a way for two computer applications to talk to each other in a common language that they both understand. NPR’s API essentially provides a way for your station’s website to get NPR stories in a predictable, flexible and powerful way. The content that is available includes audio from most NPR programs as well as text, images and other web-only content.

For emergency coverage, the NPR API can provide stations with a way to integrate national and international coverage into your emergency sections of your website.

How do I use it?

The NPR API offers a number of output formats. The easiest ones to implement are the HTML and Javascript Widget formats. NPR provides documentation for all the output formats at their API homepage. Here we will walk through using the Javascript widget format.

Implementing the Javascript format:

NPR has made it very easy to generate API calls and import content into your local station site. Take a look at the page we created here on the SAFERStations.org site. Here’s how we did it.

1. You need to register to gain an API key in order to use the service. Both Member Stations and individuals are invited to use the NPR API. Stations should register at NPRstations.org, and individuals can gain an API key by registering at NPR.org.

2. After you have a key, visit the the NPR API Query Generator. Select the type of coverage that you are interested in.

nprapi_1

3. Select the ” Fields” tab and under Output Format, check the box next to “Javascript Widget”

4. Both the Javascript and HTML formats are fixed in the story elements they retrun, so no need to select the story elements in the options.

5. Hit the “Create API Call” button and a lengthy your Query Url will appear in the box. Copy that address.

nprapi_2

6. In your HTML editor on your site, you can use the following code to display the API content.

<script type=”text/javascript” src=”PasteYourQueryURLHere”></script>

7. The result should display similarly to our NPR API example page.

8. You can then manipulate the display of the output using CSS. Each part of the javascript widget has CSS identifiers associated with it. For example, if your station only wants to display MP3 audio links to show up and hide the Real Media or Windows Media, you can apply CSS to your pages to hide those story elements. Similarly, you can adjust the style of the javascript widget to different font sizes and families.

Alternatively, stations can choose to display just the headlines from a story within a sidebar or on a section of your homepage. In the query generator under Fields, you are able to select the specific story elements to display, along with the number of stories to return. The API provides the flexibility to customize content to fit your station’s page layout.