Quantcast
Channel: THWACK: Message List
Viewing all articles
Browse latest Browse all 20607

Re: Orion API via PHP

$
0
0

It took me awhile to get something working, but here is what I was able to use:

 

<?php

$data = array(

  'query' => "SELECT TOP 1 DisplayName, DetailsUrl FROM Orion.Nodes"

  );

$url = "https://oriondev:17778/SolarWinds/InformationService/v3/Json/Query";

$jdata = json_encode($data);

echo $result = CallAPI($url, $jdata);

 

 

function CallAPI($url, $data = false) {

   $ch = curl_init();

 

    // Authentication:

    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

    curl_setopt($ch, CURLOPT_USERPWD, "username:password");

    curl_setopt($ch, CURLOPT_URL, $url);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

  curl_setopt($ch, CURLOPT_SSLVERSION, 3);

  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

  curl_setopt($ch, CURLOPT_VERBOSE, true);

  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

  curl_setopt($ch, CURLOPT_HTTPHEADER, array(

                                        'Content-type: application/json',

                                        'Content-length: ' . strlen($data)

                                      ));

 

  $result = curl_exec($ch);

  $response = curl_getinfo($ch, CURLINFO_HTTP_CODE);

  $error = curl_error($ch);

  $info = curl_getinfo($ch);

 

  curl_close($ch);

 

    if ($result == false) {

  echo "Response: " . $response . "<br>";

  echo "Error: " . $error . "<br>";

  echo "Info: " . print_r($info);

  die();

  }

 

  return $result;

}

?>

 


Viewing all articles
Browse latest Browse all 20607

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>