How to use APIs?

Let me try to get my own example running and I’ll post a reply to this thread when I get it working.

Alright, thanks! I will wait for you before trying to make any changes, as I might screw it up.

Not sure if this applies here, but can’t you just use the endpoint (URL) from a script? E.G. Avatar image endpoints? Also, have you tried turning studio api access on in the game’s settings?

Whoops! Completely wrong way to read it! My bad.

I’m not sure, I’m completely new to APIs.

After looking at the error on the google script side of things, it appears you need to be authenticated in order to use this endpoint. You’d have to write code that provides a cookie on a bot account which involves setting Cookie header and updating the cookie every once in a while.

This means that it is technically still possible, but you’d have to look more into the Google api that is in the google script project.

This is a very bad idea, I highly recommend investing into a service, or using free hosting services for a proxy, instead of going above and beyond to get something simple to work.

You need to use HTTP Requests. (YOU CAN NOT MAKE HTTP REQUESTS TO *.roblox.com IN ROBLOX’S LUA!) HttpService | Documentation - Roblox Creator Hub

But, here’s how you’d go about that, with any other API:

local httpService = game:GetService("HttpService")
local url = "https://https://games.roblox.com/v1/games"
local data = httpService:GetAsync(url .. "/920587237/favorites/count") -- Adopt Me
data = httpService:JSONDecode(data)
print(data.favoritesCount) -- 5,833,570

First problem is that I’m 99% sure Roblox doesn’t allow http requests to their own servers so they don’t dos themselves. Secondly, the problem with what was happening before is that when you send a request through your browser it automatically sends the Cookie header which has all the cookies for the website you’re on. It includes an authorization token that Roblox can verify your user with instead of asking for your username and password for every request you go to. Getting the amount of favorites requires this cookie for some reason.

At one point, this cookie method wont work. I’d just refrain using these API’s, and attempting to find new ones. Cookies don’t stay the same and valid all the time, unless you are constantly changing the ROBLOSECURITY whilst it changes then you will not be able to have a constantly working system. This is because I am pretty sure that Roblox’s cookies change in events of sign out all users, or even after a certain time.

Right, I completely forgot about that. I’ll make an edit.

Will this just be impossible to make then?

Do you know of any other APIs that allow you getting favorites? I haven’t seen any yet but at the same time I haven’t really looked too much either. Roblox loves their gosh darn cookies if you get.
Yeah, cookies must expire after a certain amount of time or else they wouldn’t be so secure. It’s a pain and I really wish Roblox added in bots that are similar to discord for stuff like this.

2 Likes

I can agree that Roblox should add some features that don’t require a cookie. I’d like to see a system similar to google’s one day, where some would require an API key or Oath 2.0 to even send requests to the API, so then Roblox can easily suspend suspicious API’s, and I actually do not know of any other API’s for that stuff, but I will begin some research to find some.

Well do you only need to get one games favorite count?
If you only need ones then you can get the unverseId by just going to this link and copying the universeId from what it returns:
https://games.roblox.com/v1/games/multiget-place-details?placeIds=0
Then you can change the URL in the script to this:

local HttpProxy = require(game.Workspace.HttpProxyService:Clone());
local universeId = 0;

local placeDetails = game.HttpService:JSONEncode(HttpProxy:GetAsync("https://games.roblox.com/v1/games/"..universeId.."/favorites/count"));

This in theory (I haven’t tested) should return the favorite count for one place.

If you have any more questions it’d probably be best to take it to DMs as it is getting slightly off-topic.

I would advise reading this reply to a thread;

If you can add some simple modifications, you can make this work for favorites.

So wait, can I do this for multiple games?

I wanted BSS, and then for example (not real), Vesteria and Bubble Gum Simulator.

Would I just use multiple instances of this same script?

Yes, you could probably do that if you changed the universeIds for all of them. There may be some HttpService restrictions but I doubt any would be so restricting.

Sweet! I’ll test now. Thanks so much!

Nope, it didn’t work. Is there a way to do this without APIs?

Looking back, since you can’t make requests to Roblox’s APIs from in a game, you could make a wrapper in NodeJS and Express to make a request to the Roblox API from a Roblox game.

var express = require("express"); // Make sure you have express installed.
var fetch = require("node-fetch");
var app = express();

app.get("/favorites/:id", function(req, res) {
    const getData = async url => {
        var response = nil, json = nil
        try {
          response = await fetch(url);
          json = await response.json();
        } catch (error) {
            console.log(error);
        }
        if(response !== nil){
            return json
        }
    };
    var json = getData("https://games.roblox.com/v1/games/" + req.params.id + "/favorites/count");
    res.json(json); // Send the JSON as the response.
});

app.listen(8000)

Then, in a Roblox script:

local httpService = game:GetService("HttpService")

local data = httpService:GetAsync("http://[URL/IP]:8000/favorites/12345678")
data = httpService:JSONDecode(data)
local favCount = data.favoritesCount  -- The amount of favorites
print(favCount) -- 12
3 Likes