Help with roblox group ranking API 401 not authorized

What is the issue?

I am trying to make a ranking bot in with the Roblox Groups Api (roblox.com) but it keeps returning 401 and I have no idea how to fix it.

What solutions have you tried so far?

I’ve looked through many posts on dev forum and none really address my problem fully any help is apricated

Python:

import requests

cookie = "_|WARNING:-DO-NOT-SHARE-THIS.--Sharing-this-will-allow-someone-to-log-in-as-you-and-to-steal-your-ROBUX-and-items.|cookie"
authurl = "https://auth.roblox.com/v2/login"

url="https://groups.roblox.com/v1/groups/7583002/users/553259739"
requestBody = {"roleId" : 47464947}

def getXsrf():
  xsrfRequest = requests.post(authurl, cookies={'.ROBLOSECURITY': cookie})
  return xsrfRequest.headers["x-csrf-token"]

def rankUp():
  xsrf = getXsrf()
  print(xsrf)
  Response = requests.request(
       "PATCH",
        url,
        headers= {
                "Cookie": cookie,
                "Content-Type": "application/json",
                "Accept": "application/json",
                "X-CSRF-TOKEN": xsrf},
                data = requestBody)
      
  print(Response.status_code, Response.headers)
rankUp()

Output:

401 {‘cache-control’: ‘no-cache’, ‘pragma’: ‘no-cache’, ‘content-length’: ‘83’, ‘content-type’: ‘application/json’, ‘expires’: ‘-1’, ‘x-frame-options’: ‘SAMEORIGIN’, ‘strict-transport-security’: ‘max-age=3600’, ‘roblox-machine-id’: ‘CHI1-WEB4264’, ‘p3p’: ‘CP=“CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE”’, ‘date’: ‘Sun, 15 May 2022 21:16:38 GMT’, ‘report-to’: ‘{“group”:“network-errors”,“max_age”:604800,“endpoints”:[{“url”:“https://ncs.roblox.com/upload”}]}’, ‘nel’: ‘{“report_to”:“network-errors”,“max_age”:604800,“success_fraction”:0.001,“failure_fraction”:1}’}

Any help would be greatly apricated :slight_smile:

1 Like

The Cookie header in your Patch request should start with “.ROBLOSECURITY=” I believe

Never mind I mistyped it but I still get an error this time:

400 {‘Content-length’: ‘90’, ‘Cache-Control’: ‘no-cache’, ‘Connection’: ‘close’, ‘Content-Type’: ‘text/html’}

You probably need to json encode the request body

Nope. I still get the same error

What is the error message you’re getting with status code 400? And what does your current code look like?

Print out the response body, it should specify what the issue is.

python:

import requests
import json 

cookie = "_|WARNING:-DO-NOT-SHARE-THIS.--Sharing-this-will-allow-someone-to-log-in-as-you-and-to-steal-your-ROBUX-and-items.|_cookie"

authurl = "https://auth.roblox.com/v2/login"

url="https://groups.roblox.com/v1/groups/7583002/users/553259739"
requestBody = json.loads('{"roleId" : 47464947}')

def getXsrf():
  xsrfRequest = requests.post(authurl, cookies={'.ROBLOSECURITY': cookie})
  return xsrfRequest.headers["x-csrf-token"]

def rankUp():
  xsrf = getXsrf()
  print(xsrf)
  Response = requests.request(
       "PATCH",
        url,
        headers= {
                ".ROBLOSECURITY=": cookie,
                "Content-Type": "application/json",
                "Accept": "application/json",
                "X-CSRF-TOKEN": xsrf},
                data = requestBody)
      
  print(Response.status_code, Response.headers,Response.text)
rankUp()

Output:

xrf token (pretend its there)
400 {‘Content-length’: ‘90’, ‘Cache-Control’: ‘no-cache’, ‘Connection’: ‘close’, ‘Content-Type’: ‘text/html’}

400 Bad request


Your browser sent an invalid request.

json.loads converts json to a dictionary, you should use json.dumps(requestBody) to convert your dictionary to json.

Your headers should look like this

headers = {
    "Cookie": ".ROBLOSECURITY=" + cookie,
    # etc
}

and data

data = json.dumps(requestBody)
1 Like

Thank you so much it works now :slight_smile:

1 Like