Need help with httpService?

In my game I have two http requests that I make, the first one is done like this:

	local url = "https://users.roproxy.com/v1/users/"
		local payload = game.HttpService:JSONEncode({userIds = idTable, excludeBannedUsers = false})
		local success, response = pcall(function()
			return game.HttpService:PostAsync(url, payload, Enum.HttpContentType.ApplicationJson)
		end)

You give it a table of userIds and it returns information about each user, but I would also like to be able to get each users follower count, so I created this script:

		local url2 = ("https://friends.roproxy.com/v1/users/{there id}/followers/count")
		local payload2 = game.HttpService:JSONEncode({userIds = idTable, excludeBannedUsers = false})
		local success2, response2 = pcall(function()
			return game.HttpService:PostAsync(url2, payload2, Enum.HttpContentType.ApplicationJson)
		end)

My Issue is that the userId needs to go in the middle of the URL and not at the end (https://friends.roproxy.com/v1/users/USER ID Goes Right Here/followers/count).

How would I go about making the URL use the table of Ids like I do in the first script, even though the Id goes in the middle of the URL.

Thanks!

(Note: I am new to using the httpService, so all this is a bit confusing)

1 Like
local function getFollowersAmount(userId: number): number
	--proxy this
	local url = "https://friends.roblox.com/v1/users/"..userId.."/followers/count"
	--pcall this
	local response = game.HttpService:GetAsync(url)
	local data = game.HttpService:JSONDecode(response)
	return data.count 
end

for _, userId in pairs(idTable) do
	local followers = getFollowersAmount(userId)
	print(userId, "has", followers, "followers!")
end
1 Like

This works, thank you!

Quick question though, sometimes i get HTTP 400 (Bad Request) instead of the players follower count, any idea why? (The userIds are randomly generated each time, so is it possible the reason is because the player doesn’t exist or was banned?)

Thanks!

For this endpoint 400 means the user doesn’t exist. You should first verify the id you pass in the function exists, your old function that makes a POST request only returns data of existing ids. So you can use that:

for _, user in pairs(usersResponse.data) do
	local followers = getFollowersAmount(user.id)
	print(user.id, "has", followers, "followers!")
end

Where usersResponse.data is the list of users you got in the older response by passing in idTable.

1 Like

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