2017 © Pedro Peláez
 

library idoitapi

Easy-to-use, but feature-rich client library for i-doit's JSON-RPC API

image

bheisig/idoitapi

Easy-to-use, but feature-rich client library for i-doit's JSON-RPC API

  • Thursday, June 28, 2018
  • by bheisig
  • Repository
  • 3 Watchers
  • 2 Stars
  • 523 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 7 Versions
  • 25 % Grown

The README.md

i-doit API client library

Easy-to-use, but feature-rich client library for i-doit's JSON-RPC API, (*1)

Latest stable version Minimum PHP version Build status, (*2)

Please note: This project is not an official product by synetics GmbH. synetics GmbH doesn't provide any commercial support., (*3)

About

i-doit is a software application for IT documentation and a CMDB (Configuration Management Database). This application is very useful to collect all your knowledge about the IT infrastructure you are dealing with. i-doit is a Web application and has an exhausting API which is very useful to automate your infrastructure., (*4)

This API client library provides a simple, but powerful abstraction layer to send requests to i-doit's API. It is written in pure PHP., (*5)

Features

Why should you use this API client library? There are some good reasons:, (*6)

  • Easy to use
  • There is a PHP function for each API method
  • Supports batch requests (much faster)
  • Sends user-defined requests
  • Uploads files and images
  • Supports login and logout methods to save sessions
  • Follows redirects (HTTP 301/302) automatically
  • Uses optional HTTP or SOCKS5 proxy
  • Verifies TLS certificate chains
  • Throws exception on error
  • Many examples
  • Well-documented
  • Easy to install via Composer
  • Well-tested with tons of integration tests

What's new? Take a look at the changelog., (*7)

Requirements

Meet these simple requirements before using the client:, (*8)

  • A running instance of i-doit pro/open, version 1.18.1 or higher (older versions may work but are not supported)
  • i-doit API add-on, version 1.12.3 or higher (older versions may work but are not supported)
  • PHP, version 8.0 or higher (8.1 is recommended, 7.4 should work but is deprecated)
  • PHP modules curl, date, json, openssl and zlib

As a rule of thumb, always use the latest stable releases to benefit from new features, improvements and bug fixes., (*9)

Installation

It is recommended to install this client via Composer. Change to your project's root directory and fetch the latest stable version:, (*10)

~~~ {.bash} composer require idoit/apiclient, (*11)


Instead of sticking to a specific/minimum version you may switch to the current development branch by using `@DEV`: ~~~ {.bash} composer require "idoit/apiclient=@DEV"

Updates

Composer has the great advantage (besides many others) that you can simply update the API client library by running:, (*12)

~~~ {.bash} composer update, (*13)


## Usage If you use Composer you should use its own autoloader, too: ~~~ {.php} require_once 'vendor/autoload.php';

This is it. All other files will be auto-loaded on-the-fly if needed., (*14)

Configuration

The API client library class requires a configuration:, (*15)

~~~ {.php} use Idoit\APIClient\API;, (*16)

$api = new API([ API::URL => 'https://demo.i-doit.com/src/jsonrpc.php', API::PORT => 443, API::KEY => 'c1ia5q', API::USERNAME => 'admin', API::PASSWORD => 'admin', API::LANGUAGE => 'en', API::PROXY => [ API::PROXY_ACTIVE => false, API::PROXY_TYPE => 'HTTP', // 'HTTP' or 'SOCKS5' API::PROXY_HOST => 'proxy.example.net', API::PROXY_PORT => 8080, API::PROXY_USERNAME => '', API::PROXY_PASSWORD => '' ], API::BYPASS_SECURE_CONNECTION => false ]);, (*17)


- `API::URL`: URL to i-doit's API, probably the base URL appended by `src/jsonrpc.php` - `API::PORT`: optional port on which the Web server listens; if not set port 80 will be used for HTTP and 443 for HTTPS - `API::KEY`: API key - `API::USERNAME` and `API::PASSWORD`: optional credentials if needed, otherwise `System API` user will be used - `API::LANGUAGE`: requests to and responses from i-doit will be translated to this language (`de` and `en` supported); this is optional; defaults to user's prefered language - `API::PROXY`: use a proxy between client and server - `API::PROXY_ACTIVE`: if `true` proxy settings will be used - `API::PROXY_TYPE`: use a HTTP (`API::PROXY_TYPE_HTTP`) or a SOCKS5 (`API::PROXY_TYPE_SOCKS5`) proxy - `API::PROXY_HOST`: FQDN or IP address to proxy - `API::PROXY_PORT`: port on which the proxy server listens - `API::PROXY_USERNAME` and `API::PROXY_PASSWORD`: optional credentials used to authenticate against the proxy - `API::BYPASS_SECURE_CONNECTION`: Set to `true` to disable security-related cURL options; defaults to `false`; do not set this in production! ## Examples A basic "Hello, World!" example is to fetch some basic information about your i-doit instance: ~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\Idoit; require_once 'vendor/autoload.php'; $api = new API([ API::URL => 'https://demo.i-doit.com/src/jsonrpc.php', API::KEY => 'c1ia5q', API::USERNAME => 'admin', API::PASSWORD => 'admin' ]); $request = new Idoit($api); $info = $request->readVersion(); var_dump($info);

It is simple like that. For more examples take a look at the next sub sections., (*18)

Login and logout

One sweet thing about i-doit's API you can (and should) use one user session for your stuff. This saves resources on the server side and allows you to perform a lot more calls in a short time., (*19)

The session handling is done by the API client library. You just need to login. And if you are nice you want to logout after your work is done., (*20)

~~~ {.php} use Idoit\APIClient\API;, (*21)

$api = new API([/* … */]);, (*22)

$api->login(); // Do your stuff… $api->logout();, (*23)


If you are unsure in which condition your session is try `isLoggedIn()`: ~~~ {.php} $api->isLoggedIn(); // Returns true or false

Pre-defined methods

For almost every case there is a remote procedure you may call to read from or manipulate i-doit's database through its API. Each remote procedure is assigned to a namespace to keep the API clean and smoothly. Furtunately, you do not need to call these remote procedures on your own. The API client library provides for each namespace a class and for each remote procedure a method. Here is a quick overview:, (*24)

Namespace Remote Procedure Call (RPC) Class in API Client Library Method
idoit idoit.addons Idoit getAddOns()
idoit.constants readConstants()
idoit.license getLicense()
idoit.search search()
idoit.version readVersion()
idoit.login API login()
idoit.logout logout()
cmdb.object cmdb.object.create CMDBObject create()
cmdb.object.read read()
cmdb.object.update update()
cmdb.object.archive archive()
cmdb.object.delete delete()
cmdb.object.purge purge()
cmdb.objects cmdb.objects.read CMDBObjects read()
cmdb.category cmdb.category.create CMDBCategory create()
cmdb.category.read read(), readOneByID(), readFirst()
cmdb.category.update update()
cmdb.category.save save()
cmdb.category.archive archive()
cmdb.category.delete delete()
cmdb.category.purge purge()
cmdb.category_info cmdb.category_info.read CMDBCategoryInfo read()
cmdb.condition cmdb.condition.read CMDBCondition read()
cmdb.dialog cmdb.dialog.create CMDBDialog create()
cmdb.dialog.read read()
cmdb.dialog.delete delete()
cmdb.impact cmdb.impact.read CMDBImpact readByID(), readByConst()
cmdb.location_tree cmdb.location_tree.read CMDBLocationTree read(), readRecursively()
cmdb.logbook cmdb.logbook.create CMDBLogbook create()
cmdb.logbook.read read()
cmdb.objects_by_relation cmdb.objects_by_relation.read CMDBObjectsByRelation readByID(), readByConst()
cmdb.object_type_categories cmdb.object_type_categories.read CMDBObjectTypeCategories readByID(), readByConst()
cmdb.object_type_groups cmdb.object_type_groups.read CMDBObjectTypeGroups read()
cmdb.object_types cmdb.object_types.read CMDBObjectTypes read(), readOne(), readByTitle()
cmdb.reports cmdb.reports.read CMDBReports read(), listReports()
cmdb.workstation_components cmdb.workstation_components.read CMDBWorkstationComponents read(), readByEMail(), readByEMails()
checkmk.statictag checkmk.statictag.create CheckMKStaticTag create()
checkmk.statictag.read read(), readByID(), readByIDs(), readByTag()
checkmk.statictag.update update()
checkmk.statictag.delete delete()
checkmk.tags checkmk.tags.read CheckMKTags read()
monitoring.livestatus monitoring.livestatus.create MonitoringLivestatus createTCPConnection, createUNIXSocketConnection
monitoring.livestatus.read read(), readByID(), readByIDs(), readByTitle()
monitoring.livestatus.update update()
monitoring.livestatus.delete deleteByID(), deleteByTitle()

Additionally, this API client library is shipped with methods as workarounds for remote procedure calls you probably miss. The RPC cmdb.objects.create does not exist but you may use CMDBObjects::create(). It simulates the missing RPC and gives you an easier and faster way to manipulate your CMDB., (*25)

If it makes sense there are methods to perform batch requests for most RPCs. For example, CMDBCategory::batchRead() fetches multiple category entries at once., (*26)

Examples

Search in i-doit's database

~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\Idoit;, (*27)

$api = new API([/* … */]);, (*28)

$idoit = new Idoit($api); $result = $idoit->search('Server XY');, (*29)

var_dump($result);, (*30)


Perform more than one search at once: ~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\Idoit; $api = new API([/* … */]); $idoit = new Idoit($api); $result = $idoit->batchSearch([ 'Server XY', 'Client A', 'John Doe' ]); var_dump($result);

Create a new object

~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\CMDBObject;, (*31)

$api = new API([/* … */]);, (*32)

$object = new CMDBObject($api); $objectID = $object->create( 'C__OBJTYPE__SERVER', 'Server XY' );, (*33)

var_dump($objectID);, (*34)


#### Read common information about an object ~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\CMDBObject; $api = new API([/* … */]); $object = new CMDBObject($api); $objectInfo = $object->read(42); var_dump($objectInfo);

Load all data of an object

This will fetch everything about an object: common data, assigned categories and category entries as well., (*35)

~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\CMDBObject;, (*36)

$api = new API([/* … */]);, (*37)

$object = new CMDBObject($api); $objectInfo = $object->load(42);, (*38)

var_dump($objectInfo);, (*39)


The method `load()` triggers round about 4 API calls. So be aware if it is heavily used. #### Update an existing object Currently, you are able to update an object's title: ~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\CMDBObject; $api = new API([/* … */]); $object = new CMDBObject($api); $object->update( 42, [ 'title' => 'A shiny new object title' ] );

Create or update an object ("upsert")

You you like to get an identifier of an object but you are unsure whether or not it exists, try an upsert. This is an "update" and an "insert" at the same time. This means, if the object exists you will get its identifier directly. If not the object will be created and then you will get its identifier. Objects must match against type and title. Additional attributes will be stored., (*40)

~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\CMDBObject;, (*41)

$api = new API([/* … */]);, (*42)

$object = new CMDBObject($api); $object->upsert( 'C__OBJTYPE__SERVER', 'My little server', [ 'purpose' => 'Private stuff' ] );, (*43)


#### Fetch an object identifier Fetch an object identifier by object title and (optional) type: ~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\CMDBObjects; $api = new API([/* … */]); $object = new CMDBObjects($api); $objectID = $object->getID('My little server'); $objectID = $object->getID('My little server', 'C__OBJTYPE__SERVER');

An exception error will be thrown if there is either no object or more than one., (*44)

Change documentation status of an object

i-doit has the concept of archiving your IT documentation. Each object has an status (normal, archived, marked as deleted). And last but not least, an object may be purged from the database., (*45)

~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\CMDBObject;, (*46)

$api = new API([/* … */]);, (*47)

$object = new CMDBObject($api); $objectID = 42; // Archive: $object->archive($objectID); // Mark as deleted: $object->delete($objectID); // Purge from database: $object->purge($objectID);, (*48)


#### Create multiple objects Create multiple objects at once: ~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\CMDBObjects; $api = new API([/* … */]); $cmdbObjects = new CMDBObjects($api); $objectIDs = $cmdbObjects->create( [ ['type' => 'C__OBJTYPE__SERVER', 'title' => 'Server No. One'], ['type' => 'C__OBJTYPE__SERVER', 'title' => 'Server No. Two'], ['type' => 'C__OBJTYPE__SERVER', 'title' => 'Server No. Three'] ] ); var_dump($objectIDs);

Read multiple objects

Reading multiple objects at once is provided by several methods. Let's see:, (*49)

~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\CMDBObjects;, (*50)

$api = new API([/* … */]);, (*51)

$cmdbObjects = new CMDBObjects($api);, (*52)

// Fetch every object: $objects = $cmdbObjects->read(); var_dump($objects);, (*53)

// Fetch max. 10 servers and sort them descending by title: $objects = $cmdbObjects->read(['type' => 'C__OBJTYPE__SERVER'], 10, 0, 'title', CMDBObjects::SORT_DESCENDING); var_dump($objects);, (*54)

// Get them by their identifiers: $objects = $cmdbObjects->readByIDs([1, 2, 3]); var_dump($objects);, (*55)

// Get all servers: $objects = $cmdbObjects->readByType('C__OBJTYPE__SERVER'); var_dump($objects);, (*56)

// Get archived clients: $objects = $cmdbObjects->readArchived('C__OBJTYPE__CLIENT'); var_dump($objects);, (*57)

// Get clients marked as deleted: $objects = $cmdbObjects->readDeleted('C__OBJTYPE__CLIENT'); var_dump($objects);, (*58)


#### Update multiple objects Update multiple objects at once: ~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\CMDBObjects; $api = new API([/* … */]); $cmdbObjects = new CMDBObjects($api); // Rename objects 1, 2, 3: $cmdbObjects->update([ ['id' => 1, 'title' => 'New name'], ['id' => 2, 'title' => 'Another name'], ['id' => 3, 'title' => 'Just a name'], ]);

Archive/delete/purge multiple objects

Archive objects, mark them as deleted or even purge them from database:, (*59)

~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\CMDBObjects;, (*60)

$api = new API([/* … */]);, (*61)

$cmdbObjects = new CMDBObjects($api);, (*62)

$cmdbObjects ->archive([1, 2, 3]) ->delete([1, 2, 3]) ->purge([1, 2, 3]);, (*63)


#### Read object by condition Allowed comparison are '=', '!=', 'like', 'not like', '>', '>=', '<', '<=', '<>'. ~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\CMDBCondition; $api = new API([/* … */]); $condition = new CMDBCondition($api); $result = $condition->read( [ [ 'property' => "C__CATG__ACCOUNTING-order_no", 'comparison' => "=", 'value' => "ORDER4711", ] ] );

You can use more than one condition and add an operator to them. Allowed operators are 'AND' and 'OR'., (*64)

~~~ {.php} $result = $condition->read( [ [ 'property' => "C__CATG__ACCOUNTING-order_no", 'comparison' => "=", 'value' => "ORDER4711", ], [ 'property' => "C__CATG__ACCOUNTING-order_no", 'comparison' => "=", 'value' => "ORDER0815", 'operator' => 'OR', ] ] );, (*65)


For more readable code you can use the condition helper class. ~~~ {.php} use Idoit\APIClient\Condition; $conditions = [ new Condition("C__CATG__ACCOUNTING", "order_no", "=", "ORDER4711"), new Condition("C__CATG__ACCOUNTING", "order_no", "=", "ORDER4711", Condition::OR), ]; $result = $condition->read($conditions);

Create category entries with attributes

~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\CMDBCategory;, (*66)

$api = new API([/* … */]);, (*67)

$category = new CMDBCategory($api); $entryID = $this->category->save( 42, 'C__CATG__IP', [ 'net' => 123, 'active' => 1, 'primary' => 0, 'net_type' => 1, 'ipv4_assignment' => 2, 'ipv4_address' => '10.20.10.100', 'description' => 'API TEST' ] );, (*68)

var_dump($entryID);, (*69)


Alternatively, use method `CMDBCategory::batchCreate()` for batch requests. #### Read categories and attributes Read one or more category entries for one specific object: ~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\CMDBCategory; $api = new API([/* … */]); $category = new CMDBCategory($api); $result = $category->read(42, 'C__CATG__IP'); var_dump($result);

Read one specific categoy entry for one specific object:, (*70)

~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\CMDBCategory;, (*71)

$api = new API([/* … */]);, (*72)

$category = new CMDBCategory($api); $result = $category->readOneByID(42, 'C__CATG__IP', 23);, (*73)

var_dump($result);, (*74)


Read just one category entry (easier than `read()` when using single-valued categories): ~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\CMDBCategory; $api = new API([/* … */]); $category = new CMDBCategory($api); $result = $category->readFirst(42, 'C__CATG__IP'); var_dump($result);

Read data for multiple objects and categories at once:, (*75)

~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\CMDBCategory;, (*76)

$api = new API([/* … */]);, (*77)

$category = new CMDBCategory($api); $result = $category->batchRead( [23, 42], ['C__CATG__IP', 'C__CATG__MODEL'] );, (*78)

var_dump($result);, (*79)


#### Update categories and attributes ~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\CMDBCategory; $api = new API([/* … */]); $category = new CMDBCategory($api); $category->save( 42, 'C__CATG__GLOBAL', [ 'cmdb_status' => 10 ] );

Alternatively, use method CMDBCategory::batchUpdate() for batch requests., (*80)

Change documentation status of a category and its attributes

~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\CMDBCategory;, (*81)

$api = new API([/* … */]);, (*82)

$category = new CMDBCategory($api); // Archive: $category->archive(42, 'C__CATG__CPU', 1); // Mark as deleted: $category->delete(42, 'C__CATG__CPU', 2); // Purge from database: $category->purge(42, 'C__CATG__CPU', 3);, (*83)


#### Create values in drop-down menus ~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\CMDBDialog; $api = new API([/* … */]); $dialog = new CMDBDialog($api); $entryID = $dialog->create('C__CATG__MODEL', 'title', 'My model'); var_dump($entryID); $entryIDs = $dialog->batchCreate([ 'C__CATG__MODEL' => [ 'manufacturer' => 'My manufacturer', 'title' => 'My model' ], 'C__CATG__GLOBAL' => [ 'category' => [ 'cat 1', 'cat 2', 'cat 3' ], 'purpose' => 'API TEST' ] ]); var_dump($entryIDs);

Fetch values from drop-down menus

Drop-down menus in i-doit are called "dialog" (read-only) or "dialog+" (editable)., (*84)

~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\CMDBDialog;, (*85)

$api = new API([/* … */]);, (*86)

$dialog = new CMDBDialog($api);, (*87)

$models = $dialog->read('C__CATG__MODEL', 'title'); var_dump($models);, (*88)

$modelsAndManufacturers = $dialog->batchRead([ 'C__CATG__MODEL' => [ 'manufacturer', 'title' ] ]); var_dump($modelsAndManufacturers);, (*89)


#### Build a location tree Read objects located directly under an object: ~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\CMDBLocationTree; $api = new API([/* … */]); $locationTree = new CMDBLocationTree($api); $result = $locationTree->read(1); var_dump($result);

Read recursively objects located under an object:, (*90)

~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\CMDBLocationTree;, (*91)

$api = new API([/* … */]);, (*92)

$locationTree = new CMDBLocationTree($api); $result = $locationTree->readRecursively(1);, (*93)

var_dump($result);, (*94)


#### Fetch relations between objects ~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\CMDBObjectsByRelation; $api = new API([/* … */]); $relation = new CMDBObjectsByRelation($api); $result = $relation->read( 10, 'C__RELATION_TYPE__PERSON_ASSIGNED_GROUPS' ); var_dump($result);

Fetch workplace components for a person

A Person may be assigned to a workplace with several components like a PC, a monitor and a telephone. These components can be fetched by the person. You either need the object ID or the email address. Even more than one workplaces are supported., (*95)

~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\CMDBWorkstationComponents;, (*96)

$api = new API([/* … */]); $components = new CMDBWorkstationComponents($api);, (*97)

$result = $components->read(111); // Person object with ID 111 var_dump($result);, (*98)

$result = $components->batchRead([111, 222]); // Person objects with IDs 111 and 222 var_dump($result);, (*99)

$result = $components->readByEMail('alice@example.org'); // Person object with email address var_dump($result);, (*100)

$result = $components->readByEMails(['alice@example.org', 'bob@example.org']); // Person objects with email addresses var_dump($result);, (*101)


#### Reports List all reports: ~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\CMDBReports; $api = new API([/* … */]); $reports = new CMDBReports($api); $result = $reports->listReports(); var_dump($result);

Fetch the result of a report:, (*102)

~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\CMDBReports;, (*103)

$api = new API([/* … */]); $reports = new CMDBReports($api);, (*104)

$result = $reports->read(1);, (*105)

var_dump($result);, (*106)


Fetch the result of one or more reports: ~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\CMDBReports; $api = new API([/* … */]); $reports = new CMDBReports($api); $result = $reports->batchRead([1, 2]); var_dump($result);

Fetch next free IP address from subnet

~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\Subnet;, (*107)

$api = new API([/* … */]);, (*108)

$subnet = new Subnet($api); // Load subnet object by its identifier: $nextIP = $subnet->load(123)->next();, (*109)

echo 'Next IP address: ' . $nextIP . PHP_EOL;, (*110)


### Upload files This API client library is able to upload a file, create a new "File" object an assigned it to an existing object identified by its ID: ~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\File; $api = new API([/* … */]); $file = new File($api); // Assign one file to object with identifier 100: $file->add(100, '/path/to/file', 'my file'); // Assign many files to this object: $file->batchAdd( 100, [ 'file1.txt' => 'File 1', 'file2.txt' => 'File 2', 'file3.txt' => 'File 3' ] );

Each object may have an image gallery provided by assigned category "images". This is the way to upload image files and assign them to an existing object:, (*111)

~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\Image;, (*112)

$api = new API([/* … */]);, (*113)

$image = new Image($api);, (*114)

// Assign one image with a caption to object's gallery with identifier 100: $image->add(100, '/path/to/flowers.jpg', 'nice picture of flowers');, (*115)

// Assign many images to this object: $file->batchAdd( 100, [ 'file1.jpg' => 'JPEG file', 'file2.png' => 'PNG file', 'file3.bmp' => 'BMP file', 'file3.gif' => 'Animated GIF file' ] );, (*116)


### Self-defined request Sometimes it is better to define a request on your own instead of using pre-defined methods provided by this API client library. Here is the way to perform a self-defined request: ~~~ {.php} use Idoit\APIClient\API; $api = new API([/* … */]); $result = $api->request('idoit.version'); var_dump($result);

request() takes the method and optional parameters., (*117)

Self-defined batch request

Similar to a simple requests you may perform a batch requests with many sub-requests as you need:, (*118)

~~~ {.php} use Idoit\APIClient\API;, (*119)

$api = new API([/* … */]);, (*120)

$result = $api->batchRequest([ [ 'method' => 'idoit.version' ], [ 'method' => 'cmdb.object.read', 'params' => ['id' => 1] ] ]);, (*121)

var_dump($result);, (*122)


### Read information about your CMDB design Fetch information about object types, object types per group, categories assigned to object types, and attributes available in categories: ~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\CMDBObjectTypes; use Idoit\APIClient\CMDBObjectTypeGroups; use Idoit\APIClient\CMDBObjectTypeCategories; use Idoit\APIClient\CMDBCategoryInfo; $api = new API([/* … */]); // Object types: $objectTypes = new CMDBObjectTypes($api); $allObjectTypes = $objectTypes->read(); var_dump($allObjectTypes); $server = $objectTypes->readOne('C__OBJTYPE__SERVER'); var_dump($server); $someObjectTypes = $objectTypes->batchRead('C__OBJTYPE__SERVER', 'C__OBJTYPE__CLIENT'); var_dump($someObjectTypes); $client = $objectTypes->readByTitle('LC__CMDB__OBJTYPE__CLIENT'); var_dump($client); // Object types per group: $objectTypesPerGroup = new CMDBObjectTypeGroups($api); $objectTypes = $objectTypesPerGroup->read(); var_dump($objectTypes); // Categories assigned to object types: $assignedCategory = new CMDBObjectTypeCategories($api); $serverCategories = $assignedCategory->readByConst('C__OBJTYPE__SERVER'); var_dump($serverCategories); // Read by identifiers is also possible. And there are methods for batch requests. // Attributes available in categories: $categoryInfo = new CMDBCategoryInfo($api); $modelCategory = $categoryInfo->read('C__CATG__MODEL'); var_dump($modelCategory); $categories = $categoryInfo->batchRead([ 'C__CATG__MODEL', 'C__CATG__FORMFACTOR', 'C__CATS__PERSON_MASTER' ]); var_dump($categories);

Read information about i-doit itself

~~~ {.php} use Idoit\APIClient\API; use Idoit\APIClient\Idoit;, (*123)

$api = new API([/* … */]); $idoit = new Idoit($api);, (*124)

$version = $idoit->readVersion(); $constants = $idoit->readConstants(); $addOns = $idoit->getAddOns(); $license = $idoit->getLicense();, (*125)

var_dump($version, $constants, $addOns, $license);, (*126)


### Re-connect to server Sometimes you need a fresh connection. You may explicitly disconnect from the i-doit server and re-connect to it: ~~~ {.php} use Idoit\APIClient\API; $api = new API([/* … */]); // Do your stuff… $api->disconnect(); $api->isConnected(); // Returns false $api->connect(); $api->isConnected(); // Returns true

Debug API calls

For debugging purposes it is great to fetch some details about your API calls. This script uses some useful methods:, (*127)

~~~ {.php}, (*128)

!/usr/bin/env php

<?php, (*129)

use Idoit\APIClient\API; use Idoit\APIClient\Idoit;, (*130)

$start = time();, (*131)

require_once 'vendor/autoload.php';, (*132)

$api = new API([/* … */]);, (*133)

// @todo Insert your code here, for example: $request = new Idoit($api); $request->readVersion();, (*134)

fwrite(STDERR, 'Last request:' . PHP_EOL); fwrite(STDERR, '=============' . PHP_EOL); fwrite(STDERR, $api->getLastRequestHeaders() . PHP_EOL); fwrite(STDERR, json_encode($api->getLastRequestContent(), JSON_PRETTY_PRINT) . PHP_EOL); fwrite(STDERR, PHP_EOL); fwrite(STDERR, '--------------------------------------------------------------------------------' . PHP_EOL); fwrite(STDERR, 'Last response:' . PHP_EOL); fwrite(STDERR, '==============' . PHP_EOL); fwrite(STDERR, $api->getLastResponseHeaders() . PHP_EOL); fwrite(STDERR, json_encode($api->getLastResponse(), JSON_PRETTY_PRINT) . PHP_EOL); fwrite(STDERR, PHP_EOL); fwrite(STDERR, '--------------------------------------------------------------------------------' . PHP_EOL); fwrite(STDERR, 'Last connection:' . PHP_EOL); fwrite(STDERR, '================' . PHP_EOL); $info = $api->getLastInfo(); unset($info['request_header']); foreach ($info as $key => $value) { if (is_array($value)) { $value = '…'; } fwrite(STDERR, $key . ': ' . $value . PHP_EOL); } fwrite(STDERR, '--------------------------------------------------------------------------------' . PHP_EOL); fwrite(STDERR, 'Amount of requests: ' . $api->countRequests() . PHP_EOL); $memoryUsage = memory_get_peak_usage(true); fwrite(STDERR, sprintf('Memory usage: %s bytes', $memoryUsage) . PHP_EOL); $duration = time() - $start; fwrite(STDERR, sprintf('Duration: %s seconds', $duration) . PHP_EOL); ~~~, (*135)

Contribute

Please, report any issues to our issue tracker. Pull requests are very welcomed. If you like to get involved see file CONTRIBUTING.md for details., (*136)

Projects using this API client library

Send pull requests to add yours., (*137)

Copyright (C) 2022 synetics GmbH, (*138)

Copyright (C) 2016-2022 Benjamin Heisig, (*139)

Licensed under the GNU Affero GPL version 3 or later (AGPLv3+). This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law., (*140)

The Versions

28/06 2018

dev-master

9999999-dev https://github.com/bheisig/i-doit-api-client-php

Easy-to-use, but feature-rich client library for i-doit's JSON-RPC API

  Sources   Download

AGPL-3.0+

The Requires

  • php >=5.6.0
  • ext-curl *
  • ext-date *
  • ext-json *
  • ext-openssl *
  • ext-zlib *
  • ext-spl *

 

The Development Requires

api json-rpc i-doit cmdb it documentation

21/06 2018

0.6

0.6.0.0 https://github.com/bheisig/i-doit-api-client-php

Easy-to-use, but feature-rich client library for i-doit's JSON-RPC API

  Sources   Download

AGPL-3.0+

The Requires

  • php >=5.6.0
  • ext-curl *
  • ext-date *
  • ext-json *
  • ext-openssl *
  • ext-spl *
  • ext-zlib *

 

The Development Requires

api json-rpc i-doit cmdb it documentation

25/04 2018

0.5

0.5.0.0 https://github.com/bheisig/i-doit-api-client-php

Easy-to-use, but feature-rich client library for i-doit's JSON-RPC API

  Sources   Download

AGPL-3.0+

The Requires

  • php >=5.6.0
  • ext-curl *
  • ext-date *
  • ext-json *
  • ext-openssl *
  • ext-zlib *

 

The Development Requires

api json-rpc i-doit cmdb it documentation

21/02 2018

0.4

0.4.0.0 https://github.com/bheisig/i-doit-api-client-php

Easy-to-use, but feature-rich client library for i-doit's JSON-RPC API

  Sources   Download

AGPL-3.0+

The Requires

  • php >=5.6.0

 

The Development Requires

api json-rpc i-doit cmdb it documentation

25/07 2017

0.3

0.3.0.0 https://github.com/bheisig/i-doit-api-client-php

Easy-to-use, but feature-rich client library for i-doit's JSON-RPC API

  Sources   Download

AGPL-3.0+

The Requires

  • php >=5.6.0

 

The Development Requires

api json-rpc i-doit cmdb it documentation

05/04 2017

0.2

0.2.0.0 https://github.com/bheisig/i-doit-api-client-php

Easy-to-use, but feature-rich client library for i-doit's JSON-RPC API

  Sources   Download

AGPL-3.0+

The Requires

  • php >=5.6.0

 

The Development Requires

api json-rpc i-doit cmdb it documentation

09/02 2017

0.1

0.1.0.0 https://github.com/bheisig/i-doit-api-client-php

Simple PHP client for i-doit's JSON-RPC API

  Sources   Download

AGPL-3.0+

The Requires

  • php >=5.6.0

 

The Development Requires

api json-rpc i-doit cmdb it documentation