Search code examples
pythonroblox

Roblox API - Token Validation Failed


Whenever I try to send a request to the roblox api, I get the error "Token Validation Failed"

Code:
import requests

cookie = "COOKIE HERE"

session = requests.session()
session.cookies[".ROBLOSECURITY"] = cookie

def createBadge(id):
    data = {
        "name": "test",
        "description": "test badge",
        "enabled": True,
        "iconImageId": 11154174324,
        "expectedCost": 0
    }
    output = session.post(f"https://badges.roblox.com/v1/universes/{id}/badges", data=data)
    print(output.text)

createBadge(3944841252)

Solution

  • That error means that you have to include the "x-csrf-token" header. To obtain the token you firstly need to make a request fail and it will be in the response headers.