stelar7/R4J

API Request is malformed

Opened this issue · 15 comments

I keep getting APIResponseExceptions with "Your API request is malformed". The URL for the call (/active-games/by-summoner/[puuid]) is strange because the PUUID specified consists of letters and numbers and is sometimes separated by hyphens. What also surprises me is that the error only occurs sporadically, sometimes not at all for days and then several times in a row. The exact response of the call is "Exception decrypting [...]"

Hello @wafebreaker!

All IDs you receive through the Riot API are encrypted with your API key (not directly, but a key tied too the api key). If you retrieve an ID using one API key (e.g., the development key) and later switch to a different key (e.g., your project's production key) while still using the old ID, you will receive this error.
This error occurs because you're trying to use a PUUID that was encrypted with a different API key than the one you're currently using.

Your issue is probably linked to that.

I hope this helps!

Thanks for your reply! Im definetly only using one key for all requests. So this should not be my issue

Yesterday, for example, I didn't even have the error. Today, it's been giving this error continuously for 10 minutes. And the requests today are exactly the same as yesterday (same key, same PUUID). Could this have something to do with Riot's server availability?

Exception decrypting .... is an error you only get when you pass a id to an endpoint that doesnt use that id. It might be because youre using multiple api keys, or using the wrong type of id (passing a summoner id to a puuid endpoint)

i have been thinking of forcing types on the endpoint parameters to avoid this, but its far back on the list of things i have to do unfortunately.

Feel free to post your code where the error happens, and maybe people can help you find the error

As I said, both reasons are not possible for me. There are days when the error doesn't appear and days when it appears every minute. And currently only about 20 accounts are retrieved. The only thing I could imagine is the following:

I have a thread running that calls a function every minute. In this function, all accounts are retrieved from the Riot API. Is it possible that if the requests are duplicated or overlap due to the longer response time from RIOT, then the ID is malformed?

A short excerpt from the code:

task that is executed every minute
`executorService = Executors.newScheduledThreadPool(2);

    executorService.scheduleAtFixedRate(() -> {
        try {
            checkMatchHistory();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }, 0, 1, TimeUnit.MINUTES);`

Parts from the called function

private static void checkMatchHistory() throws Exception {
DataCall.setCacheProvider(EmptyCacheProvider.INSTANCE);
DataCall.getCacheProvider().clearOldCache();
DataCall.getCacheProvider().clear(URLEndpoint.V4_LEAGUE_ENTRY, Collections.emptyMap());
DataCall.getCacheProvider().clear(URLEndpoint.V5_MATCH, Collections.emptyMap());
DataCall.getCacheProvider().clear(URLEndpoint.V4_LEAGUE, Collections.emptyMap());
SummonerAPI summonerAPI = r4j.getLoLAPI().getSummonerAPI();
List playerAccounts = sqlConnector.fetchPlayerAccountsFromDB();

    for (PlayerAccount playerAccount : playerAccounts) {
        Summoner summoner = summonerAPI.getSummonerByPUUID(LeagueShard.valueOf(playerAccount.getPlatform().toUpperCase()), playerAccount.getPuuid());

        try {
            SpectatorGameInfo spectatorGameInfo = summoner.getCurrentGame();
            if (spectatorGameInfo != null) {
                sqlConnector.updateActiveAccount(playerAccount.getStreamer(), playerAccount.getPuuid(), playerAccount.getQueue());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

(Code function doesn't work somehow)

Is it possible that you store the wrong ID in the database?

No, that shouldn't be possible. I retrieve the PUUID with the same key using name + tag. After that, the PUUID is stored in the DB and is no longer changed.

These errors only occur with the SpecatorAPI. In the same code 2 lines below I retrieve matches with the same PUUID and that works without errors.:

https://euw1.api.riotgames.com/lol/spectator/v5/active-games/by-summoner/**********************
{"status":{"message":"Bad Request - Exception decrypting **********************","status_code":400}}
at no.stelar7.api.r4j.basic.calling.DataCallBuilder.build(DataCallBuilder.java:142)
at no.stelar7.api.r4j.impl.lol.raw.SpectatorAPI.getCurrentGame(SpectatorAPI.java:94)
at no.stelar7.api.r4j.pojo.lol.summoner.Summoner.getCurrentGame(Summoner.java:177)
at org.example.Main.checkMatchHistory(Main.java:135)
at org.example.Main.lambda$startMonitoring$0(Main.java:59)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:840)

(i hided the number, dont know if its necessary)

If you have the name/tag of a summoner that is failing, can you go to https://developer.riotgames.com/ and manually check the results you are getting?

The endpoints are
account from name/tag -> https://developer.riotgames.com/apis#account-v1/GET_getByRiotId
current game -> https://developer.riotgames.com/apis#spectator-v5/GET_getCurrentGameInfoByPuuid

The puuid in the first request should be the same as the one that shows in the error message. If not, you have somehow ended up with an invalid id

No, I think you misunderstood me. I pull the PUUID over the name + tag of a summoner. I then save this PUUID in the database. I use the same PUUID to query both the Spectator API and the MATCH API. However, I only get this error with the Spectator API, not the Match API. Even though it is the same PUUID. And the one in the error looks completely different (I assume it's because it's decrypted?)

Example:
The PUUID that I get from Account V1 API looks like this:
M0aMsK8p8brvRDP_xGRUCawAsThd_2J3O_JPgHHD_uVOR9bReQe-wq8wpTKkDdaheGFnNz_uVPXBFw (modified from the original)

The error message says something like this:
{"status":{"message":"Bad Request - Exception decrypting 9739163a-2a06-567f-72bf-e5b573856ea6","status_code":400}} (also modified)

Pastebin of the function: https://pastebin.com/NJqd5S1j

the Line 15 (SpectatorGameInfo spectatorGameInfo = summoner.getCurrentGame();) throws the error.

But the Function continues and pulles the matches with the same PUUID

(Sorry for multiple posts)

That seems very odd..
Do you have the log outputs?
It should say something like:

.. stuff here..

Trying url: https://europe.api.riotgames.com/riot/account/v1/accounts/by-riot-id/stelar7/STL7

.. stuff here..

responseData={"puuid":"inxcpz8Bw4qzirO6sd0OPv4q3SnRzLV0ql4Q2XUq65aDRqfrjGwY3Sj54rr0W9qpvmTtINbI0VNITw","gameName":"stelar7","tagLine":"STL7"}

.. stuff here..

Trying url: https://euw1.api.riotgames.com/lol/spectator/v5/active-games/by-summoner/inxcpz8Bw4qzirO6sd0OPv4q3SnRzLV0ql4Q2XUq65aDRqfrjGwY3Sj54rr0W9qpvmTtINbI0VNITw

.. stuff here..

responseData={"status":{"message":"Data not found - spectator game info isn't found","status_code":404}}

If the ID in the response and the request dont match, theres something changing your puuids somehow 🤔

Yeah i have logs enabled but the responsedata is missing?

But i checked the last 2 hours of logs (in this time the error happens multiple times) and all i see are lines like this:

2024-11-12 10:40:35 [pool-2-thread-1] INFO n.s.a.r.b.calling.DataCallBuilder - Trying url: https://euw1.api.riotgames.com/lol/summoner/v4/summoners/by-puuid/S0MHH1ir28Jl4fPyQw0W0ls0NoiJaBjJY8ceD_xF63QcSr5ppEoRo4UEZhFPGHVHq_01g378lQNovA
2024-11-12 10:40:35 [pool-2-thread-1] INFO n.s.a.r.b.calling.DataCallBuilder - Trying url: https://euw1.api.riotgames.com/lol/spectator/v5/active-games/by-summoner/S0MHH1ir28Jl4fPyQw0W0ls0NoiJaBjJY8ceD_xF63QcSr5ppEoRo4UEZhFPGHVHq_01g378lQNovA
2024-11-12 10:40:35 [pool-2-thread-1] INFO n.s.a.r.b.calling.DataCallBuilder - Trying url: https://europe.api.riotgames.com/lol/match/v5/matches/by-puuid/S0MHH1ir28Jl4fPyQw0W0ls0NoiJaBjJY8ceD_xF63QcSr5ppEoRo4UEZhFPGHVHq_01g378lQNovA/ids?queue=420&type=ranked&count=5

and this "group of three" of queries is always with the same puuid

Your earlier message seems to imply they are different: #106 (comment)
but maybe it was only different in the response.. 🤷

But if they are the same in all cases, that would be an issue with the RiotAPI.
It seems there might be a bug that returns the unencrypted data instead RiotGames/developer-relations#1007
I would suggest messaging them on the developer portal, or trying to reach out on the discord https://discord.com/invite/riotgamesdevrel

For the response you would need to set the log level to DEBUG by doing something like

LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
loggerContext.getLogger("no.stelar7.api.r4j.basic.calling.DataCallBuilder").setLevel(Level.DEBUG);

That's what surprises me. The error from #106 is the one that is output in the console with " printStackTrace();"

And the ID that is specified in the URL is definitely different (numbers separated by hyphens).

But in the log itself the IDs are all identical

But then it really seems to be an error from RIOT that the unencrypted data is being sent back