Games V1 API doesn't work

So I tried to get the game data from the games api https://games.roblox.com/v1/games?universeIds=4922186765.

But it doesn’t work is it in some way rejected

I make a website games | unviere to show my games with stats but it doesn’t fetch data also it only should fetch it once you load the site and update it if you reload the site idk how to


document.addEventListener('DOMContentLoaded', () => {
  const gameTemplate = document.getElementById('test').content;
  const gameContainer = document.querySelector('.test-content');

  // Array of game universe IDs
  const universeIds = ['4922186765', 'anotherUniverseId', 'anotherUniverseId2'];

  // Function to fetch and display game data for a single universe ID
  const fetchAndDisplayGame = (universeId) => {
    const apiUrl = `https://games.roblox.com/v1/games?universeIds=${universeId}`;
    const proxyUrl = `https://cors-anywhere.herokuapp.com/${apiUrl}`;
    console.log('Fetching data from API URL via proxy:', proxyUrl);

    fetch(proxyUrl)
      .then(response => {
        if (!response.ok) {
          throw new Error(`Network response was not ok: ${response.statusText}`);
        }
        return response.json();
      })
      .then(data => {
        console.log('API response data:', data);

        if (!data.data || !Array.isArray(data.data)) {
          throw new Error('Invalid data format received from API');
        }

        data.data.forEach(game => {
          const gameClone = document.importNode(gameTemplate, true);

          gameClone.querySelector('.game-title').textContent = game.name || 'No title available';
          gameClone.querySelector('.icon').src = `https://www.roblox.com/Thumbs/Asset.ashx?width=110&height=110&assetId=${game.rootPlaceId}`;
          gameClone.querySelector('.game-desc').textContent = game.description || 'No description available';
          gameClone.querySelector('.active').textContent = `active: ${game.playing || 'N/A'}`;
          gameClone.querySelector('.owner').textContent = `owner: ${game.creator && game.creator.name ? game.creator.name : 'N/A'}`;
          gameClone.querySelector('.likes').textContent = `likes: ${game.likes || 'N/A'}`;

          gameContainer.appendChild(gameClone);
        });
      })
      .catch(error => {
        console.error('Error fetching the game data:', error);
        const errorMessage = document.createElement('p');
        errorMessage.textContent = `Error fetching the game data: ${error.message}`;
        gameContainer.appendChild(errorMessage);
      });
  };

  // Fetch and display games for each universe ID sequentially
  universeIds.forEach(universeId => {
    fetchAndDisplayGame(universeId);
  });
}); 

Anny help is appreciated

2 Likes

whether you have enabled API Service and HTTP Requests?

It’s not in studio it says something like error to fetch data

It is trough a website not in Roblox studio


document.addEventListener('DOMContentLoaded', () => {
  const gameTemplate = document.getElementById('test').content;
  const gameContainer = document.querySelector('.test-content');

  // Array of game universe IDs
  const universeIds = ['4922186765', 'anotherUniverseId', 'anotherUniverseId2'];

  // Function to fetch and display game data for a single universe ID
  const fetchAndDisplayGame = (universeId) => {
    const apiUrl = `https://games.roblox.com/v1/games?universeIds=${universeId}`;
    const proxyUrl = `https://cors-anywhere.herokuapp.com/${apiUrl}`;
    console.log('Fetching data from API URL via proxy:', proxyUrl);

    fetch(proxyUrl)
      .then(response => {
        if (!response.ok) {
          throw new Error(`Network response was not ok: ${response.statusText}`);
        }
        return response.json();
      })
      .then(data => {
        console.log('API response data:', data);

        if (!data.data || !Array.isArray(data.data)) {
          throw new Error('Invalid data format received from API');
        }

        data.data.forEach(game => {
          const gameClone = document.importNode(gameTemplate, true);

          gameClone.querySelector('.game-title').textContent = game.name || 'No title available';
          gameClone.querySelector('.icon').src = `https://www.roblox.com/Thumbs/Asset.ashx?width=110&height=110&assetId=${game.rootPlaceId}`;
          gameClone.querySelector('.game-desc').textContent = game.description || 'No description available';
          gameClone.querySelector('.active').textContent = `active: ${game.playing || 'N/A'}`;
          gameClone.querySelector('.owner').textContent = `owner: ${game.creator && game.creator.name ? game.creator.name : 'N/A'}`;
          gameClone.querySelector('.likes').textContent = `likes: ${game.likes || 'N/A'}`;

          gameContainer.appendChild(gameClone);
        });
      })
      .catch(error => {
        console.error('Error fetching the game data:', error);
        const errorMessage = document.createElement('p');
        errorMessage.textContent = `Error fetching the game data: ${error.message}`;
        gameContainer.appendChild(errorMessage);
      });
  };

  // Fetch and display games for each universe ID sequentially
  universeIds.forEach(universeId => {
    fetchAndDisplayGame(universeId);
  });
});

This the new script but it still gives errors

at li._formatMsg (http://localhost:7700/games.html:5:153819)
at new li (http://localhost:7700/games.html:5:151287)
at Si.insertSync (http://localhost:7700/games.html:5:165613)
at http://localhost:7700/games.html:5:167384```