Retrieving badges API (help!)

Hi, I made a game that awarding all available badges when you joining it, but unfortunately, the API that I’m using can load only 100 badges per one page. So, can anyone edit this script to automatically retrieve all badges from next cursors? Script:

game.Players.PlayerAdded:Connect(function(Player)
	local http = game:GetService("HttpService")
	local BadgeService = game:GetService("BadgeService")
	local data = http:GetAsync("https://badges.roproxy.com/v1/universes/3487637972/badges?limit=100&sortOrder=Asc")

	if data then
		data = http:JSONDecode(data)
		for _, Badge in data.data do
			BadgeService:AwardBadge(Player.UserId, Badge.id)
		end
	end
end)

So, does anyone knows how to do that?

local cursor = ""
while cursor do
	local url = "https://badges.roproxy.com/v1/universes/3487637972/badges?limit=100&sortOrder=Asc"
	local json = http:GetAsync(url.."&cursor="..cursor)
	local data = http:JSONDecode(json)
	for _, badge in pairs(data.data) do
		--action per badge here
	end
	cursor = data.nextPageCursor
end

Thanks, if it’s working that will be sooooooooooooooo OP

You also need to pcall and handle each GetAsync request else if one of them fails(due to rate limits or internal server errors) the entire loop will break.

I don’t even tried pcall, Idk what’s it

Basically it catches an error within the API call if it occurs without breaking the script, based on the error you can choose to take certain actions like for example wait and retry or ignore said request etc. Depending on what you’re doing.

Thanks, but it somehow giving only 85 badges