Reputation: 13
I want to print result from API... But it is not working... I don't know what is wrong I tried to do it but got this and it is not working:
<?php
$api = 'https://api.battlemetrics.com/servers/'; // the main API for servers.
$server = '5090469'; // the number of the server you will get the info from most of thime something like 5484856.
$api_full = $api . $server; // bringing them together.
$json = file_get_contents("$api_full"); // Putting the content of the file in a variable.
$response = json_decode($json, true); // decode the JSON feed
if ($response['data']['status'] == "online") {
echo "ONLINE";
} else {
echo "OFFLINE";
};
?>
Extra if you want to see the json response this is the link: https://api.battlemetrics.com/servers/5090469
Thanks in advance for your tips and help.
Upvotes: 0
Views: 188
Reputation: 178
Looks like you are just missing a key in your if statement.
It should be:
if($response['data']['attributes']['status'] == "online")
Upvotes: 1