PHP code example of ec-europa / itopapi

1. Go to this page and download the library: Download ec-europa/itopapi library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ec-europa / itopapi example snippets




$iTopAPI = new \iTopApi\ITopClient( 'http://localhost/itop', 'itopUser', 'iTopPassword' );

//disable SSL checks ?
//$iTopAPI->setCertificateCheck(false);

$query = sprintf("SELECT Servers WHERE environment = '%s'",'development');

$serversRequest = $iTopAPI->coreGet("Servers",$query);

$servers = $serverRequest['objects'];



$iTopAPI = new \iTopApi\ITopClient( 'http://localhost/itop', 'itopUser', 'iTopPassword' );

//disable SSL checks ?
//$iTopAPI->setCertificateCheck(false);

$request = $iTopAPI->coreCreate("Servers",array(
  'hostname' => 'localhost',
  'memory' => 2048,
  'cpu' => 4,
  'location' => 'dc1'
));




$iTopAPI = new \iTopApi\ITopClient( 'http://localhost/itop', 'itopUser', 'iTopPassword' );

//disable SSL checks ?
//$iTopAPI->setCertificateCheck(false);

$request = $iTopAPI->coreUpdate("Servers",array(
  'hostname' => 'localhost'
),array(
  'memory' => 1024
));




$iTopAPI = new \iTopApi\ITopClient( 'http://localhost/itop', 'itopUser', 'iTopPassword' );

//disable SSL checks ?
//$iTopAPI->setCertificateCheck(false);


/**
 * Query and iterate 
 */

$servers = $iTopAPI->getObjects("Server",
  array(
    'name' => 'server001'
  )
);

foreach($servers as $server) {
  echo $server->name.' is '.$server->status_friendlyname;
  $server->name = 'server001-eu';
  $server->save();
}


/**
 * Deletes a new server : 
 */
if($server->status_friendlyname == 'decommissioning')
  $server->delete();
  
  
/**
 * Creates a new server : 
 */
$server = $iTopClient->getNewObject('Server');

$server->name = 'server002';
$server->status_friendlyname = 'deployed';
$server->save();