JavaScript API Reference

The Netflix Javascript API allows subscribers to add, save, or instantly watch movies from pages on your web site. You include this API on a page with a single line of JavaScript. To try it out, sign up as a Netflix developer, find your consumer key (sometimes called the "API key" or just your "key") in My Keys, and place the <script> element shown in the examples below in your page at the place where you want the add, save, or watch buttons to show up.

Running the Examples on This Page

To run an example on this page, copy it, paste it into a text editor, substitute your own consumer key for my_consumer_key, save it with an .html extension, and load it into a Web browser.

Netflix Button Sets

<html><head><title>My Spiffy Movie Page</title></head><body>
<div id="myMovieLocation">
<img src="http://cdn-7.nflximg.com/us/boxshots/large/70068647.jpg" /><br />
<script src="http://jsapi.netflix.com/us/api/js/api.js">
{
"title_id" : "http://api.netflix.com/catalog/movie/70068647",
"button_type" : ["PLAY_BUTTON", "ADD_BUTTON"],
"show_logo" : "true",
"x" : "40",
"y" : "20",
"dom_id" : "myMovieLocation",
"application_id" : "my_consumer_key"
}
</script>
</div>
</body></html>

When you load this into your browser, you ought to see a page with box art and a button set for The King of Kong (which we happen to know is usually available for instant watching). If you click the Add button, or mouse over Play and then click the Add to Instant button, the result of this interaction will come up in an <iframe> that is absolutely positioned 40 pixels from the left edge and 20 pixels from the top of the <div> whose id is "myMovieLocation". If you click the Play button, the instant movie viewer will come up in its own browser window.

There’s a JSON object inside the <script> tag that consists of key-value pairs inside a set of curly brackets. That’s how you pass your parameters to the Netflix JavaScript API, and it must be in the form of a valid JSON object.

Buttons

  • Valid buttons include ADD_BUTTON, SAVE_BUTTON, and PLAY_BUTTON. Put these in the button_type array.
  • Add supersedes Save, so if you try to show them both, you will only see Add. You should only use Save when you are positive that the movie is not available from Netflix yet.
  • If you include a Play button, you will also automatically get the Add to Instant button, which will only show when you mouse over Play.

The Netflix Logo

Although we like to set show_logo to true to make our code easier to explain and maintain, it’s not strictly necessary because the logo is on by default. To eliminate it, set show_logo to false.

Title Availability

If you’re writing your pages by hand, the fastest way to find out whether a title is available is to go to its page and check for yourself. You can also determine instant-watch availability with the Netflix REST API. Calls like this one:

http://api.netflix.com/catalog/titles/movies/your_movie_id/format_availability

…will tell you if your title is available for instant-watch streaming. For more information on how to make Netflix REST API requests, please consult Common REST API Tasks and the REST API Reference.

Buttonless Calls

If you don’t want to use our buttons, you can use your own mechanism to call the addToQueue( ) and openPlayer( ) functions after you include the base API script anywhere in your site.

Watch Instantly

<html><head><title>My Spiffy Movie Page</title></head><body>
<a href="#" onclick="javascript:nflx.openPlayer('http://api.netflix.com/catalog/movie/70068647', 0, 0, 'my_consumer_key');">Watch The King of Kong Now</a>
<script src="http://jsapi.netflix.com/us/api/js/api.js"></script>
</body></html>

Load that code in your browser and you ought to see a page with a single link that will open the Netflix player to play The King of Kong.

Add to Queue

<html><head><title>My Spiffy Movie Page</title></head><body>
<a id="addMe" href="#" onclick="javascript:nflx.addToQueue('http://api.netflix.com/catalog/movie/70068647', 10, 20, 'my_consumer_key', 'disc', 'addMe');">Add The King of Kong to DVD Queue</a>
<script src="http://jsapi.netflix.com/us/api/js/api.js"></script>
</body></html>

Load that code in your browser and you ought to see a page with a single link that will add The King of Kong to your "Watch Later" queue. If you want to add this movie to the subscriber’s instant-watch queue, the way the Add to Instant button does, use instant instead of disc as the fifth parameter to addToQueue( ).

Important Notes and Technical Details about Buttonless Actions:

When performing buttonless actions, you directly call JavaScript functions that expect certain parameters to appear in a certain order. Here’s how they work:

nflx.addToQueue : function (movieId, xPos, yPos, applicationId, type, domId)
addToQueue( ) expects the movie ID, the X and Y position in pixels from the top of the viewport, your application ID, the queue type you want to add to, and the DOM id of the element you want your X and Y position to be counted from. Only the DOM id is optional.
nflx.openPlayer : function(movieId, xPos, yPos, applicationId, domId)
openPlayer( ) expects the movie ID, the X and Y position in pixels from the top of the viewport, your application ID, and the DOM id you want your X and Y position to be counted from. Only the DOM ID is optional.

Other Useful Things to Know

  • If the Netflix subscriber who views your page is not signed in to Netflix, an authentication window will come up instead of the add, save, or instant-watcher window.
  • Visitors who are not currently Netflix subscribers will be prompted to sign up.