Roblox API Error 401 Unauthorized

Hello there,

I’m using PHP to access the Roblox Games API so that I can get games description. In my code I use this URL:

$GameDataJSON = file_get_contents("https://games.roblox.com/v1/games/multiget-place-details?placeIds=7705244718");
$GameData = json_decode($GameDataJSON,true);
echo $GameData;

However this code gives out the following error:

Warning : file_get_contents(https://games.roblox.com/v1/games/multiget-place-details?placeIds=7705244718): Failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized in /home2/icrannco/public_html/analytics/home.php on line 8

However if I past this link into my browser I get my infromation. Try it for yourself if you want:
https://games.roblox.com/v1/games/multiget-place-details?placeIds=7705244718

Thanks in advance for any help.

1 Like

You need authorization (cookie) to access that endpoint. It works when you paste the link into browser because your browser uses your logged in account’s cookie

You can make a fresh roblox account and get its cookie and pass it with your GET request

1 Like

How do I pass through a cookie?

I have no idea how to code or use PHP but you I found a way to pass a cookie using this code I found:


<?php
// Create a stream
$opts = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"Accept-language: en\r\n" .
              "Cookie: foo=bar\r\n"
  )
);

$context = stream_context_create($opts);

// Open the file using the HTTP headers set above
$file = file_get_contents('http://www.example.com/', false, $context);
?>

The cookie would be called “.ROBLOSECURITY”, and make sure you keep this private, you can find it by looking in the dev storage tab or using a cookie viewing extension.

1 Like

Also it’s better to create an alt account for this, exposing your main account cookie definitely doesn’t sound safe.

1 Like

Sorry for marking this solution late. I just have some extra details:

The "Accept-language: en\r\n" is not neaded and for the cookie you will set it as .ROBLOSECURITY={You Cookie}

This is the final code:

$opts = array(
        "http"=>array(
            "method"=>"GET",
            "header"=>"Cookie: .ROBLOSECURITY={YOUR COOKIE}\r\n"
        )
    );
    
    $context = stream_context_create($opts);

        
    $GameDataJSON = file_get_contents("https://games.roblox.com/v1/games/multiget-place-details?placeIds=7705244718", false, $context);
    $GameData = json_decode($GameDataJSON,true);
    
    echo $GameDataJSON;