grantholle / moviedb-promise

Interact with themoviedb.org's api with Node... now in TypeScript!
Other
213 stars 49 forks source link

find function throws 404 #34

Closed au2001 closed 4 years ago

au2001 commented 4 years ago

Hi,

The find function seems outdated and not to work anymore. It throws a 404 error every I call it.

According to The Movie Database's API documentation, the parameters should be an external_id (in the path), an external_source and optionally a language.

I believe the current implementation of the find function is bugged because:

  1. Its params parameter is of type string | number | FindRequest | undefined which doesn't make sense, you can't pass a single string/number for it to work.
  2. FindRequest (which extends Request) has id: ExternalId (on top of external_source?: 'imdb_id' | 'freebase_mid' | ...) where ExternalId is an enum containing something similar to external_source:
    export enum ExternalId {
    ImdbId = "imdb_id",
    Freebase_Mid = "freebase_mid",
    ...
    }

Here is an example code using the current version:

import { MovieDb } from "moviedb-promise";

const moviedb = new MovieDb("xxx");

// Instagram
moviedb.find("avengers");  // Error: Request failed with status code 404

// IMDb
moviedb.find("tt0959621"); // Error: Request failed with status code 404

// TheTVDB non-existing ID
moviedb.find("0");         // Error: Request failed with status code 404

Here would be an example code of the expected usage:

import { MovieDb } from "moviedb-promise";

const moviedb = new MovieDb("xxx");

// Instagram (URL: https://api.themoviedb.org/3/find/avengers?api_key=xxx&language=en-US&external_source=instagram_id)
moviedb.find({ id: "avengers", external_source: "instagram_id" });
// { movie_results: [ { title: "Avengers: Endgame", ... }, { title: "Avengers: Infinity War", ... } ], person_results: [], tv_results: [], tv_episode_results: [], tv_season_results: [] }

// IMDb (URL: https://api.themoviedb.org/3/find/tt0959621?api_key=xxx&language=en-US&external_source=imdb_id)
moviedb.find({ id: "tt0959621", external_source: "imdb_id" });
// { movie_results: [], person_results: [], tv_results: [], tv_episode_results: [ { name: "Pilot", ... } ], tv_season_results: [] }

// TheTVDB non-existing ID (URL: https://api.themoviedb.org/3/find/0?api_key=xxx&language=en-US&external_source=tvdb_id)
moviedb.find({ id: "0", external_source: "tvdb_id" });
// { movie_results: [], person_results: [], tv_results: [], tv_episode_results: [], tv_season_results: [] }
grantholle commented 4 years ago

Thanks for catching that and the extensive writeup. I've published moviedb-promise@3.1.0 correcting the parameters for find to only be a FindRequest.

export interface FindRequest extends Request {
  id: string|number
  language?: string
  external_source?: ExternalId
}

It was a misconfiguration on my part. Thanks again.

grantholle commented 4 years ago

Sorry, already caught an problem and published 3.1.1, making external_source required...

export interface FindRequest extends Request {
  id: string|number
  language?: string
  external_source: ExternalId
}
au2001 commented 4 years ago

Thanks for the fast reply and fix. Unfortunately, I still encounter problems with the latest version (3.1.1).

More precisely, FindRequest extends Request from the Fetch API, rather than RequestParams from ./types. Performing (only) this modification fixes the issue for me and the function now works as expected.

grantholle commented 4 years ago

.... 🤦‍♂️

Thanks, I've corrected it for 3.1.2

au2001 commented 4 years ago

I can confirm that the 3.1.2 version from npm works fine now. Thanks.