How to retrieve all existing gamepass id's for a game

  1. What do you want to achieve?
    I want to retrieve a list of all existing gamepass id’s for a game and add them to a table. To be clear, I do not want to update the IDs manually every time I create a new gamepass.
  2. What is the issue?
    I can not find any documentation, syntax, or existing forum posts that have an effective way of doing this.
  3. What solutions have you tried so far?
    Looked for solutions on Developer Hub, YouTube, and any websites I could find.
1 Like

The BTRoblox README is usually where I look to answer my own roblox API questions.

For your question, first you’re going to need your universe ID. We can make an api request to
https://api.roblox.com/universes/get-universe-containing-place?placeid=1818. (the number being your place id of choice)

This responds with JSON data that looks like this:

{
    "UniverseId": 13058
}

Once you retrieve your universe ID with HttpService:JSONDecode(), we can move on to requesting gamepasses.

We need to make requests to
https://games.roblox.com/v1/games/13058/game-passes?limit=100&sortOrder=1. (the number after /v1/games being the universe ID.)
In your case, we do not need to change sortOrder because all we need is a list of gamepass IDs.

The response JSON data looks somewhat like this:

{
  "previousPageCursor": "id_2zwAAAYSGa_2rzgY7JK0",
  "nextPageCursor": null,
  "data": [
    {
      "id": 104539309,
      "name": "a",
      "displayName": "a",
      "productId": null,
      "price": null,
      "sellerName": "Roblox",
      "sellerId": null,
      "isOwned": false
    }
  ]
}

You can iterate through the data and add each ID to a table, but for your code to scale correctly, I would suggest recursively using the nextPageCursor in the response to keep re-requesting more gamepasses by adding another query parameter: &cursor=1234 (1234 being the nextPageCursor).

1 Like

Thanks so much for the help! This is exactly what I needed. However what exactly is a cursor in this case?

When trying to retrieve the JSON I get the following error: HttpService is not allowed to access ROBLOX resources

Replace Roblox with roproxy. This is what I use at least to access Roblox API in game.

I heard about that. Is it secure, though? Does it have any security risk?

I wouldn’t be using it if it had any Security Risks. You aren’t really supposed to use Token Information with the Roblox API within’ Roblox. Hence why they locked it in the first place, so people didn’t try and risk putting their cookie token in their game.

If your scared that the spooky dookie government is going to spy on your Tax Evasion. Just don’t use it. But if your terrified that a person is going to see your requests. Your fine.

Alright thanks. I just know they say not to send HTTP requests to non trusted links because they can provide security risks for your games.

hmm i tried this, but its not seeming to print anything

-- // Register Gamepasses
Players.PlayerAdded:Connect(function(Player : Player)
	-- // Setup Gamepasses to table
	local profile = DataManager:Get(Player)
	repeat task.wait() until profile
	
	local URL = `https://games.roproxy.com/v1/games/{game.GameId}/game-passes?limit=100&sortOrder=1.`
	local success, result = pcall(function()
		return httpService:GetAsync(URL)
	end)
	
	if success then
		local placeGamepasses = httpService:JSONDecode(result)
		
		print(placeGamepasses)

		for _, gamepass in placeGamepasses do
			local gamepassData = gamepass.Data
			print(gamepassData)
		end
	end
end)

im pretty new to httpService and using external apis, could you help me out with this?

You mean to write:

local URL = `https://games.roproxy.com/v1/games/{game.GameId}/game-passes?limit=100`

local success, response = pcall(HttpService.GetAsync, HttpService, URL)
if not success then
    warn(response)

    return
end

local gamePasses = HttpService:JSONDecode(response)

for _, gamePass in gamePasses.data do
    print(gamePass)
end

Nonetheless, your code is fine. It could be that your script is in an inappropriate location, that the data profile is never loading, or an edge case with Players.PlayerAdded firing

So I copied this code and I added a test gamepass but it’s not printing nothing…, but I’m confused on what you mean by inappropriate location, the script is in Server Script Service.
image

Maybe its because I did the URL wrong? Not sure, any help would be appreciated!

I do not see why you need to get the player’s profile for this test. Remove that code and the Players.PlayerAdded event

I was initializing the players gamepass table inside of their profile, thats what the Players.PlayerAdded

even when I did get the gamepass IDs outside of the PlayerAdded event nothing prints but it prints outside though, why is that?

-- // Register Gamepasses
local gamepassIDs : {} = {} do
	local URL = `https://games.roproxy.com/v1/games/{game.GameId}/game-passes?limit=100`
	local success, response = pcall(httpService.GetAsync, httpService, URL)
	if not success then
		warn(response)
		return
	end
	
	local gamePasses = httpService:JSONDecode(response)
	for _, gamePass in gamePasses.data do
		table.insert(gamepassIDs, tonumber(gamePass.id))
	end
    print(gamepassIDs)
end

Players.PlayerAdded:Connect(function(Player : Player)
	-- // Setup Gamepasses For Player
	local profile = DataManager:Get(Player)
	repeat task.wait() until profile

	for _, id in gamepassIDs do
        print(id)
		local isOwned = marketPlace.Get(Player, id)
		
		if isOwned then
			marketPlace.AddGamepass(Player, id)
		end
	end
end)