Award all in-game badges via API

Hi, I’m making a game with free badges. Does anyone know how to award all badges when joining with using APIs?

Do you want to make it so that when a player joins a game he gets a badge?

Of course, I can help you with that! To reward all players with badges when they connect, you need to use the Roblox API to award badges. Here’s an example of how to do this using LuaU in Roblox Studio:

local BadgeService = game:GetService("BadgeService")
local BadgeID = 123456789 -- Replace with your badge ID

game. Players.PlayerAdded:Connect(function(player)
    local success, message = pcall(function()
        BadgeService:AwardBadge(player. UserId, BadgeID)
    end)

if success then
        print("Badge successfully issued!")
    else
        warn("Badge could not be issued: " .. message)
    end
end)

This script must be hosted in ‘ServerScriptService’ in order to be executed on the server side. Let’s take a closer look at it:

  1. ‘local BadgeService = game:GetService(“BadgeService”)’ — Get access to the badge service.
  2. ‘local BadgeID = 123456789’ – Replace ‘123456789’ with the actual ID of your badge.
  3. `game. Players.PlayerAdded:Connect(function(player)

Right. I want to award all available badges when player joined the game.

I wrote at the top, I hope it will help you

It doesn’t have any sense. I want to award all available badges without updating the game and with using API services.

I already know this script, but I don’t want to update the game for each badge.

That is, you want to make sure that not 1 badge is issued, but many?

I want to award 1K+ badges with one script without updating it each time

Loop through a table using the same function with all the badge ids

If that’s what you want, you can use the Badges Api v1 by Roblox: https://badges.roblox.com/docs/

You’d probably have to use /v1/universes/{universeId}/badges endpoint to get all the badges in the specific universe, and award all those badges either by using api, or BadgeService’s awardbadge

edit: since the limit for 1 request at a time is 100 badges, you’d have to use like a recursive function to get the request, and send the same request with data.nextPageCursor, store it all in a table, until nextPageCursor is nil, then return that table

You can use HTTP Service to do this. It’s still a Roblox API, but does what you ask for.

local uid = --Refer to posts below for ways to get the id]]--
local url = "https://badges.roproxy.com/v1/universes/"..uid.."/badges" -- Special link holding your game badges
local hs = game:GetService("HTTPService")
local badgetable = hs:JSONDecode(hs:GetAsync(url))


As you can see it took me to the proxy site with the badges. You might have to manipulate the table once decoded to achieve your goal

Make sure to publish your game and enable http requests in game settings prior to this. If my syntaxes are wrong (sry), do ask me for clarification or visit the hyperlink above!

1 Like

For correction, the placeId is what comes after the https://roblox.com/games/. As for the universeId, you can get it using the following: https://apis.roblox.com/universes/v1/places/<your placeId here>/universe

Oh my bad. I got my universe I’d using another proxy site. Thanks for the clarification

1 Like

Of course, you can also get it from the Creator Hub, specially that the point of this thread is to award badges.
image

Fair enough. There are so many ways to get it

I already know it, but how can I make a script that awarding first 100 badges, and then automatically other 101 - 1K+?

For this you need to fetch all badges through some web API and then reward them one by one to the player using BadgeService. The web response will be paginated, meaning that you will need to make different API calls per x returned badges. However this doesn’t mean you need to fetch all badges before rewarding them, you can solve the problem dynamically as follows:

local badgeIds: {number} = {}

local function badgesRoutine(): () 
	local universeId = game.GameId 
	--proxy this(example: replace roblox.com with roproxy.com)
	local url = "https://badges.roblox.com/v1/universes/"..universeId.."/badges"
	local cursor = ""
	while cursor do
		--we are using a small limit on purpose so we receive more frequent updates
		local request = url.."?sortBy=DateCreated&limit=10&sortOrder=Asc&cursor="..cursor
		--pcall and add retry logic to this
		local response = game.HttpService:GetAsync(request)
		local data = game.HttpService:JSONDecode(response)
		for _, badge in pairs(data.data) do
			if table.find(badgeIds, badge.id) then continue end
			table.insert(badgeIds, badge.id)
		end
		cursor = data.nextPageCursor
	end
end

local function awardBadges(player: Player)
	local i = 1
	while true do
		if not player then break end
		local badgeId = badgeIds[i]
		if not badgeId then
			task.wait(1)
			continue
		end
		--pcall and retry logic both calls
		if not game.BadgeService:UserHasBadgeAsync(player.UserId, badgeId) then
			game.BadgeService:AwardBadge(player.UserId, badgeId)
		end
		i += 1
	end
end

--call this once per player
game.Players.PlayerAdded:Connect(awardBadges)
--call this once
task.spawn(badgesRoutine) --run routine 

It’s not working bro, I also changed from roblox to roproxy to avoid errors in console and it still not working