Use Java/C#/PHP code to fetch the XML data using basic authentication

  • Release version: Xanadu
  • Updated August 1, 2024
  • 1 minute to read
  • If a local data store is not an option, another way to get the data is to call the CSV/XML processor directly and then parse the results.

    Use the resulting data in a similar manner as you would a direct SOAP call. An example of this in PHP:

    <?php
    //This example is in PHP 
     
    	$user = "itil";
    	$pass = "itil";
            $userPass = $user.':'.$pass;
     
     
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, 'https://<instance name>.service-now.com/incident_list.do?CSV');
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
            curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
            curl_setopt($ch, CURLOPT_USERPWD, $userPass);
     
            $data = curl_exec($ch);
            $info = curl_getinfo($ch);
     
            if ($output === false) {
              $output = "No cURL data returned for $addr [". $info['http_code']. "]";
              if (curl_error($ch))
                  $output .= "\n". curl_error($ch);
              print $output;
            }
            else{
              echo $data;
            }
            curl_close($ch);
    ?>