i-doit / api-client-php Goto Github PK
View Code? Open in Web Editor NEWEasy-to-use, but feature-rich client library for i-doit's JSON-RPC API
License: GNU Affero General Public License v3.0
Easy-to-use, but feature-rich client library for i-doit's JSON-RPC API
License: GNU Affero General Public License v3.0
Guten Tag
Ich habe eine neue Installation von i-doit in der Version 1.15.1 PRO und die API in der Version 1.11.2. Für diverse Tests möchte ich den API-Client nutzen. Die Nutzung des Clients erfolgt über "xampp". Bei dem Befehl "Initialize.php" erfolgt die Abfrage für den APi entry-point und den APi-Key. Danach erhalte ich folgende Fehlermeldung;
Ich habe auch eine Testinstallation unter i-doit Version 1.15.2 und der API Version 1.11.3, erhalte aber die gleiche Fehlermeldung.
Herzlichen Dank für Eure Hilfestellung.
Christian
$entryID = $category->create(
$jdkID,
'C__CATG__VERSION',
[
'title' => '1.8.0',
'description' => 'API TEST5',
// patchlevel scheint nicht zu funktionieren
'servicepack' => 'servicepack',
'kernel' =>'kernel',
'patchlevel' =>'SOMETEXTHERE'
]
);
print_r ($category->read($jdkID, 'C__CATG__VERSION', $entryID));
[0] => Array
(
[id] => 104
[objID] => 73415
[title] => 1.8.0
[servicepack] => servicepack
[kernel] => kernel
[patchlevel] => SOMETEXTHERE
[description] => API TEST5
)
Array
(
[id] => 107
[objID] => 73415
[title] => 1.8.0
[servicepack] => servicepack
[kernel] => kernel
[patchlevel] =>
[description] => API TEST5
)
just follow my code up above, it's pretty basic..
Question | Answer |
---|---|
bheisig/idoitapi version | 0.6 via composer |
PHP version | 7.0.30 |
i-doit version | 1.10.1 pro |
i-doit API add-on version | 1.9 |
Excerpt taken from /var/log/apache2/error.log
:
192.168.13.21 - - [16/Jul/2018:13:50:39 +0200] "POST /src/jsonrpc.php HTTP/1.1" 200 642 "-" "bheisig/idoitapi 0.6"
192.168.13.21 - - [16/Jul/2018:13:50:39 +0200] "POST /src/jsonrpc.php HTTP/1.1" 200 301 "-" "bheisig/idoitapi 0.6"
192.168.13.21 - - [16/Jul/2018:13:50:39 +0200] "POST /src/jsonrpc.php HTTP/1.1" 200 110 "-" "bheisig/idoitapi 0.6"
192.168.13.21 - - [16/Jul/2018:13:50:39 +0200] "POST /src/jsonrpc.php HTTP/1.1" 200 434 "-" "bheisig/idoitapi 0.6"
192.168.13.21 - - [16/Jul/2018:13:50:39 +0200] "POST /src/jsonrpc.php HTTP/1.1" 200 80 "-" "bheisig/idoitapi 0.6"
Excerpt taken from /var/www/html/i-doit/log/api_*.log
:
[2018-07-16 13:52:40 0.07794100] INFO: JSON-RPC controller started for request: array ( 'version' => '2.0', 'method' => 'cmdb.category.create', 'params' => array ( 'objID' => 73415, 'data' => array ( 'title' => '1.8.0', 'description' => 'API TEST5', 'servicepack' => 'servicepack', 'kernel' => 'kernel', 'patchlevel' => 'patchlevel', ), 'category' => 'C__CATG__VERSION', 'apikey' => '2c6goba23d', ), 'id' => 5,)
[2018-07-16 13:52:40 0.18825700] INFO: Transmitting response: {"jsonrpc":"2.0","result":[{"id":"109","objID":"73415","title":"1.8.0","servicepack":"servicepack","kernel":"kernel","patchlevel":"","description":"API TEST5"},{"id":"110","objID":"73415","title":"1.8.0","servicepack":"servicepack","kernel":"kernel","patchlevel":"","description":"API TEST5"},{"id":"111","objID":"73415","title":"1.8.0","servicepack":"servicepack","kernel":"kernel","patchlevel":"","description":"API TEST5"},{"id":"112","objID":"73415","title":"1.8.0","servicepack":"servicepack","kernel":"kernel","patchlevel":"","description":"API TEST5"}],"id":6}
normal login into idoit via the api
PHP Fatal error: Uncaught RuntimeException: i-doit responded with an error: i-doit system error: Unable to get userId by credentials in /var/www/itservices/ois/vendor/bheisig/idoitapi/src/API.php:630
Stack trace:
#0 /var/www/itservices/ois/vendor/bheisig/idoitapi/src/API.php(418): bheisig\idoitapi\API->evaluateResponse(Array)
#1 /var/www/itservices/ois/vendor/bheisig/idoitapi/src/API.php(338): bheisig\idoitapi\API->request('idoit.login')
#2 /var/www/itservices/ois/idoit-config.php(15): bheisig\idoitapi\API->login()
#3 /var/www/itservices/ois/fips.php(46): require_once('/var/www/itserv...')
#4 {main}
thrown in /var/www/itservices/ois/vendor/bheisig/idoitapi/src/API.php on line 630
require_once 'vendor/autoload.php';
use bheisig\idoitapi\API;
echo "initializing API...\n";
$api = new API([
'url' => 'https://i-doit.example.net/src/jsonrpc.php',
'key' => 'XXXXXXXXX',
'username' => 'ansible',
'password' => 'YYYYYYYYYYYYYYYYY'
]);
echo "logging into idoit...\n";
$api->login();
Question | Answer |
---|---|
bheisig/idoitapi version | 0.7 |
PHP version | 7.0.31 |
i-doit version | 1.12 pro |
i-doit API add-on version | 1.10 |
Excerpt taken from /var/log/apache2/error.log
:
Paste logs
Excerpt taken from /var/www/html/i-doit/log/api_*.log
:
Paste logs
The test testCreateWithCategories() in CMDBObjectTest.php verifies from line 233-256 the creation of three category entries by checking the content of the $result associative array.
$modelEntryID, $firstIPEntryID and $secondIPEntryID should contain the correct references (
// Verify entries:
$objectID = $result['id'];
$modelEntryID = (int) $result['categories'][Category::CATG__MODEL][0];
$firstIPEntryID = $result['categories'][Category::CATG__IP][0];
$secondIPEntryID = $result['categories'][Category::CATG__IP][1];
$secondIPEntryID contains an incorrect index and references the first IP entry of the array $result['categories'].
// Verify entries:
$objectID = $result['id'];
$modelEntryID = (int) $result['categories'][Category::CATG__MODEL][0];
$firstIPEntryID = $result['categories'][Category::CATG__IP][0];
$secondIPEntryID = $result['categories'][Category::CATG__IP][0];
Run the unit test CMDBObjectTest->testCreateWithCategories().
Current main branch.
hallo benjamin,
ich hab versucht einen entry fuer eine custom category anzulegen, mit folgendem syntax:
$entryID = $category->create(
$objectID,
'C__CATG__CUSTOM_FIELDS_MONITORINGCHECKS',
[
'f_text_c_1506087447500' => "textual-content",
'f_link_c_1506087469287' => "textual-content"
]
);
-> der eintrag wird nicht angelegt. und die api gibt mir folgendes zurueck:
[2017-09-26 14:42:50 0.07164900] INFO: JSON-RPC controller started for request: array ( 'version' => '2.0', 'method' => 'cmdb.category.create', 'params' => array ( 'objID' => 28, 'data' => array (
'f_text_c_1506087447500' => 'textual-content', 'f_link_c_1506087469287' => 'textual-content', ), 'catgID' => 'C__CATG__CUSTOM_FIELDS_MONITORINGCHECKS', 'apikey' => '5usn4n47e', ), 'id' => 5
,)
[2017-09-26 14:42:50 0.07166200] INFO: API-Key: 5usn4n47e
[2017-09-26 14:42:50 0.07167900] INFO: Logging in with RPC Session header (User: controller)
[2017-09-26 14:42:50 0.08476800] INFO: Logged in as controller
[2017-09-26 14:42:50 0.08773100] INFO: Method: create
[2017-09-26 14:42:50 0.11641700] INFO: Data: array (
)
[2017-09-26 14:42:50 0.11647600] INFO: Transmitting response: {"jsonrpc":"2.0","result":{"id":"1","message":"Category entry successfully created.","success":true},"id":5}
[2017-09-26 14:42:50 0.11649200] INFO: Request with id 5 transmitted.
mit dem custom-request geht es hingegen:
$result = $api->request("cmdb.category.create",
array(
"language"=> "en",
"category"=> "C__CATG__CUSTOM_FIELDS_MONITORINGCHECKS",
"objID"=> $objectID,
"data"=>array (
"f_text_c_1506087447500"=> "textual-content",
"f_link_c_1506087469287"=> "textual-content"
)
)
);//*/
2017-09-26 14:43:43 0.86415100] INFO: JSON-RPC controller started for request: array ( 'version' => '2.0', 'method' => 'cmdb.category.create', 'params' => array ( 'language' => 'en', 'category' => 'C
__CATG__CUSTOM_FIELDS_MONITORINGCHECKS', 'objID' => 28, 'data' => array ( 'f_text_c_1506087447500' => 'textual-content', 'f_link_c_1506087469287' => 'textual-content', ), 'apikey' => '5
usn4n47e', ), 'id' => 5,)
[2017-09-26 14:43:43 0.86417100] INFO: API-Key: 5usn4n47e
[2017-09-26 14:43:43 0.86419900] INFO: Logging in with RPC Session header (User: controller)
[2017-09-26 14:43:43 0.87787000] INFO: Logged in as controller
[2017-09-26 14:43:43 0.88046100] INFO: Method: create
[2017-09-26 14:43:43 0.92881000] INFO: Data: array (
)
[2017-09-26 14:43:43 0.92888800] INFO: Transmitting response: {"jsonrpc":"2.0","result":{"id":6,"message":"Category entry successfully created.","success":true},"id":5}
[2017-09-26 14:43:43 0.92890700] INFO: Request with id 5 transmitted.
der unterschied scheint einmal category und andernmal catgID im request zu sein.
ich hab auch versucht statt der 'constant' C__CATG__CUSTOM_FIELDS_MONITORINGCHECKS, wie der feld name es suggeriert die id dieser custom category anzugeben. aber ich weiss nicht ob ich da die richtige, art, in meinem fall '2' erwischt habe. hat jedenfalls auch nicht funktioniert.
ich hab kein problem weil ich das einfach mit dem custom request jetzt lassen werde. aber ich dachte ich schreib dir das, falls da ein bug is, und du zeit und lust hast, das zu perfektionieren.
The environment variable username in windows environments can't be changed with .env file
Connect successfully with username (=admin) defined in .env-File
Connection fails, because of wrong username.
The username is set to the username with the user logged into windows.
However, this username can differ from the username defined in the .env file
Changing the environment variable to IDOIT_USERNAME works:
File: .env
IDOIT_USERNAME=admin
File: BaseTest.php
Method: setUp()
Line: 143
if (getenv('IDOIT_USERNAME') !== false && getenv('PASSWORD') !== false) {
$config[API::USERNAME] = getenv('IDOIT_USERNAME');
$config[API::PASSWORD] = getenv('PASSWORD');
}
Windows
Hallo,
ich würde gerne in CMDBObject.php die Restore-Funktion benutzen. Ein Status-Update scheint ja nicht zu klappen.
Gibt es über die API evtl. eine andere Möglichkeit, wie man Objekte wiederherstellen kann? Ist etwas in der Art in Planung? Oder muss ich weiterhin auf die Restore-Funktion verzichten? Damit ist eine Sync-Schnittstelle leider nur schwer abzubilden...
Viele Grüße
Michael
Hallo,
nach dem Update auf die aktuelle Pro Version 1.16.2 habe ich wie beschrieben mittels composer die Api wieder installiert. Dabei scheint aber ein Downgrade an einigen Paketen zu erfolgen. Dies hat den Effekt, dass Fehler in I-doit auftreten.
bheisig/idoitapi version 0.10.0
i-doit version 1.16.2
i-doit API add-on version 1.12.1
Hier die Ausgabe von composer:
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Warning from https://repo.packagist.org: You are using an outdated version of Composer. Composer 2 is now available and you should upgrade. See https://getcomposer.org/2
Using version ^0.10.0 for bheisig/idoitapi
./composer.json has been updated
Loading composer repositories with package information
Warning from https://repo.packagist.org: You are using an outdated version of Composer. Composer 2 is now available and you should upgrade. See https://getcomposer.org/2
Updating dependencies (including require-dev)
Package operations: 15 installs, 30 updates, 11 removals
~0.12
as dependency)~0.12
as dependency)~0.12
as dependency)~0.12
as dependency)~0.12
as dependency)Hier der I-doit Fehler z.B. beim Aufruf der console.php:
PHP Fatal error: Uncaught Error: Class 'idoit\Component\ClassLoader\MapClassLoader' not found in /var/www/html/i-doit/src/autoload.inc.php:271
Stack trace:
#0 /var/www/html/i-doit/src/bootstrap.inc.php(36): include_once()
#1 /var/www/html/i-doit/console.php(14): require('/var/www/html/i...')
#2 {main}
thrown in /var/www/html/i-doit/src/autoload.inc.php on line 271
ich mach category->read(..)
und bekomme ein leeres array,also mache ich
category->create(...)..
dabei tritt folgender fehler auf..
ich wollte das nur grob melden, zu deiner information;
ich werd mal schauen das ich die exception abfange und einfach weitermache..
gruesse,
PK
creating the group membership category
PHP Fatal error: Uncaught RuntimeException: Bad result: Category entry was already existing and has been updated. [This method is deprecated und will be removed i
n a feature release. Use 'cmdb.category.save' instead.] in /var/www/itservices/ois/vendor/bheisig/idoitapi/src/CMDBCategory.php:104
Stack trace:
#0 /var/www/itservices/ois/idoit-syncdoc.php(399): bheisig\idoitapi\CMDBCategory->create(148915, 'C__CATG__GROUP_...', Array)
Question | Answer |
---|---|
bheisig/idoitapi version | 0.7 |
PHP version | 7.2 |
i-doit version | 1.12.1 mit hotfixes fuer api open/pro |
i-doit API add-on version | latest |
Excerpt taken from /var/log/apache2/error.log
:
Paste logs
Excerpt taken from /var/www/html/i-doit/log/api_*.log
:
Paste logs
Hello World Example returns the i-doit version
I'm getting the following error:
PHP Fatal error: Uncaught Exception: The requested URL returned error: 403 in /opt/scripts/vendor/bheisig/idoitapi/src/API.php:512
Stack trace:
#0 /opt/scripts/vendor/bheisig/idoitapi/src/API.php(405): bheisig\idoitapi\API->execute(Array)
#1 /opt/scripts/vendor/bheisig/idoitapi/src/Idoit.php(40): bheisig\idoitapi\API->request('idoit.version')
#2 /opt/scripts/apiclient.php(16): bheisig\idoitapi\Idoit->readVersion()
#3 {main}
thrown in /opt/scripts/vendor/bheisig/idoitapi/src/API.php on line 512
Try using the provided "Hello, World!" example (change the API variables to your need ofc), mine looks like this:
#!/usr/bin/php
<?php
use bheisig\idoitapi\API;
use bheisig\idoitapi\Idoit;
require_once 'vendor/autoload.php';
$api = new API([
'url' => 'https://_yourserver_/src/jsonrpc.php',
'key' => '_yourapikey_',
'username' => '_yourusername_',
'password' => '_yourpassword_'
]);
$request = new Idoit($api);
$info = $request->readVersion();
var_dump($info);
?>
### Underscored text has been altered
Question | Answer |
---|---|
bheisig/idoitapi version | 0.4 |
PHP version | 7.0.29 |
i-doit version | 1.10.1 pro |
i-doit API add-on version | 1.9 |
Excerpt taken from /var/log/apache2/error.log
:
sadly the log doesn't show anything when executing the script
Excerpt taken from /var/www/html/i-doit/log/api_*.log
:
same here, no information is logged
When i do a "manual" curl api call it works fine with the same api url/key/user.
That's why it shouldn't be a permission problem, right?
Unit-Test does not fail.
Unit-Test works as expected.
Run unit test.
Question | Answer |
---|---|
bheisig/idoitapi version | master |
i-doit version | 1.15 pro |
i-doit API add-on version | bugfix |
Problems in "testAssignSingleObject":
Problems in "testAssignMultipleObjects"
Hello everyone,
The standard installation does not work according to the instructions.
Error message occurs on a Linux with Apache2 and PHP 8.2
Fatal error: Uncaught Error: Class "Idoit\APIClient\API" not found in /var/www/test/idoit-api/api.php:12 Stack trace: #0 {main} thrown in /var/www/test/idoit-api/api.php on line 12
My Code
`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);`
My environment:
Debian 12, Apache 2.4.57-2 , PHP 8.2.7-1~deb12u1
phpcs on windows throws on every file following error: End of line character is invalid; expected "\n" but found "\r\n"
FILE: ...\MAMP\htdocs\api-client-php\tests\Idoit\APIClient\SubnetTest.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
1 | ERROR | [x] End of line character is invalid; expected "\n" but
| | found "\r\n"
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------
Found this Issue:
squizlabs/PHP_CodeSniffer#2554
I'm not firm with phpcs, so I can't judge if my successful test can be a solution!
create ruleset.xlm from following link
https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/src/Standards/PSR2/ruleset.xml
Change eolChar from "\n" to "\r\n"
<rule ref="Generic.Files.LineEndings">
<properties>
<property name="eolChar" value="\r\n"/>
</properties>
</rule>
<!-- checked by PSR2.Classes.ClassDeclaration -->
<!-- <rule ref="Squiz.Functions.MultiLineFunctionDeclaration"/> -->
"phpcs-win": "./vendor/bin/phpcs --standard=ruleset.xml --extensions=php src/ tests/",
composer phpcs-win
Windows
Throw SPL exceptions on error whenever possible
Only standard \Exception
instances are thrown
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.