"Token Validation Failed" error on roblox API

Im trying to send API POST requests in Python to the endpoint: http://economy.roblox.com/v1/purchases/products/
The Script runs fine for a while but then the API starts returning the error 403 Token Validation Failed and it wont stop returning that error unless i restart the script.


(Failed at Asset [ID]: [Name]) means that the API returned an error.

def buyProduct(asset):
    time.sleep(.5)
    Response = Session.post('https://economy.roblox.com/v1/purchases/products/' + str(asset['productId']),data={'expectedCurrency': 1, 'expectedPrice': 0, 'expectedSellerId': 1})
    if 'Too many requests' in Response.text:
        print(Fore.MAGENTA+'Too many requests. Waiting 60 seconds.')
        time.sleep(60)
        return buyProduct(asset)
    elif Response.status_code != 200:
        print(f'{Fore.RED}Failed at Asset {asset["id"]}: {asset["name"]}')
        time.sleep(10)
        return buyProduct(asset)

    JSON = Response.json()
    if JSON['purchased']:
        print(Fore.GREEN+'Successfully Purchased '+asset["name"])
    elif JSON['reason'] == 'AlreadyOwned':
        print(Fore.BLUE+'You aready own '+asset["name"])
1 Like

you need to include X-Csrf-Token in your request

i am.
heres my code that gets the XCSRF Token

try:
    XCSRF = Session.post("https://auth.roblox.com/v2/logout").headers['X-CSRF-TOKEN']
    print('Successfully got X-CSRF: '+XCSRF)
    Session.headers["X-CSRF-TOKEN"] = XCSRF
    Session.headers['Referer'] = "https://www.roblox.com"
except:
    print('Invalid cookie')

the code does work and is buying the items but after like 5 munities it stops working and i get the error (i tested this multiple times and it always happens).

Managed to fix it by refreshing the Token whenever it gives that error.
still having some wierd issue where after 11 requests the api will return “InternalServerIssue” for a bit before finaly telling me i have been rate limited… Wierd…

yes every 5 minutes your csrf token changes you can just make a loop in the background to make the request every 5 minutes

Internal Server Error is being returned because you are buying too many assets in a given time

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.