Methods > glpi.createObjects > PHP Script Example (XML-RPC)

In the examplexmlrpc.php php script you can see a complete implementation example for glpi.createObjects method.

You can find this script in release v1.1.0+ (eg : /plugins/webservices/scripts/examplexmlrpc.php) or directly in the current trunk :
https://forge.indepnet.net/projects/webservices/repository/changes/trunk/scripts/examplexmlrpc.php

For use this script, of course, the webservices plugin is installed and XML-RPC PHP extension is OK.

Running the script with command php examplexmlrpc.php --help in a terminal (eg : CMD in windows) should display the help screen.

sh-3.2# php examplexmlrpc.php --help

usage : examplexmlrpc.php [options] 

    help     : display this screen
    host     : server name or IP (default = localhost)
    url      : SOAP plugin URL (default = /glpi/plugins/webservices/xmlrpc.php)

    ws_user : login name of webservices user (optional)
    ws_pass : login password of webservices user (optional)

    glpi_user : login name of GLPI user (default = glpi)
    glpi_pass : login password of GLPI user (default = glpi)

    glpi_test_user : login name for created user (default = WSXML-RPC_User_01_TESTING)
    glpi_test_pass : password for test user (default = WSXML-RPC_User_01_TESTING)

    deflate  : allow server to compress response (if supported)

This example do the following ACTIONS :
  • Make login into glpi
  • Create one ENTITY
  • Create one PROFILE
  • Create on USER and on GROUP
  • Affect USER in the GROUP previously created
  • and affect PROFILE previously created to the USER previously created too
  • Create one COMPUTER and one MONITOR (with the previously created - eg: Entity/User/Group)
  • Create a link between COMPUTER and MONITOR
  • Show the COMPUTER with monitor informations.

-------
Output call example (with --deflate option)

sh-3.2# php examplexmlrpc.php --deflate
+ Calling glpi.doLogin on http://localhost/glpi/plugins/webservices/xmlrpc.php
+ Compressed response : 218
+ Uncompressed response : 688 (32%)
+ Calling glpi.createObjects on http://localhost/glpi/plugins/webservices/xmlrpc.php
+ Compressed response : 284
+ Uncompressed response : 1005 (28%)
+ Calling glpi.doLogout on http://localhost/glpi/plugins/webservices/xmlrpc.php
+ Compressed response : 163
+ Uncompressed response : 266 (61%)
+ Calling glpi.doLogin on http://localhost/glpi/plugins/webservices/xmlrpc.php
+ Compressed response : 217
+ Uncompressed response : 688 (32%)
+ Calling glpi.createObjects on http://localhost/glpi/plugins/webservices/xmlrpc.php
+ Compressed response : 448
+ Uncompressed response : 2647 (17%)
+ Calling glpi.createObjects on http://localhost/glpi/plugins/webservices/xmlrpc.php
+ Compressed response : 424
+ Uncompressed response : 2983 (14%)
+ Calling glpi.createObjects on http://localhost/glpi/plugins/webservices/xmlrpc.php
+ Compressed response : 300
+ Uncompressed response : 2005 (15%)
+ Calling glpi.createObjects on http://localhost/glpi/plugins/webservices/xmlrpc.php
+ Compressed response : 596
+ Uncompressed response : 6961 (9%)
+ Calling glpi.createObjects on http://localhost/glpi/plugins/webservices/xmlrpc.php
+ Compressed response : 228
+ Uncompressed response : 796 (29%)
+ Calling glpi.doLogout on http://localhost/glpi/plugins/webservices/xmlrpc.php
+ Compressed response : 163
+ Uncompressed response : 266 (61%)
+ Calling glpi.doLogin on http://localhost/glpi/plugins/webservices/xmlrpc.php
+ Compressed response : 215
+ Uncompressed response : 688 (31%)
+ Calling glpi.getObject on http://localhost/glpi/plugins/webservices/xmlrpc.php
+ Compressed response : 669
+ Uncompressed response : 5996 (11%)
Array
(
    [name] => WSXML-RPC_Computer_01_TESTING
    [id] => 1
    [locations_id] => 0
    [computertypes_id] => 0
    [computermodels_id] => 0
    [states_id] => 0
    [operatingsystems_id] => 0
    [operatingsystemversions_id] => 0
    [operatingsystemservicepacks_id] => 0
    [autoupdatesystems_id] => 0
    [serial] => I98GFD-FF98-F0ZFDF8-980
    [otherserial] => 0000134
    [users_id] => 6
    [groups_id] => 1
    [date_mod] => 2011-02-07 17:30:22
    [networks_id] => 0
    [domains_id] => 0
    [manufacturers_id] => 0
    [users_id_tech] => 0
    [entities_id] => 1
    [is_ocs_import] => 0
    [Monitor] => Array
        (
            [0] => Array
                (
                    [name] => WSXML-RPC_Monitor_01_TESTING
                    [id] => 1
                    [locations_id] => 0
                    [monitortypes_id] => 0
                    [monitormodels_id] => 0
                    [states_id] => 0
                    [serial] => I98GFD-8973987-DE98
                    [otherserial] => 0000190
                    [users_id] => 6
                    [groups_id] => 1
                    [date_mod] => 2011-02-07 17:30:22
                    [size] => 0
                    [have_micro] => 0
                    [have_speaker] => 0
                    [have_subd] => 0
                    [have_bnc] => 0
                    [have_dvi] => 0
                    [have_pivot] => 0
                    [manufacturers_id] => 0
                    [users_id_tech] => 0
                    [entities_id] => 1
                    [is_global] => 0
                )

        )

)
+ Calling glpi.doLogout on http://localhost/glpi/plugins/webservices/xmlrpc.php
+ Compressed response : 163
+ Uncompressed response : 266 (61%)