Roblox Game API Tutorial

Update 3/16/2023: This topic will teach you how to get some data from your game using a PUBLIC proxy (Hosting your own is more viable)

Points to see:

  1. Get the visits and the thumbnail of a game?
  2. Username and UserId of the creator.
  3. Place name and last update

Requires:

  1. It only works In-game, not in studio so you’d better publish it before testing
  2. You need to have HTTP Request enabled and access to the API

This tutorial was made especially for beginner users and to reduce the number of separate topics on this subject.

Game Visits:

Now as some know we need a proxy to be able to access, I will use “Roproxy”
To get the visits we will need to get the UniverseId.

Get UniverseId

To get the UniverseId of your game write: game.GameId

Getting the UniverseId of another game (not yours):

local HttpService = game:GetService("HttpService")
local GameId = 0000000000

local UniverseUrl = "https://apis.roproxy.com/universes/v1/places/"..GameId.."/universe"
local UniverseResponse = HttpService:RequestAsync({
	Url = UniverseUrl,
	Method = "GET"
});
local data = HttpService:JSONDecode(UniverseResponse.Body);
local UniverseId = data["universeId"]

With the UniverseId in our hands, we can finally see the total visits of our game

local HttpService = game:GetService("HttpService")
local UniverseId = game.GameId

local Url = "https://games.roproxy.com/v1/games?universeIds="..UniverseId
local IsSuccess, Result = pcall(function()
	return HttpService:GetAsync(Url)
end)

if IsSuccess then
	local data = HttpService:JSONDecode(Result)["data"][1]
	local visits = data["visits"]
	
	print("Game Visits: "..visits)
else
	warn("Something went wrong!")
end

HttpService can fail sometimes so there may be cases that the script doesnt progress, to solve this, its recommended to use pcall()

Game Thumbnail:

This is much easier, you will simply place the following:
Where it says “GameId” you put the id of your game.

"https://assetgame.roblox.com/Game/Tools/ThumbnailAsset.ashx?aid="..GameId.."&fmt=png&wd=420&ht=420"

Creator details:

For this we will need MarketplaceService:

local MarketPlaceService = game:GetService("MarketplaceService")
local info = MarketplaceService:GetProductInfo(GameId)

local CreatorId = info.Creator.CreatorTargetId
local CreatorName = info.Creator.Name

Extra:

local GameName = TheGame.Name

If you want more information: click here

Game Extra Data:

Dates

If you put something like “TheGame.Created”, it works… but its not clean
→ 2020-07-07T06:10:00.000Z
We want something like this:
→ 07-07-2020
So we create this function:

local function ConvertJsonDate(ISO8601Date)
	local GameDate = ISO8601Date:sub(1, 10)
	local TheDate = GameDate:split("-")
	return TheDate[3].."-"..TheDate[2].."-"..TheDate[1]	
end

and convert the dates:

ConvertJsonDate(TheGame.Created)
ConvertJsonDate(TheGame.Updated)

I hope this helps, especially for those trying to find random games like Super Place Roulette.

Where to find the roblox API?

Here: Roblox Docs

Conclusion:

The errors in the scripts were fixed, but dont forget that the proxy isn’t mine, so it can become deprecated at any time.

I’ve fixed this now, but I may not be able to do it in the future, so like I said before: Hosting your own is much more viable

19 Likes

This worked perfect, thank you. One question though, how would I get the likes and dislikes from this? If that’s even possible?

1 Like

Ive been looking for a while, its possible…
First you must obtain the UniverseId, with the method in the post

if UniverseResponse.Success then
    local Response = HttpService:RequestAsync({
    Method = "GET";
	Url = string.format("https://games.roblox.com/v1/games/votes?universeIds="..UniverseData.UniverseId);
});
    if Response.Success then
       local Body = HttpService:JSONDecode(Response.Body)
       local Likes = Body.data[1].upVotes;
       local Dislikes = Body.data[1].downVotes;
    end
end

I did it quickly, maybe you should change the variables, if it doesnt work, try to combine it with the previous method

1 Like

Shows nil for me, I did it with just the data and I cant find anything in the table that says upVotes or downVotes.

1 Like

The only thing found there is this [Example] and visits.
It would be exactly the same method, maybe you should combine both scripts? [along with visits]

if UniverseResponse.Success then
   (both codes)
end

Edit: Forget it, try this

Url = string.format("https://games.roproxy.com/v1/games/votes?universeIds="..UniverseData.UniverseId);
3 Likes

Does this still work? I can’t seem to get it, I followed the instructions correctly.

HTTP is enabled and Studio access to API, and I tested it in a public game.

So, it seems get-universe-containing-place endpoint has been removed.

Yep. Which is why you’d use the new endpoint to get the Universe Id.
Here’s a sample script that uses the correct Endpoint:

local HttpService = game:GetService("HttpService")

local UniverseUrl = "https://apis.roproxy.com/universes/v1/places/"..game.PlaceId.."/universe" -- Or whatever proxy you use

local success, result = pcall(function() -- A Pcall is necessary for proper error handling
		return HttpService:RequestAsync({
			Url = UniverseUrl,
			Method = "GET"
		})
	end)

	if success then
		print(HttpService:JSONDecode(result.Body).universeId)
	else
		warn(result)
	end

The universeId should print out. The only reason this script wouldn’t work is if the proxy is not working.

1 Like

Thanks, this works! However, I am having trouble getting the visits.

function GetVisits(universeID) 
	local DataUrl = "http://games.roproxy.com/v1/games?universeIds="..universeID

	local success, result = pcall(function()
		return web:RequestAsync({
			Url = DataUrl,
			Method = "GET"
		})
	end)

	if success then
		print(web:JSONDecode(result.Body).data[1].visits) -- error: attempt to index nil with number
		local Body = web:JSONDecode(result.Body)
		local UniverseVisits = Body.data[1].visits;
		print("VISITS: "..UniverseVisits)
		
		return  UniverseVisits
	else
		warn(result)
		return nil
	end
end
1 Like

I figured out the issue. It’s the proxy.

For some reason roproxy is failing to respond. I tried it with my own proxy and it worked.

You’ll need to use your own proxy or find a different one that works.

I see, thank you for your help! Is there any place you would suggest I start looking on how to setup my own proxy?

1 Like

I use rprxy, which is an open-source proxy that you can host yourself.

Previously, you were able to use rprxy like you would for roproxy but it got shutdown. You can still self-host your own though, and it works beautifully.

Do you have experience in Node.js?

I just started learning about http and proxy today so unfortunately I have no experience with Node.js or really anything http related :confused: