Groups API fails Token Validation although the token is valid

I’m trying to change someone’s rank on my group with the Groups Api. os.environ[".ROBLOSECURITY"] is my account key I got from the cookies page. It worked in another project with the catalog, and economy APIs but it doesn’t work in mine. I decided to use the exact same key to get my robux balance and it worked. Why isn’t it working with the Groups API?
python code:

import requests, os

userId = 2747902661

response = requests.patch(f"https://groups.roblox.com/v1/groups/9697297/users/{userId}", cookies={".ROBLOSECURITY": os.environ[".ROBLOSECURITY"]}, json={"roleId": 73986715})
print(response.status_code, response.text)

response = requests.get(f"https://api.roblox.com/currency/balance", cookies={".ROBLOSECURITY": os.environ[".ROBLOSECURITY"]})
print(response.status_code, response.text)

This is the Output:

403 {"errors":[{"code":0,"message":"Token Validation Failed"}]}
200 {"robux":508}
1 Like

Your .ROBLOSECURITY cookie often refreshes try grabbing it again by visiting any Roblox page and checking your cookies.

2 Likes

It didn’t work, I copied it again from Roblox but it’s still the same output, where the group API fails but getting my robux balance worked, this is the output:

403 {"errors":[{"code":0,"message":"Token Validation Failed"}]}
200 {"robux":508}

Thanks for the help though.

https://groups.roblox.com/v1/groups/9697297/users/

Visit the link itself, grab the cookie from request headers. Use developer tools if you’re on Chrome.

Oh, you’re sending a patch request to update a user in the group, you’ll need to send your CSRF-Token as well.

“x-csrf-token” is the header name you’re looking for.

It works now, thank you so much!