How to get Grafana dashboard via API in my Symfony Proyect?

I´m a junior developer and I´m trying to get a dashboard from Grafana in my Symfony proyect.

In Grafana´s API, i have seen i can get a dashboard by uid. Exactly this is the information offered by the grafana´s api:

GET /api/dashboards/uid/:uid

Will return the dashboard given the dashboard unique identifier (uid).

Example Request:

GET /api/dashboards/uid/cIBgcSjkk HTTP/1.1     
Accept: application/json
Content-Type: application/json 
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

In Symfony documentation, i have seen how i should do a GET request:

use SymfonyComponentHttpClientHttpClient;

$client = HttpClient::create();
$response = $client->request('GET', 'https://api.github.com/repos/symfony/symfony-docs');

$statusCode = $response->getStatusCode();
// $statusCode = 200
$contentType = $response->getHeaders()['content-type'][0];
// $contentType = 'application/json'
$content = $response->getContent();
// $content = '{"id":521583, "name":"symfony-docs", ...}'
$content = $response->toArray();
// $content = ['id' => 521583, 'name' => 'symfony-docs', ...]

But I don’t know how I should correctly write all the request headers to get my dashboard. Can someone help me?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *