matching a player to their country

Sort:
Avatar of YankeeBastid

I cannot find an API that allows me to enter a player's name and have it return data containing the country they are from.. Any help is appreciated.

Avatar of Omed

This should work

https://api.chess.com/pub/player/{username}

but do note that this returns the country using

the format "Alpha2" which you can find a list online.
example: https://api.chess.com/pub/player/hikaru

response:

The user hikaru is from the US also known as The United States of America

Avatar of YankeeBastid

If you wanted to retrieve the country from this example, how would you do it in PHP? https://https://api.chess.com/pub/player/yankeebastid

Avatar of Martin_Stahl

You would grab the country property and then pull off the last two characters from the value

Avatar of YankeeBastid

so search for "/country/" and retrieve the next two characters, right?

Avatar of Omed
YankeeBastid wrote:

so search for "/country/" and retrieve the next two characters, right?

I don't deal with php so im not sure how u would do it in php but in javascript thats something u can do in javascript, but it can cause some issues with it. For example looking at this profile
https://www.chess.com/member/countrythere could be some conflict in the code if u do it this way.

Avatar of YankeeBastid

I have successfully written a script in PHP that retrieved the code. If you want to see it, DM me