trakt / api-help

Trakt API docs at https://trakt.docs.apiary.io
186 stars 7 forks source link

Response code 401 (Unauthorized) on users/id/lists/list_id #392

Closed tomacotuna closed 1 year ago

tomacotuna commented 1 year ago

Recently I've been starting to get a 401 error while trying to retrieve some featured lists data using the users/id/lists or users/id/lists/list_id. In the docs it is stated that OAuth is optional for this endpoints (https://trakt.docs.apiary.io/#reference/users/list/get-personal-list), but perhaps something has since changed?

Example Request:

GET: https://api.trakt.tv/users/andreofgyn/lists/10747986 Error: HTTPError: Response code 401 (Unauthorized) at EventEmitter. (.../node_modules/got/dist/source/as-promise.js:118:31)

rectifyer commented 1 year ago

I got a 200 response when trying that URL with a valid Authorization header. It also got a 200 when not sending the Authorization header (which is fine since it's a public resource). I got a 401 when sending an invalid Authorization header.

Are you sure the access token is valid?

tomacotuna commented 1 year ago

Thanks for the quick reply on this matter.

Interesting I am currently using trackt.tv (https://github.com/vankasteelj/trakt.tv/issues) package for a cleaner code (and a bit of laziness if I am honest) to access all the endpoints. I never used Auth within it so it comes as a surprised that i was getting the 401 for a public resource. I mostly query movies, tv series and lists to construct a series of carousels to be served to a client app (the instance on the client for Trakt.tv does have auth and it works without issues).

The only call failing is the one with the lists, the one for shows or movies works just fine (using the exact same instance).

This is how i configure said instance:

const trakt = (req, res, next) => {
  let { clientId, clientSecret } = req.config.trakt;

  let options = {
    client_id: clientId,
    client_secret: clientSecret,
    pagination: true,
    debug: true,
    plugins: {
      // cached: require("trakt.tv-cached"),
      queued: require("trakt.tv-queued"),
    },
    options: {
      queued: {
        concurrency: 2,
        delay: 1,
      },
    },
  };

  const traktInstance = new Trakt(options);
  req.trakt = traktInstance;

  next();
};

Nothing fancy at all. I wonder if underneath the hood the js library for Trakt is doing something else when it comes to calling lists, perhaps since it is optional it sends an empty one which is then rejected?

rectifyer commented 1 year ago

Here is how I called the API directly, is that working for you? If so, it seems like a potential issue with the library you're using.

curl -i -H "trakt-api-version: 2" -H "Content-type: application/json" -H "trakt-api-key: API_KEY" --compressed https://api.trakt.tv/users/andreofgyn/lists/10747986
tomacotuna commented 1 year ago

Thanks for the example, that helps me clarify that this is not an issue on Trakt side, as in terminal that works perfectly, but rather something to do with the library, will dive in its code to determine where it takes place.