LukeHagar / plexjs

A Typescript SDK for interacting with Plex Media Server
MIT License
21 stars 0 forks source link

Plex url not correct resulting in 404 #22

Open Deff3x opened 2 months ago

Deff3x commented 2 months ago

When trying to retrieve the User details for the display name using client.plex.getUserDetails() it is returning a 404 response due to a bad request url.

When instantiating I am providing the following:

const client = new PlexAPI({
  accessToken,
  xPlexClientIdentifier: uuid,
  ip: '192.168.0.53',
  port: '32400',
  protocol: 'http',
})

const test = await client.plex.getUserDetails()
console.log(test)

Results:

SDKError: API error occurred: Status 404 Content-Type application/json; charset=utf-8 Body 
{"status":404,"error":"Not Found"}
{
  rawResponse: Response {
    status: 404,
    statusText: 'Not Found',
    headers: Headers {
      date: 'Wed, 04 Sep 2024 20:49:31 GMT',
      'content-type': 'application/json; charset=utf-8',
      'transfer-encoding': 'chunked',
      connection: 'keep-alive',
      'x-request-id': '4ceb9337c8be874ded4d20c8dfa4ba32',
      'x-runtime': '0.002691',
      'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
      'referrer-policy': 'origin-when-cross-origin',
      'x-content-type-options': 'nosniff',
      'x-frame-options': 'SAMEORIGIN',
      'x-xss-protection': '1; mode=block',
      vary: 'Origin',
      'content-encoding': 'gzip'
    },
    body: ReadableStream { locked: true, state: 'closed', supportsBYOB: true },
    bodyUsed: true,
    ok: false,
    redirected: false,
    type: 'basic',
    url: 'https://plex.tv/api/v2user'
  },
  body: '{"status":404,"error":"Not Found"}',
  statusCode: 404,
  contentType: 'application/json; charset=utf-8'
}

As you can see from above the url is set to url: 'https://plex.tv/api/v2user'.

I am receiving similar results with *.plex.getUserFriends()

Fix for now is manually overriding the server url and including the ending forward slash / as follows:

const test = await client.plex.getUserDetails({
  serverURL: "https://plex.tv/api/v2/",
})
LukeHagar commented 1 month ago

This is hopefully fixed in the most recent set of regenerations, please let me know if otherwise

Deff3x commented 1 month ago

Looks like the endpoint is now working although has been moved into client.authentication.getUserDetails

I am now getting a giant error block into the console stating rawMessage: 'Response validation failed', looks like some of the models/enums don't fully line up yet.

error-dump.log

Let me know if you need any more information or if you want me to open a new issue to track.

LukeHagar commented 1 month ago

Thanks for confirming!

If you want to provide a sanitized version of the raw response you are getting from the API I can try to get the schemas aligned

Deff3x commented 1 month ago

Apologies for the delay!

Here is the JSON you asked for, I have marked {REMOVED} on anything I have sanitised.

Let me know if you need anything else!

user.json