What is api.roblox?

Direct requests to the Roblox API, ie. From a Roblox Game cannot be completed.

You can either use a pre existing proxy which can be found with a quick google search (something like https://roproxy.com [have not tested personally]) or you can set up your own proxy via something like repl.it, glitch, or heroku.

If you’ve ever used “:IsInGroup()”, “:GetRankInGroup()”, “:GetRoleInGroup()” and the many other API-oriented instance methods then you’ve essentially queried Roblox’s API. It is far from “useless”.

1 Like

sorry for that but can you give me a example on using api.roblox? it would help alot :smiley:

also yes i have used them

Once again, it depends on what you want to achieve. For the sake of simplicity, I will use RoProxy, the proxy I provided earlier (https://roproxy.com). For example, we’ll say you want to get how many favourites a game has.

I’ll take you step by step.

Firstly, you’ll need to enable HttpService. This can be done from the Game Settings panel if published or by running this in the command bar.

game:GetService("HttpService").HttpEnabled = true

Now that HttpService is enabled, we’ll create a server script and define HttpService.

local HttpService = game:GetService("HttpService")

We’ll take a look at the game API documentation (https://games.roblox.com/api), and we’ll switch from V2 to V1 so we can see the endpoint we need. From this documentation, we can see that there are a few ways we can get the favourite count of a game. For this demonstration, we’ll use the /v1/games/{universeId}/favorites/count endpoint (Found Here).

From this endpoint documentation, we can see that it is a GET request and takes a path parameter within the URL (universeId).

local HttpService = game:GetService("HttpService")
local favorites = HttpService:GetAsync("https://games.roproxy.com/v1/games/123456/favorites/count")

We’ll use :GetAsync() to make a GET request to our favourites endpoint. Swap “123456” with the Universe Id you want to get data from. Once again, we use roproxy.com in place of roblox.com within the URL, as a proxy.

:warning: Keep in mind: This is a Universe ID, NOT a Place ID.

Now that we’ve sent our get request, we can use our data retrieved from the endpoint. For the sake of demonstration, we’ll print the favourites count.

local HttpService = game:GetService("HttpService")
local favorites = HttpService:GetAsync("https://games.roproxy.com/v1/games/123456/favorites/count")

print(favorites)

Let’s see what outputs from this. It printed {“favoritesCount”:1} in our output. Hooray! We’ve gotten the favourites, but we aren’t done yet.

Let’s actually go to use this data. We’ll print out the actual favourites count itself.

local HttpService = game:GetService("HttpService")
local favorites = HttpService:GetAsync("https://games.roproxy.com/v1/games/123456/favorites/count")

print(favorites.favoritesCount)

Let’s see what happens here. It outputs nil. :face_with_raised_eyebrow:

Why?
The response provided from the API is JSON data. In order for us to actually use this data, we need to decode it to a format that we can use. Thankfully, we can just use JSONDecode through HttpService. Let’s just set our favourites variable to be the table we receive from decoding it and print the count.

local HttpService = game:GetService("HttpService")
local favorites = HttpService:GetAsync("https://games.roproxy.com/v1/games/123456/favorites/count")
favorites = HttpService:JSONDecode(favorites)

print(favorites.favoritesCount)

We now get the favourites count in a format we can use.

:partying_face: | Congratulations! You’ve just used a Roblox API endpoint to get the favourites of a Game.

There are so many other possibilities with API endpoints, and I encourage you to continue to explore them. Obviously, this is still an example in all and you can adapt it however you’d like to achieve whatever you’re looking to do with it.

References:
Games API - https://games.roblox.com/docs
HttpService Documentation - HttpService
RoProxy - https://roproxy.com (proxy used in this demo)

Keep on exploring,
Ovadux

2 Likes

Thank you for helping me! this tutorial helps ALOT! like ALOT ALOT! just wanted to thank you!

1 Like

also i think i can also get like likes dislikes visits players etc

You sure can! Use the /v1/games/votes endpoint (Found Here). Just use the code from the last reply and use the votes endpoint URL instead. Once again, I’ll use print statements as a demo. It should look something like this.

local HttpService = game:GetService("HttpService")

local favorites = HttpService:GetAsync("https://games.roproxy.com/v1/games/123456/favorites/count")
favorites = HttpService:JSONDecode(favorites)

local votes = HttpService:GetAsync("https://games.roproxy.com/v1/games/votes?universeIds=123456")
votes = HttpService:JSONDecode(votes).data[1]

print("Favorites: "..favorites.favoritesCount) --number of game favorites
print("Likes: "..votes.upVotes) -- number of game likes
print("Dislikes: "..votes.downVotes) --number of game dislikes

This endpoint sends a response in an array through the data object. Once we have decoded the JSON, we have to get the data with .data and then specify that we want to get the first object in our array with [1].

Happy developing,
Ovadux

3 Likes

this makes me feel like I am a noob lol

2 Likes