Httpservice POST is acting abnormal, 401 unauthorized

Okay to begin with, yes, I did heavy research and still cannot figure this out, asked my friends and they said its a problem with your game, yes… My settings inventory is open to everyone, it is not a problem with the user.

http service enabled

local HttpService = game:GetService("HttpService")

local link = "https://presence.rprxy.xyz/v1/presence/users"
local params = {
	["userIds"] = {
		51967249
	}
}
local response = HttpService:PostAsync(link, HttpService:JSONEncode(params), Enum.HttpContentType.ApplicationJson, false)
print(response)

Basically I am trying to get this:
https://presence.roblox.com/docs#!/Presence/post_v1_presence_users
but it keeps erroring. I used 2 different proxies and tried changing how my code was setup, I got a table error that again said “401 unauthorized”, the other http requests I send seem to work fine but why won’t this post work? The other questions I searched were linked to trello, this has nothing to do with it…

Thanks for any help.

3 Likes

Are you having problem’s with just enabling HTTP Service?

Nope, I enabled it, the other api tests I have done worked but they are unrelated to ‘post’, they are ‘get’

I have no idea. It never happened to me before. Anything else I can help you with?

Is there any sample code you have with PostAsync that I could see?

Try this code and if it does not work then you can contact me on discord and see what we can do there!

Code:

local HttpService = game:GetService("HttpService")
 
local URL_PASTEBIN_NEW_PASTE = "https://pastebin.com/api/api_post.php"
local dataFields = {
	-- Pastebin API developer key from
	-- https://pastebin.com/api#1
	["api_dev_key"] = "FILL THIS WITH YOUR API DEVELOPER KEY";    
	
	["api_option"] = "paste";                                -- keep as "paste"
	["api_paste_name"] = "HttpService:PostAsync";            -- paste name
	["api_paste_code"] = "Hello, world";                     -- paste content
	["api_paste_format"] = "text";                            -- paste format
	["api_paste_expire_date"] = "10M";                       -- expire date        
	["api_paste_private"] = "0";                             -- 0=public, 1=unlisted, 2=private
	["api_user_key"] = "";                                   -- user key, if blank post as guest
}
 
-- The pastebin API uses a URL encoded string for post data
-- Other APIs might use JSON, XML or some other format
local data = ""
for k, v in pairs(dataFields) do
	data = data .. ("&%s=%s"):format(
		HttpService:UrlEncode(k),
		HttpService:UrlEncode(v)
	)
end
data = data:sub(2) -- Remove the first &
 
-- Here's the data we're sending
print(data)
 
-- Make the request
local response = HttpService:PostAsync(URL_PASTEBIN_NEW_PASTE, data, Enum.HttpContentType.ApplicationUrlEncoded, false)
-- The response will be the URL to the new paste (or an error string if something was wrong)
print(response)
1 Like

Tried that already, didn’t work, that is a pastebin link and I am working with a proxy

Try looking through the reply’s here and this may resolve your problem!

HTTP Service

This error means you need to be signed in to use this endpoint. You’d need to use cookies in the header to do that.

3 Likes

I can use any userid in the userPresenceRequest on the presence api. I don’t see how I’d get their cookie and if that is even legal, I don’t want to end up leaking their cookies either…

1 Like

You just need to be signed into an account, not their account. I don’t know why that’s how it works, but it is.

3 Likes

So basically when I play the game it should work because I am signed into my current account, I am so lost… Is there anything I specifically need to change, wait, do I need to put my cookie in the header?

1 Like

No, it won’t work when you play the game. Remember, HttpService can only be used on the server, so it won’t be able to fire an endpoint for a player. You have to use HTTP headers (specifically, a cookie) to tell the endpoint “hey, I’m signed in. This is who I’m signed in as.”

3 Likes

To anyone else that can’t figure this out, I used the legacy way of fetching the users previous data. So I really didn’t solve this… Maybe you learned something from rogchamp but the legacy way is how I got it done.

1 Like