Python Code for creating gamepasses keeps bugging and giving random errors for literally no reason

I do everything it says in the errors, it tells me hey copy universe id… I copy universe id now theres a new error. It says “hey check if read/write is enabled for this place” read and write is literally enabled and restricted to be only directed towards this place???

Heres my code pls help guys :sob: :sob: :sob: i’ve been arguing with ChatGPT + Gemini for like an hour straight while making sure to be as specific as possible yet they can’t fix it literally what’s happening :sob:… I know python a bit and this looks PERFECTLY fine??? what could possibly be the issue all I see are output errors for THINGS I FIXED…


import requests
import random
import time

# --- CONFIGURATION ---
# 1. API Key (Ensure "developer-products" Read/Write is checked in the dashboard)
API_KEY = "kU xKZ1NoUmxwWVlZ dEJUREZfbjN"

# 2. Universe ID (Confirmed Game ID)
UNIVERSE_ID = "9452487574" 

# Tiers
prices = [1, 2, 5, 10, 20, 50, 80, 100, 500, 1000, 2500, 5000, 10000, 50000, 100000, 250000, 500000, 1000000, 5000000, 10000000, 50000000, 100000000]

adjectives = ["Epic", "Legendary", "Giga", "Ultimate", "Godly", "Omega", "Insane", "Divine", "Mythical", "Astral"]
nouns = ["Donation", "Gift", "Contribution", "Tribute", "Blessing", "Flex", "Support", "Sacrifice", "Offering"]

def check_connection():
    """Verify if the API key can see the Universe before starting."""
    url = f"https://apis.roblox.com/cloud/v2/universes/{UNIVERSE_ID}"
    headers = {"x-api-key": API_KEY}
    response = requests.get(url, headers=headers)
    if response.status_code == 200:
        print(f"✅ Connection Successful! Verified Universe: {UNIVERSE_ID}")
        return True
    else:
        print(f"❌ Connection Failed (Error {response.status_code}): {response.text}")
        print("💡 Check: Is the game added to the API Key permissions in the Dashboard?")
        return False

def create_dev_product(price):
    name = f"{price:,} Robux {random.choice(adjectives)} {random.choice(nouns)}"
    url = f"https://apis.roblox.com/cloud/v2/universes/{UNIVERSE_ID}/developer-products"
    
    headers = {
        "x-api-key": API_KEY,
        "Content-Type": "application/json"
    }
    
    payload = {
        "displayName": name,
        "description": f"A generous {price:,} Robux contribution!",
        "price": price
    }

    response = requests.post(url, headers=headers, json=payload)
    
    if response.status_code in [200, 201]:
        data = response.json()
        prod_id = data.get('id') or data.get('path', '').split('/')[-1]
        print(f"✅ Created Product: {name} (ID: {prod_id})")
        return prod_id, price
    elif response.status_code == 429:
        print("⚠️ Rate limited. Waiting 15s...")
        time.sleep(15)
        return create_dev_product(price)
    else:
        print(f"❌ Error {response.status_code}: {response.text}")
        return None, None

# --- RUN ---
if check_connection():
    final_table = {}
    print(f"🚀 Starting creation for {len(prices)} products...")

    for p in prices:
        pid, pval = create_dev_product(p)
        if pid:
            final_table[pid] = pval
        time.sleep(1.5)

    if final_table:
        print("\n" + "="*40)
        print("local DonationProducts = {")
        for pid, pval in final_table.items():
            print(f"    [{pid}] = {pval},")
        print("}")
else:
    print("🚫 Aborting: Please fix the connection error above first.")
1 Like

This is just one thing I noticed, but I think your price parameter is incorrect. The third parameter should be a boolean indicating whether your dev product is for sale or not. Also mind showing the exact errors and which lines they’re happening at?

1 Like

Okay thanks kinda strange how gemini is still doing allat yeah this isn’t my code I got gemini to do it while giving long Shakespearan esque prompts, which is why i’m writing like this on the devforum right now. Anyway, yeah i’m barely experienced in python so i didn’t realise that but thanks for the advice so I can learn more python! I’ll see if that changes anything. Let me see the output.

1 Like

=========== RESTART: C:\Users\mwmtm\Desktop\Auto_Create_Gamepasses.py ==========
:cross_mark: Connection Failed (Error 401): {“errors”:[{“code”:0,“message”:“Invalid API Key”}]}

:light_bulb: Check: Is the game added to the API Key permissions in the Dashboard?
:prohibited: Aborting: Please fix the connection error above first. It’s in the API key dashboard permissions in the dashboard though im confused… It doesn’t show a UI saying it is in the search tab but when i goto search it it’s grayed out for some reason…

1 Like

To me, this key does look invalid. The key is usually alot longer, and there shouldn’t be any spaces.

By the way I suggest you learn the risks of API keys and cookies, i’m not a bad guy but if someone knows your api key they could use your api key and ruin your game. I hope the key code you wrote here is invalid because you never know what type of people lurk here. I mean if it’s not invalid I can always ruin your game for you.

Oh yeah and the same thing but worse for roblox cookies, if someone knows your roblox cookie they can ruin your account instead of your game. Which is alot worse.. So make sure your cookie and api key are hidden somewhere safe.

Neither am I lol, I don’t even know all of python’s fundamentals properly. It took me a bit of time to properly learn httpservice but you don’t need to learn python for it. You should only be writing luau code when you’re in roblox studio. All I had to learn was a bit of basics of web development like how HTTP headers work and how JSON data works.

You don’t even need to write in JSON in scripts, you can just convert any of your luau dictionaries into json with the json encode method in httpservice and then send over that json data when sending a post request.

Pro tip: Always use requestasync, it’s just so much better than any other method.

I recommend you use the documentation instead of ai since ai is just using data off google, it taught me alot and helped me learn the complex service quite fast. here’s some resources I used:

https://create.roblox.com/docs/reference/engine/classes/HttpService

https://create.roblox.com/docs/cloud-services/http-service

2 Likes

The API key I just changed for post engagement to be invalid but shorter so people commented on it and boosted my post to the top over and over so I got actual support.

1 Like

I want to use the python documentation but it’s so ugly but sure i’ll try Roblox when I get the time since I have a busy schedule.

1 Like

Well roblox studio is based on lua so why would you use the python documentation? They’re both documentations for completely different things. For roblox you should always use documentation + devforum thats my goto anyway and the roblox docs are really good for roblox.

1 Like

I’m not using Roblox Studio to write the code though, I’m using python which is why I might need to read python documentation because it might be a python issue as well. I don’t know if it’s both or just Studio…

2 Likes

It could be an issue with python because I don’t know how you’re using python code on stuff in studio. I know there are some plugins but i’m pretty sure it’s not a good idea anyway because python is much slower than luau. You should just write up all your code in luau always.

2 Likes

Python is very good for automation and stuff in general, so it has libraries like lua modules etc or how regular lua has libraries to do stuff on the web etc… I doubt its a python issue tho since the first error talks about the API key not the python code… I had an error earlier for the python code and it went away…

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