[API] Is there a way to use /pms/servers and get a JSON response?

I’m trying to develop using the web API documentation. For whatever reason, only 1 request (and one that’s REQUIRED) will only return responses in XML format.

https://plex.tv/pms/servers

Even if I add the header,

"Accept": "application/json"

Sends me XML responses. Is there any way to force this route to return json instead? I’d rather use JSON across the app, rather than using XML for this one request and then json everywhere else, or have to use all XML. Does anyone know how I can get this route working the way I want?

[Edit]
I’ve tried changing from https://plex.tv/pms/servers.xml to https://plex.tv/pms/servers.json, and this also hasn’t worked. When I submit my request with .json at the end, I get a 406 error, but the same request, with .xml instead of .json sends me a 200 with proper data back.

AFAIK, the models, like the servers, only return info in XML

All other requests I’ve used return JSON no problem. Example: https://plex.tv/devices.json instead of https://plex.tv/devices.xml returns valid JSON. Literally every other request I’ve used except /servers has returned valid JSON

I know :wink:

/Tommy

So is this just a bug with the API? Is it going to be addressed at some point?

1 Like

AFAIK, it’s WAD (Working as designed)

And if this is going to change, I can sadly only suggest you ask here:
https://forums.plex.tv/c/general/feature-suggestions

Wait, so how is a 406 when it should be a 200… WAD? They designed an API route to return errors instead of proper response data?

406 means:

The resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request.

Unless it was a HEAD request, the response SHOULD include an entity containing a list of available entity characteristics and location(s) from which the user or user agent can choose the one most appropriate. The entity format is specified by the media type given in the Content-Type header field. Depending upon the format and the capabilities of the user agent, selection of the most appropriate choice MAY be performed automatically. However, this specification does not define any standard for such automatic selection.

Note: HTTP/1.1 servers are allowed to return responses which are not acceptable according to the accept headers sent in the request. In some cases, this may even be preferable to sending a 406 response. User agents are encouraged to inspect the headers of an incoming response to determine if it is acceptable.
If the response could be unacceptable, a user agent SHOULD temporarily stop receipt of more data and query the user for a decision on further actions.

I understand why a 406 exists. That makes perfect sense. What I don’t understand is why a route, in the documented API, returns a 200 with .xml, and with the exact same data, returns a 406 in the .json. There’s no reason the data is “acceptable” (200) in the .xml, but unacceptable (406) in the .json

That’s the part I’m having a hard time with.

Not sure here, but think/guess that if req. servers.json == Accept:Application/json

As such, a 406 is valid, since the header entry is not accepted

Ah, I think I’m with you now. It seems like this route may not be configured properly. I will try posting in feature requests, maybe they can fix it. It should just be a few small changes to that one route, so hopefully someone wants to tackle it.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.