Twitch bot api requests being blocked?

Sort:
Avatar of senti3ntb3ing

Trying to pull the stats of a user via Cloudflare worker, using the `api.chess.com/pub/player/stats` endpoint is returning an html response saying that the request was blocked. Are there specific headers I need to be including with the request to get around this? Haven't had this issue with my bot before, but it was hosted on a separate service before. Any help would be much appreciated.

Avatar of AlAlper

Yeah, when using Cloudflare Workers (or any hosted setup), Chess.com’s API will block requests without proper headers — especially the User-Agent. They expect devs to identify themselves clearly.

Here’s how I do it in Python, and it works fine with the /stats endpoint:

import requests

def get_player_stats(username):
    url = f"https://api.chess.com/pub/player/{username}/stats"
    headers = {
        "User-Agent": "ChessStatsWorker/1.0 (contact: senti3ntb3ing@example.com; project: https://github.com/senti3ntb3ing/chess-stats-worker)",
        "Accept": "application/json",
    }
    response = requests.get(url, headers=headers)

    if response.status_code == 200:
        return response.json()
    elif response.status_code == 403:
        print("403 Forbidden – usually means your headers are missing or you’ve been blocked.")
    elif response.status_code == 404:
        print("404 Not Found – the username might not exist or the endpoint is wrong.")
    elif response.status_code == 429:
        print("429 Too Many Requests – you're hitting the rate limit, try slowing down.")
    else:
        print(f"Request failed with status: {response.status_code}")
        print(response.text)

# Example
print(get_player_stats("Hikaru"))

🔑 Why the User-Agent matters:Chess.com recommends something like:
YourAppName/1.0 (contact: your@email.com; project: URL)

This tells their team who to contact if something goes wrong or if your app misbehaves.
If you leave out the User-Agent, or use the default from Python or JS, your request is much more likely to get blocked.

Let me know if you need a JS/Cloudflare Worker version — happy to help.

AlAlper – Founder, ChessDev Hub
(Helping coders for less than 1 week on Chess.com) 😅

Avatar of senti3ntb3ing

I've added in those headers and I am still unfortunately getting blocked. Not sure what I can do to get unblocked on my requests.

Avatar of AlAlper

When Cloudflare blocks a request, it's usually due to edge-based heuristics like rate limiting, unusual header combinations, or traffic patterns that resemble bots. It will block entire IP rangers if they look suspicious.

Even if you’ve received approval from Chess.com support, Cloudflare operates independently — and their system can't be overridden manually. Once your request signature is flagged (IP, user-agent, structure), it can be blocked or challenged automatically.

For example, I added a User-Agent header to an automation-based request so the Chess.com dev team could more easily identify and contact me — but Cloudflare immediately blocked it outright. That’s how sensitive the filtering can be.

If you're running into issues, feel free to DM me. I’m happy to review your request structure and headers to help you stay within acceptable thresholds and avoid triggering Cloudflare's defenses.