I try to get data from New Relic API using CURL php
curl -X GET 'https://api.newrelic.com/v2/servers.json' \
-H 'X-Api-Key:my-api-key' -i \
i write
$ch = curl_init('https://api.newrelic.com/v2/servers.json');
curl_setopt($ch, CURLOPT_HTTPHEADER, ['X-Api-Key' => 'my-api-key']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
if (curl_errno($ch)) {
print "Error: " . curl_error($ch);
}
curl_close($ch);
var_dump($data);
but it not work and write 403 New Relic API access has not been enabled
what i do wrong?
Hello your all do right but header your send wrong. it must be next
$ch = curl_init('https://api.newrelic.com/v2/servers.json');
curl_setopt($ch, CURLOPT_HTTPHEADER, ['X-Api-Key:my-api-key']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
if (curl_errno($ch)) {
print "Error: " . curl_error($ch);
}
curl_close($ch);
var_dump($data);
if your my-api-key
is real API key :)