Bot Authentication Issues When Sending Server Statistics via API

I’m working on a Discord bot and trying to send server stats to a bot listing website. The process requires two steps: first authenticate with an auth token, then POST the actual data.

The authentication part works fine and I get a proper response. But when I try to POST the server information afterward, I don’t get any response at all. Here’s what I’m doing:

async def updateBotStats():
    guild_list = list(bot.guilds)
    server_count = len(bot.guilds)
    
    base_url = "https://www.botlistsite.com"
    stats_endpoint = "https://www.botlistsite.com/api/bots/:myBotId/statistics"
    
    payload = {'servers': int(server_count)}
    auth_header = {'Authorization': 'Bot myActualToken'}
    
    response = requests.get(base_url, headers=auth_header)
    print(response)
    response = requests.post(stats_endpoint, data=payload)
    print(response)

The first request works but the second one gives me nothing. What am I missing here?

You’re missing the auth header in your second request. Look at your code - you authenticate once with the GET request but then send the POST without any headers.

The bot listing API needs that authorization token for both requests. Your POST should include the same auth header:

response = requests.post(stats_endpoint, data=payload, headers=auth_header)

Honestly though, managing these API calls manually sucks. I’ve dealt with bot stat reporting across multiple services and it gets messy fast - rate limits, retries, different API formats everywhere.

I ended up setting up automation in Latenode that handles all this. It grabs server count from Discord, formats payloads for each bot listing site, manages auth, and handles errors automatically.

Runs every hour without me touching it. When bot listing sites change their API (and they will), I update the workflow once instead of digging through bot code.

Worth checking out if you’re tired of babysitting these calls: https://latenode.com

Yeah, you’re missing the authorization token, but there’s another problem I hit when doing bot stats updates. You’re using the data parameter, but most bot listing APIs want JSON format. Try this instead:

response = requests.post(stats_endpoint, json=payload, headers=auth_header)

Using json=payload instead of data=payload automatically sets the right Content-Type header and formats everything properly. I had the same silent failures until I switched to JSON. Also double-check that your endpoint URL has the actual bot ID instead of :myBotId - that placeholder won’t work. Adding try-except blocks saved me tons of debugging time when these API calls inevitably break.

You’re not sending auth headers with your POST request. The GET works because it has proper auth, but your POST is anonymous to the API. I hit this same problem when I started posting to bot lists. Most APIs need auth on every single request - they don’t remember your GET auth for the POST. Server has no session state between calls. Also check if the API wants JSON instead of form data. Some bot sites are picky about content type. Add ‘Content-Type’: ‘application/json’ to your headers and use json=payload instead of data=payload. And make sure :myBotId in your URL actually gets replaced with your real bot ID. I’ve done that before and the API just fails silently.

bruh you’re sending the POST without auth headers. your second request needs headers=auth_header too - the server doesn’t remember your GET auth. also check if :myBotId is actually replaced with real bot id in the url, that could cause silent fails.

Yeah adding the auth headers will fix your immediate problem, but you’re doing this the hard way.

I used to write similar code for updating bot stats across different listing sites. The real pain comes later when you need error handling, retry logic, rate limiting, and logging. Each bot listing site has slightly different requirements too.

You’ll realize you need this running on a schedule, not just when your bot feels like it. What happens when your bot goes down but you still want to report stats from your database?

I moved all my bot stat reporting to Latenode workflows. One workflow pulls server counts from Discord API, formats data for each listing site, handles auth tokens, and posts to multiple endpoints. Built-in error handling and retries.

Runs every hour automatically. APIs change or go down? I get notifications. Add new bots? Just clone the workflow.

Way cleaner than mixing API calls into bot code. Your bot handles Discord events, automation handles the boring API stuff.

oh duh, you forgot the auth headers on your POST request lol. You’re doing requests.post(stats_endpoint, data=payload) but it should be requests.post(stats_endpoint, data=payload, headers=auth_header). The API doesn’t know who you are without the token in that second call.