Failed to fetch badges: Unable to cast token to bool

Hi, Im trying to make a script that will award every badge inside of a roblox game and im trying to use an api to do this, i dont have any api experience so i am struggling, i have this so far,

local apiUrl = "https://badges.roblox.com/v1/universes/4979760840/badges?sortOrder=Asc"
	local success, response = pcall(function()
		return HttpService:GetAsync(apiUrl, Enum.HttpContentType.ApplicationJson)
	end)
	if success then
		local responseData = HttpService:JSONDecode(response)
		for _, badgeInfo in ipairs(responseData.data) do
			print("Badge ID:", badgeInfo.id)
			print("Badge Name:", badgeInfo.name)
		end
	else
		warn("Failed to fetch badges:", response)
	end

I keep getting the error
Failed to fetch badges: Unable to cast token to bool
anything would be useful

3 Likes

Could you tell on which line the error occurs?

the line where it says

local response = HttpService:GetAsync(apiUrl, Enum.HttpContentType.ApplicationJson)

ok sorry for not analyzing the code, I saw that it was in a Pcall and that’s why I got confused, it seems silly but I could see that the Id is typed correctly and that the enumeration is correct, do you get the service right? do you know how the HttpService works?

No, i dont really know how it works yet

Why not just use the Badge Service?
edit: BadgeService | Documentation - Roblox Creator Hub

can i grab all the badge ids of the corresponding experience?

that is the exact forum i saw yet i dont understand that much

could the error be because i used Decode and not Encode?

It wouldn’t hurt to check…limited of characters

I did, nothing changed
(roblox character limit)

To access the Roblox Web API, utilizing a proxy is essential. My recommendation is to employ roproxy for this purpose! The designated link takes the following form:

https://badges.roproxy.com/v1/universes/4979760840/badges?sortOrder=Asc

what do i have to do to employ?

i Changed it to

local apiUrl = "https://badges.roproxy.com/v1/universes/4979760840/badges?sortOrder=Asc"

I still have the error is there anything else i must do?

Remove the second request argument:

return HttpService:GetAsync(apiUrl)

i removed the pcall so its like this now

local apiUrl = "https://badges.roproxy.com/v1/universes/4979760840/badges?sortOrder=Asc"
local response = HttpService:GetAsync(apiUrl, Enum.HttpContentType.ApplicationJson)
local responseData = HttpService:JSONEncode(response)
for _, badgeInfo in ipairs(responseData.data) do
	print("Badge ID:", badgeInfo.id)
	print("Badge Name:", badgeInfo.name)
end

Remove this argument, it’s the cause of the error.

The second argument of GetAsync is named nocache and it’s a bool value, not an enum, that’s why the error occurs(it’s a type mismatch).

1 Like

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