Request in graphane API with PHP

Asked

Viewed 212 times

0

I’m trying to create a PHP file that does direct authentication on GRAPHANA and displays the DASHBOARD on my page, but is not displaying anything with the structure below:

<?php

//Server url
$url = "http://meu-ip/api/dashboards/home";
$apiKey = 'aqui-vem-a-chave'; // should match with Server key
$headers = array(
     'Authorization: Bearer '.$apiKey
);
// Send request to Server
$ch = curl_init($url);
// To save response in a variable from server, set headers;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// Get response
$response = curl_exec($ch);
// Decode
$result = json_decode($response);

?>

I created a KEY API on the graph to make this authentication.

  • see if the problem is not adding a curl_close($ch); before the $result

  • Parse error: syntax error, Unexpected '$result' (T_VARIABLE) in C: xampp htdocs front-end teste.php on line 18

  • Returned the above error

  • if I place a print_r(), without the curl_close($ch), in $result, the output is: stdClass Object ( [redirectUri] => /d/hc63X9VZz/menu-Automation )

1 answer

1


Test this way by putting your api key in place of $Authorization KEY_API

  //Server url
    $url = "http://meu-ip/api/dashboards/home";
    $authorization = "Authorization: Bearer KEY_API";

    // Send request to Server
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , $authorization ));
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    $result = curl_exec($ch);
    curl_close($ch);

    $jsonDecode = json_decode($result);
  • I made the reactions, got the following output: Notice: Undefined variable: post in C: xampp htdocs front-end teste.php on line 12

  • modified now, accidentally put the $post

  • I did not return any error, I printed the $result variable, and returned this: {"message":"Not found"}

  • you tbm can trade curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); for curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); if the request by GET msm

Browser other questions tagged

You are not signed in. Login or sign up in order to post.