How to Get Users in a Role in a Group Using HttpService

I’m trying to get users in a selected role with HttpService, but it errors with “HTTP 400 (Bad Request)” so how would I fix this or do this differently?

local HttpService = game:GetService("HttpService")
local response = HttpService:JSONDecode(
	HttpService:GetAsync("https://groups.rprxy.xyz/v1/groups/4585564/roles/255/users?limit=10&sortOrder=Asc")
)

Also tried searching the Developer Forum but none of the topics helped.

2 Likes

You need to use https://groups.roblox.com/v1/groups/{groupId}/roles to get their ids. Then use the endpoint you used to get the users.

3 Likes

I don’t think you even need to use HttpService. You can check if a player is in a group or is a certain rank without any services. Example:

local rank = 0 -- The rank the player will need to get through

local groupID = 0 -- The group ID the player must be in

local character = game.Players.LocalPlayer

if (character:IsInGroup(groupID) and character:GetRankInGroup(groupID) == rank) then

print("The player is the correct rank.")

end

Just if you’re wondering, yes, I did test this. It works fine.

Could you show me an example I’d do that? I thought the role ids were just the group rank.

@SpeakerDev I’m not checking if a player is in a group or their roles I’m looking at users inside a group at a certain rank.

You could chain them like so:

local HttpService = game:GetService("HttpService")

function GetUsersInRank(groupId, rankNumber)
	local rankIds = HttpService:JSONDecode(
		HttpService:GetAsync("https://groups.rprxy.xyz/v1/groups/"..groupId.."/roles")
	)
	if rankIds.roles == nil then 
		warn("Something went wrong")
		return
	end
	for i, v in ipairs(rankIds.roles) do
		if v.rank == rankNumber then
			return HttpService:JSONDecode(
				HttpService:GetAsync("https://groups.rprxy.xyz/v1/groups/"..groupId.."/roles/"..v.id.."/users?limit=100&sortOrder=Asc")
			).data
		end
	end
	return nil
end

print(GetUsersInRank(4585564, 255))

Basically, ranks have an id behind them like an asset id. This id is not the same as the rank number. This id is a unique identifier across the platform and will only ever identify that one role.

2 Likes

Also is it possible to get the result by only using GetAsync once since you can only send 500 HTTP requests a minute and you might be doing other things with HttpService?

You can cache the rolesets of each group id and request it only when needed.

1 Like