Roblox Purchasing an item from catalog

Viewed 396

I have written a script that should purchase an asset from catalog.

import re
from requests import post, get

cookie = "blablabla"
ID = 1562150

# getting x-csrf-token

token = post("https://auth.roblox.com/v2/logout", cookies={".ROBLOSECURITY": cookie}).headers['X-CSRF-TOKEN']
print(token)
# getting item details

detail_res = get(f"https://www.roblox.com/library/{ID}")
text = detail_res.text

productId = int(get(f"https://api.roblox.com/marketplace/productinfo?assetId={ID}").json()["ProductId"])
expectedPrice = int(re.search("data-expected-price=\"(\d+)\"", text).group(1))
expectedSellerId = int(re.search("data-expected-seller-id=\"(\d+)\"", text).group(1))

headers = {
    "x-csrf-token": token,
    "content-type": "application/json; charset=UTF-8"
}

data = {
    "expectedCurrency": 1,
    "expectedPrice": expectedPrice,
    "expectedSellerId": expectedSellerId
}

buyres = post(f"https://economy.roblox.com/v1/purchases/products/{productId}", headers=headers,
              data=data,
              cookies={".ROBLOSECURITY": cookie})

if buyres.status_code == 200:
    print("Successfully bought item")

The problem is that it somehow doesn't purchase any item with error 500 (InternalServerError). Someone told me that if I add json.dumps() to the script it might work. How to add json.dumps() here (I don't understand it though I read docs) and how to fix this so the script purchases item? Big thanks to anyone who can help me.

2 Answers

Import the json package.

json.dumps() converts a python dictionary to a json string.

I'm guessing this is what you want.

buyres = 
post(f"https://economy.roblox.com/v1/purchases/products/{productId}", 
headers=json.dumps(headers),
          data=json.dumps(data),
          cookies={".ROBLOSECURITY": cookie})

I found the answer finally, I had to do it like this:

dataLoad = json.dumps(data)
buyres = post(f"https://economy.roblox.com/v1/purchases/products/{productId}", headers=headers,
              data=dataLoad,
              cookies={".ROBLOSECURITY": cookie})
Related