Pulling Roblox data to an external website without being rate limited

Hello, i’ve been working on a portfolio website that includes some statistics of my games on Roblox.
The problem i came across is the following;

Due being rate limited sometimes the Data doesn’t get pulled correctly. Is there any way to bypass this rate limit?

    const apiKeyParam = apiKey ? `&apiKey=${apiKey}` : '';
    const url = `https://apis.roproxy.com/universes/v1/places/${gameId}/universe${apiKeyParam}`;

    const maxRetries = 3;
    let retries = 0;

    while (retries < maxRetries) {
        try {
            const response = await fetch(url);
            if (!response.ok) {
                if (response.status === 429) {
                    // Rate limit exceeded, apply exponential backoff
                    const delay = Math.pow(2, retries) * 1000;
                    await new Promise(resolve => setTimeout(resolve, delay));
                    retries++;
                    continue;
                } else {
                    throw new Error(`Failed to fetch data. Status code: ${response.status}`);
                }
            }

            const jsonData = await response.json();
            const universeId = jsonData.universeId;
            return universeId;
        } catch (error) {
            retries++;
        }
    }

    throw new Error("Max retries reached. Unable to fetch data.");
}
async function ImportData(title, active, favourites, visits, universeId) {
    try {
        const response = await fetch(`https://games.roproxy.com/v1/games?universeIds=${universeId}`);
        const data = await response.json();

        if (data.data && data.data[0]) {
            title.innerHTML = data.data[0].name;
            active.innerHTML = NumberConverter(data.data[0].playing, "norm");
            favourites.innerHTML = NumberConverter(data.data[0].favoritedCount, "norm");
            visits.innerHTML = NumberConverter(data.data[0].visits, "norm");
            totalVis += data.data[0].visits;
            totalFav += data.data[0].favoritedCount;
            totalPlr += data.data[0].playing;
            localStorage.setItem("totalVisits", totalVis);
            localStorage.setItem("totalFavourites", totalFav);
            localStorage.setItem("totalPlayers", totalPlr);
        }
    } catch (error) {
        console.error('Fetch error in ImportData:', error);
    }
}

My website: (refresh a couple times and see that the data doesn’t show up anymore)

1 Like

Your website isn’t working at all, this is the page that appears when I visit the URL you shared.

It would be useful if you share the code that is fetching the data.

Hey, thanks for your reply. I’ve inserted the code in the main post

The problem is that you are calling that function inside a while loop which results in a lot of API queries in a short time.

You are setting a timeout after you’ve already been rate limited while you should do that before to avoid these issues.