Set Up the Credentials

Set up your credentials to get the API key for The Movie Database.

To use The Movie Database (TMDB) API platform, we need to create an account on TMDB.

Create an account

We can sign up for our TMDB account on their official page. Please follow the steps below to successfully sign up:

  1. Fill in the primary details like username, password, and email address and click “Sign Up”.

  2. Before you can log in to your account, you need to verify your email address to activate it. Go to your inbox and click the verification link in the verification email sent by TMDB.

  3. Enter your username and password to log in.

  4. A successful login would take you to the homepage of TMDB.

The slides below are to help you visualize the process.

Get the API key

Please follow the steps below to register for an API key:

  1. Log in to your TMDB account.
  2. Click on your name icon at the top right corner and then click “Settings” to go to the settings page.
  3. Click “API” to go to the API creation page.
  4. Click “click here” under the “Request an API Key” section.
  5. Select “Developer” as the type of your API.
  6. Click “Accept” to agree with the terms of use of TMDB API.
  7. Fill in the application details and click “Submit”.

Note: The “Application URL” field takes in any random URL as our application URL. For example, www.example.com.

  1. TMDB API key generated successfully!

The slides below are to help you visualize the process.

Check your API key

Since we have our TMDB API key with us, get ready to do some great stuff! Here’s a sneak peek of how we can use our API key to fetch the required information. Let’s run the code below to fetch the popular movies on TMDB.

If you haven’t already entered your API_KEY then please click “Edit” and enter the value. Now, click “Run” to execute the code.

import fetch from "node-fetch";
const API_KEY = '{{API_KEY}}';
const endpointUrl = new URL('https://api.themoviedb.org/3/movie/popular');
const queryParameters = new URLSearchParams({
api_key: API_KEY,
language: 'en-US'
});
async function fetchData() {
try {
endpointUrl.search = queryParameters;
const response = await fetch(endpointUrl);
// Call to function that prints the response
printResponse(response);
} catch (error) {
// Call to function that prints the error message, if any
printError(error);
}
}
// Call to function that makes API call
fetchData();

If your API key is valid, it will lead to a successful call of TMDB’s popular movies endpoint, and we’ll get a list of popular movies with their details as our output. We’ll explore all such endpoints together throughout this course, so let’s get started.