-2

I have to make a curl request in php with these parameters, can you help me with an example, since I can't find anything similar

the link curl

curl -X GET "https://example.com/nms/api/v2.1/devices?withInterfaces=true&authorized=false&type=uisps&role=switch" -H "accept: application/json" -H "x-auth-token: wsedr4455-3345-es45-2345-4edeesssd"
ADyson
  • 57,178
  • 14
  • 51
  • 63
K10YW
  • 11
  • 4
  • Just use a converter such as https://incarnate.github.io/curl-to-php/ – ADyson Jul 22 '22 at 16:00
  • 1
    I rolled back your update, since that makes it a totally different question and invalidates the answer and comment already given. Make a new post if you have an issue specifically with processing the data. But first you should follow the link Markus gave below anyway, since it teaches you how to understand your data and then access different parts of it. Once you learn the principles it should be easy to get what you need – ADyson Jul 23 '22 at 11:48

1 Answers1

0

You should transform it into PHP curl syntax. It should work like this:

$ch = curl_init('https://example.com/nms/api/v2.1/devices?withInterfaces=true&authorized=false&type=uisps&role=switch');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'accept: application/json',
    'x-auth-token: wsedr4455-3345-es45-2345-4edeesssd'
));
$result = curl_exec($ch);
curl_close($ch);

The JSON incoming is in $result.

Markus Zeller
  • 8,516
  • 2
  • 29
  • 35
  • The example is perfect, how could I visualize the data? – K10YW Jul 22 '22 at 16:08
  • 1
    Do you mean the result? You may echo it and see the JSON or transform it to a PHP array for further use. `print_r(json_decode($result));` – Markus Zeller Jul 22 '22 at 16:55
  • Indeed, with json_decode they are shown in an array, but I do not have much experience with this, I have tried to move through the data like this print_r(json_decode($result[0][1])); but it doesn't work well, and I need to dump the info to a database – K10YW Jul 23 '22 at 11:04
  • Look here: https://stackoverflow.com/questions/29308898/how-to-extract-and-access-data-from-json-with-php – Markus Zeller Jul 23 '22 at 11:11