How could I do this with Roblox Games Api?

The goal I am trying to get out of this is getting all the roblox games created into a json file with the game id inside it. I know how HttpService works but I still have the issue to do this.

Thanks!

(If this is not possible i will figure out alt ways!)

I don’t understand. Can you please try to explain your goal a bit better?

That’ll be appreciated to I can help you solve your problem :slightly_smiling_face:

do you mean all games in roblox over than 40 million game ? or some games ?

Yeah. All the games to exist on roblox.

I want to use the roblox api to create a json file with all the games and game ids inside

You could use the https://games.roblox.com/v1/games?universeIds={UNIVERSE_ID} endpoint and just have a loop that constantly increments the universe ID and writes the output to the JSON object.

Keep in mind you will most likely be ratelimited though.

2 Likes

How could I increment a json file?
like in a lua script?

Here’s a quick example:

local Http = game:GetService("HttpService")
local data = {} -- data
local uid = 0 -- current universe ID

while true do
    local s, e = pcall(function()
        return Http:GetAsync("https://games.roblox.com/v1/games?universeIds=" .. tostring(uid))
    end
    if s then
        local decoded = Http:JSONDecode(e)
        data[uid] = decoded.data[1]
    end
    uid += 1
    task.wait()
end

Note: You could do like ten Universe IDs at a time by separating them with commas in the query. For the sake of simplicity, I did one per request.

1 Like

Thanks for the example! How could i print the Id into the console?

Use print(uid) in the loop (before it’s incremented).

is the “+” the right thing or is it “…” to connect them?

Oh right, use .. to concatenate strings, not +.

here is a quick problem:

local Http = game:GetService("HttpService")
local data = {} -- data
local uid = 0 -- current universe ID

while true do
	local s, e = pcall(function()
		return Http:GetAsync("https://games.roblox.com/v1/games?universeIds=" .. tostring(uid))
	end)
	if s then
		local decoded = Http:JSONDecode(e)
		data[uid] = decoded.data[0]
	end
	uid += 1
	task.wait(.5)
	print(data[uid])
end

data[uid] prints nil or it could be that on roblox the games dont exist anymore

Another mistake, 0 is the starting index on most languages. Change it to 1 as that is the starting index in Lua.

I fixed it thanks for the help!