Presence API Bad Request

I want to make a POST request to https://presence.roblox.com/v1/presence/users but it keeps saying "There was an error while accessing presence.roblox.com: HTTP 400 (Bad Request). I’ve looked on the Forum if somebody else has it but I found no post about it. Here is the Script I’m using:

-- Services

local HTTP = game:GetService("HttpService")
local ReplicatedS = game:GetService("ReplicatedStorage")

-- Variables

local URL = "https://presence.roproxy.com/v1/presence/users"
local Remote = ReplicatedS:FindFirstChild("Player")

-- Functions

local function getPresenceData(plr : Player, userID : number)
	
	local presenceData = {}
	
	local data = HTTP:JSONEncode({
		["userIds"] = userID
	})
	
	local succ, response = pcall(function()
		
		return HTTP:PostAsync(URL, data)
		
	end)
	
	if succ then
		
		print(response)		
		Remote:FireClient(plr, response)
		
	else
		
		warn("There was an error while accessing presence.roblox.com : " .. response)
		
	end
	
end

Remote.OnServerEvent:Connect(getPresenceData)

It would be cool if somebody had a solution :slight_smile:

userID has to be in a list
zzzzzzzzzzzzzzzzzzzzz

the parameter is the UserID so that can’t be the error

The reply above is correct. The docs clearly show an example request body that has “userIds” as a list (array).

local data = HTTP:JSONEncode({
	["userIds"] = {userID}
})

I think that was a skill issue from my side. Thank you so much, now it works! I knew I had to put it in curly brackets but forgot it :sweat_smile:

that is definitely not what i said but im glad @hell_ish cleared it up :+1:

1 Like

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