How to acces chess.com api?

Sort:
Avatar of WARDGAATHARD

I have been trying to acces the chess.com api via Python.

--------------------------------------------------------------------------------

import requests

x = requests.get("https://api.chess.com/pub/player/Hikaru/stats")
print(x.json())

----------------------------------------------------------------------------------------------

However, this gives me an error and when just printing 'x' I get <Response [403]> which indicates that the server understands the request but refuses to authorize it. Anybody knows how to solve this?

Avatar of Martin_Stahl
WARDGAATHARD wrote:

I have been trying to acces the chess.com api via Python.

--------------------------------------------------------------------------------

import requests

x = requests.get("https://api.chess.com/pub/player/Hikaru/stats")
print(x.json())

----------------------------------------------------------------------------------------------

However, this gives me an error and when just printing 'x' I get <Response [403]> which indicates that the server understands the request but refuses to authorize it. Anybody knows how to solve this?

https://www.chess.com/club/chess-com-developer-community

You need to be hitting the Public API endpoints and you have to include a header with contact information in your scripts.

Avatar of Dmitriy149

In your case the following will work:

import requests
h = requests.get('https://api.chess.com/context/Match.jsonld')
x = requests.get("https://api.chess.com/pub/player/Hikaru/stats", headers = h)
print(x.json())

For others see json-ld contexts in chess.com api docs:

https://www.chess.com/news/view/published-data-api#pubapi-endpoint-games