- Previous: Authentication Overview
- Up: Introduction to Netflix API Documentation
- Next: REST API Conventions
JavaScript API Reference
The Netflix Javascript API allows subscribers to add, save, or instantly watch movies from your web site. It's a single-line JavaScript include; to try it out, sign up as a Netflix developer, find your consumer key in My Keys, and place the SCRIPT tag in your document, right where you want the add, save, or watch buttons to show up.
Running 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 drag 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>
Here 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 will come up in an IFRAME that's been absolutely positioned 40 pixels from the left edge and 20 pixels from the top of the DIV with id myMovieLocation. When you click the Play button, the instant movie viewer will come up in its own browser window.
Did you notice? There's a JSON object inside the SCRIPT tag, consisting of key-value pairs inside a set of curly brackets. That's how you pass your input to the API, so it must be a valid JSON object.
Buttons
- Valid buttons include
ADD_BUTTON,SAVE_BUTTON, andPLAY_BUTTON. Put these in thebutton_typearray. - 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 get (for free!) 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 a movie's availability is to go to its page and check for yourself. If you're dynamically generating your page, you can determine title availability with the Catalog API. Calls like this one:
http://api.netflix.com/catalog/titles/movies/your_movie_id/format_availability
... will instantly tell you how and when your title is available. For more information, please consult Common API Tasks and the REST API Reference.
Buttonless Calls
If you don't want to use our buttons, you can call the addToQueue and openPlayer functions after including 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>
Run this and you ought to see a page with a single link that will open the Netflix player for 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>
Run this 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-watcher queue, the way the Add to Instant button does, use instant instead of disc.
Important Notes and Technical Details about Buttonless Actions:
When performing buttonless actions, you are directly calling JavaScript functions which 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 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 is not signed in, 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.
- If you participate in our affiliate program, you will be awarded a bounty for all new subscribers who sign up from your page.

Comments
Please sign in to post a comment.