Endpoints for dummies - An HttpService Guide

Hey there, this post will teach you how to use endpoints. For a while I didn’t know how JSon worked and always knew it played a big part in programming. I decided to research it but nothing online made sense. To think of it, it plays a major role in this tutorial. My simple definition for it is basically a string to a table converter.

You might be wondering why you should learn this… In the future many jobs would love to hire people who can use JSon and use post and get methods.

To begin, you might be wondering why you would even use it, simple… To fetch data

Suppose you went to a website and wanted to collect data, you might use surveys or different techniques of obtaining data but that takes effort. Endpoints are here to help.

The list of current known endpoints for roblox:

With this I will talk about proxies. Proxies are like vpn’s, although it filters data and responses.

Proxies are essential since roblox doesn’t allow requests to their own site. The proxy will be used to send data to and from the site to your game.

An example proxy would be heroku or rprxy.xyz, I will get into detail with the code soon. Without a proxy you might recieve an error along the lines of Trust check failed

An appropriate endpoint I will be using in this example is devforum.
You can get the endpoint by typing devforum.roblox.com/u/username.json

Let’s get into the code now but before that make sure HTTP requests are on.

local HttpService = game:GetService("HttpService")
local function GetDevforumStats(username)
	local data = Proxy:Get("https://devforum.roblox.com/u/"..username..".json")
	local ReturnedJSon = HttpService:JSONDecode(data)
	return ReturnedJSon
end

In this example, I fetched the data using a proxy since devforums is linked to roblox. The data is currently raw and will be shown as a string. To convert it to a table you would use HttpService:JSONDecode(json string)

Currently I am using the Get method as shown in the example… That will get the data, the get method is not as safe as the post method but is much easier to use.

If you don’t understand how to create a proxy and get it in the format I did above, you could also do this:

local HttpService = game:GetService("HttpService")
local function GetDevforumStats(username)
	local data = HttpService:GetAsync("https://devforum.rprxy.xyz/u/"..username..".json")
	local ReturnedJSon = HttpService:JSONDecode(data)
	return ReturnedJSon
end

Now since you understand that, I will get into the details of how cursors work in endpoints, an example of this would be the badges api. Badges Api
Think of it as a unique key that is used to go to the next page or previous page. Ways to use this:

local function GetBadges2(id)
	local b = HttpService:GetAsync("https://badges.rprxy.xyz/v1/users/"..id.."/badges?limit=100&sortOrder=Asc")
	b = HttpService:JSONDecode(b)
	
	local totalBadges = 0
	while b.nextPageCursor do
		totalBadges = totalBadges + #b.data
		b = HttpService:GetAsync("https://badges.rprxy.xyz/v1/users/"..id.."/badges?limit=100&cursor="..b.nextPageCursor.."&sortOrder=Asc")
		b = HttpService:JSONDecode(b)
		print(totalBadges)
	end
	
	return totalBadges
end

In this example I am looping the next page cursor to get every badge the user owns. As shown by b.nextPageCursor.."&sortOrder=Asc", In the example, I am setting b to the newest cursor then looping it till the last page.

These are the basics, in the future, you would have to cope with headers and using tokens. For now this shall suffice. Thank you for taking the time to read my tutorial.

You can use postman to create endpoints. https://www.postman.com/

Updates:
Edit 1 - 11/17/20 .body is no longer needed, before: HttpService:JSONDecode(data.body) after: HttpService:JSONDecode(data)
Edit 2 - 9/26/21 rprxy no longer available, rely on your own proxy by using sites such as heroku.

25 Likes

Wow, it sounds really interesting! I don‘t know this was even possible, thanks for this tutorial! So, witht his method I could use all the functions from https://api.roblox.com/docs, wich its really important.

Correct, I am glad you liked my post c:

1 Like

This is super useful! Thank you so much for the guide!

1 Like

No problem bro. Glad that you find it resourceful

1 Like

Hi this post was pretty helpful the only problem I got is when you were using the API for badges it showed you how to create the URL

It doesn’t do this with the presence api

How would you set up the URL for the presence api?

There are a few endpoints within the presence api, https://presence.roblox.com/docs#/, since this is post rather than get you would have to send headers. There are other places to get the users previous time when they were online though that uses get. In the curl section, that will show how to set it up.

Thank you for the reply! Rather than getting the last time the user was online I was hoping to find a way to figure out what game a user is in like the game flamingo status tracker. This game does it by looking at the recent badges from the user. they use an API that can only figure out if the user is in-game or on the website. I thought of using the presence API because it indicates the exact game name the user is in.

Presence Api

Other Api

My problem with using the other API is that the game Id is null so you cannot figure out what game the user is currently in using the marketplace API. Is it possible to use the presence API and if not is it possible in any other way? Thank you for reading.