cjsauer / pubg-clj

PUBG API client library for the Clojure programming language
MIT License
4 stars 1 forks source link

`pubg-clj.api/fetch-player-season-stats` always fails. #2

Open redbeardymcgee opened 2 years ago

redbeardymcgee commented 2 years ago
(require '[pubg-clj.api :as pubg])

(def my-api-key "foo-bar")
(def player-name "Some_Player")

(def player-map
  (pubg/with-api-key my-api-key
                     (pubg/fetch-player-by-name "steam" player-name)))

(pubg/with-api-key my-api-key
                   (pubg/fetch-player-season-stats player-map season-id))

The PUBG API will return a Bad Request error with the detail: "unknown data - shardId: steam-".

I believe this may be the fault of api-url which tries to concatenate a region variable during the url construction, while fetch-player-season-stats will always send at least the empty string as the region.

Supplying a region also fails.

The problem seems to be a mixup between the platform shard and the platform-region shard, where this endpoint is expecting a platform shard. In a legacy case for seasons prior to the introduction of the Survival Title system, it would be "pc-na" to request season stats from the NA region for a PC player. I suspect this will also always fail because api-url will concat "steam-pc-na" or "steam-na" depending on how the client tries to pass the region.

However, I think the url for seasons since the Survival Title system should simply be:

https://api.pubg.com/shards/**steam**/players/$account-id/seasons/$season-id?filter[gamepad]=false

I believe a rather large change was made a couple of years ago making leaderboards global, and the API accommodated this by implying the region from the platform shard. I could have mixed some things up.

You can verify here and read about it here.

While I think I found the source of the problem, I did not feel confident that I could fix it directly myself.

redbeardymcgee commented 2 years ago

After poking around the API docs some more, I found that the use of platform-region shards seems to be a legacy case for old seasons, and no other data.

The platform-region shard should be used for making requests for season stats for seasons before the Survival Title system was launched

https://documentation.pubg.com/en/making-requests.html#the-platform-shard

Requesting data with a platform-region shard appears to not fail with an error, but the API also does not respond with complete data, e.g. fetch-player-by-name will return a player with an empty match samples vector.

I believe we can just remove this line and document the need for specifying a platform-region shard for legacy seasons.

https://github.com/cjsauer/pubg-clj/blob/333f285212135420463e981afc4a9ecd5314c17d/src/pubg_clj/api.clj#L33

I've tested this change a bit manually and am currently trying to learn how to run your tests instead.