matching a player to their country

Sort:
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.

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

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

Martin_Stahl

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

YankeeBastid

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

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.

YankeeBastid

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