Forums

Inconsistency in white/black format in TournamentRoundGroup

Mig_Well

Hi everyone,

When integrating with the API, I noticed inconsistencies across API calls when returning white and black values. For example, for `Current Daily Chess`, the documentation tells us that white/black is a string. But then for `Daily Team match board`, white/black is suddenly an object containing more information (username, rating, etc.). Ok, this doesn't make much sense to me but I can live with it, I just need to use different classes for different calls.

Today, I encountered sometimes way worse. Inconsistencies within the same endpoint. When calling the `Tournament's round group` endpoint, `games` contains white/black values that are documented to be string. But depending on which tournament you are calling it for, a string or a complex object will be returned. For example, for this call, the response contains

{
"url": "https://www.chess.com/game/daily/138891582",
...
"white": {
"rating": 1428,
"result": "insufficient",
"@id": "https://api.chess.com/pub/player/rockaround",
"username": "Rockaround"
},
"black": {
"rating": 1533,
"result": "insufficient",
"@id": "https://api.chess.com/pub/player/mrtn",
"username": "mrtn"
},
"tournament": "https://api.chess.com/pub/tournament/-33rd-chesscom-quick-knockouts-1401-1600"
}

Ok, that means the documentation is wrong but whatever. What is seriously wrong is that if you make the exact same call for this tournament, you'll get the following:

{
"url": "https://www.chess.com/game/daily/289647422",
...
"white": "https://api.chess.com/pub/player/rainbowsandcastle",
"black": "https://api.chess.com/pub/player/mainak_roy",
...
}

Am I missing something? Could this be fixed? This makes it very hard to integrate with the API...

Nevfy
Mig_Well write:

Am I missing something? Could this be fixed? This makes it very hard to integrate with the API...

Yes. You are missing the fact, that first game is finished and the second one is not. So for the finished game "white" and "black" are structures with all info, that could be interesting (result, rating of player after game's end and reference for player's data). For current game "white" and "black" are just references for player's data.

For sure, the developers of API could keep the same pattern for both cases, returning for unfinished game a structure with one element inside, but I don't really care and easily work with how it is made. If "end_time" is inside the game's structure, the game is finished and you can expect the result to be a structure (as described above), otherwise - a string.

By the way, basing on this rule, you can make a conversion on your side, if you really prefer the data to be always of the same type.

Mig_Well

Ah yes, you seem to be right, thanks!

I do think that it makes much more sense to always keep the data in the same format in the responses otherwise you are moving the burden on the client side and you make the documentation harder to manage (this behavior is not documented).

But yes, "for now", I can easily make a change on my end to be able to handle it