Get bulk TMDB IDs by name

In this article we will teach you how to obtain IDs from TMDB (Themobiedatabase) through the name of the series or film using a script in Google Sheet and a function called “=searchTMDbId”.

There was a JustWatch Widget that I wanted to put on my website for a long time, I had a database of animes, but I didn't have TMDB IDs for each anime. So I created this script that made the process of obtaining IDs very quick and practical.

The first thing you should do is add the Apps Script to your form, save and run the script, so you will be able to use the formula without problems in Google Sheet.

Apps Script for TMDB

Follow the code below:

// Função para buscar o ID de uma obra pelo nome usando a API do TMDb
function searchTMDbId(name) {
  var apiKey = '80387065ffe0b71fa2f11fecfa92a146'; // Substitua pelo sua chave de API do TMDb
  var apiUrl = 'https://api.themoviedb.org/3/search/tv';
  var query = encodeURIComponent(name);

  var response = UrlFetchApp.fetch(apiUrl + '?api_key=' + apiKey + '&query=' + query);
  var data = JSON.parse(response.getContentText());

  if (data.results.length > 0) {
    return data.results[0].id; // Retorna o ID da primeira obra encontrada
  } else {
    return 'Obra não encontrada';
  }
}