Coding Help for Roblox API and Understanding Pages and Paging Cursors

  1. What do you want to achieve? Keep it simple and clear!
    I want to get each page, of however many items that may contain, for Roblox API.

  2. What is the issue? Include screenshots / videos if possible!
    I am not very good at making and understanding pages. It confuses me and I could use some help.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried reverse engineering the Roblox Documentation for Stand Pages, but that doesn’t help as this is json requests I’m trying.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
This is the API I’ve been using:
The limit is 100 and I want to load at least 10x that many, at max.
So in the Output, along with the items in the data that is outputs, there is the ["nextPageCursor"] which if there was some way to bring it back up and put it back into original function to make like a courintine.wrap function or something that goes through each page.

This is just one page that only loads a max of 100 items:

local function festchplayerRoles(plyr,GroupId, RoleId)
	local Stuff = {
		Url = `https://groups.roproxy.com/v1/groups/{GroupId}/roles/{RoleId}/users?limit=100&sortOrder=Asc`,
		Method = "GET",
		Headers = {
			["Content-Type"] = "application/json",
		},
	}
	local success, MainData = pcall(function()
		return HTPS:RequestAsync(Stuff)
	end)

Any idea how to do a page items with Roblox API and json?

And the link with the Next page Cursor looks like this:

https://groups.roblox.com/v1/groups/15911622/roles/89278583/users?limit=100&cursor=3183562523_1_7d7dfe983d4241be26fb6abaec33ca38&sortOrder=Asc

1 Like

The API returns a cursor ID for each page in the group. Using those cursor IDs you can go through each page of a group to get the players.

To make a system like this, you can create a while loop that runs the function, gets the next page cursor ID from that function, and runs the function again with that cursor ID so it gets to the next page.

Wouldn’t it start running and then break when it runs out?

So, something like this?

local function festchplayerRoles(plyr,GroupId, RoleId)
	local Info = {}
	local nextPageCursor = nil
	while true do
		if nextPageCursor == nil then
			local Stuff = {
				Url = `https://groups.roproxy.com/v1/groups/{GroupId}/roles/{RoleId}/users?limit=100&sortOrder=Asc`,
				Method = "GET",
				Headers = {
					["Content-Type"] = "application/json",
				},
			}
			local success, MainData = pcall(function()
				return HTPS:RequestAsync(Stuff)
			end)
			table.insert(MainData, HTPS:JSONDecode(MainData.data))
			nextPageCursor = MainData.nextPageCursor
		else
			local Stuff = {
				Url = `https://groups.roproxy.com/v1/groups/{GroupId}/roles/{RoleId}/users?limit=100&sortOrder=Asc&cursor={nextPageCursor}`,
				Method = "GET",
				Headers = {
					["Content-Type"] = "application/json",
				},
			}
			local success, MainData = pcall(function()
				return HTPS:RequestAsync(Stuff)
			end)
			table.insert(Info, HTPS:JSONDecode(MainData.data))
			nextPageCursor = MainData.nextPageCursor
		end		
	end
end

Here’s a neat algorithm for you:

  • Define a table that will hold all the player names in the group.
  • Create a while loop that will go through each and every page of the group.
  • This while loop will call the function without a cursor id first, returning the data of the group with the players. First, save the players’ names to the defined table.
    Then if there are no next pages, the function will return no cursor ids, if this is the case, break the while loop using the break keyword.
  • If there’s a cursor id, call the function again with that cursor id so it uses that id to make an API request that will get the next group page with the players.
  • The while loop will repeat this until there are no cursor ids, which then the first case should happen. After the while loop breaks, you can print out the table or use it however you wish.

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