Methods > glpi.createObjects > PHP Script Example (SOAP)

In the examplesoap.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/examplesoap.php) or directly in the current trunk :
https://forge.indepnet.net/projects/webservices/repository/changes/trunk/scripts/examplesoap.php

For use this script, Oof course, the webservices plugin is installed and SOAP PHP extension is OK.

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

sh-3.2# php examplesoap.php --help

usage : examplesoap.php [options] 

    help     : display this screen
    host     : server name or IP (default = localhost)
    url      : SOAP plugin URL (default = /glpi_078_svn/plugins/webservices/soap.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 = WSOAP_User_01_TESTING)
    glpi_test_pass : password for test user (default = WSOAP_User_01_TESTING)

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

sh-3.2# php examplesoap.php 
+ Calling glpi.doLogin on http://localhost/glpi/plugins/webservices/soap.php
+ Calling glpi.createObjects on http://localhost/glpi/plugins/webservices/soap.php
+ Calling glpi.doLogout on http://localhost/glpi/plugins/webservices/soap.php
+ Calling glpi.doLogin on http://localhost/glpi/plugins/webservices/soap.php
+ Calling glpi.createObjects on http://localhost/glpi/plugins/webservices/soap.php
+ Calling glpi.createObjects on http://localhost/glpi/plugins/webservices/soap.php
+ Calling glpi.createObjects on http://localhost/glpi/plugins/webservices/soap.php
+ Calling glpi.createObjects on http://localhost/glpi/plugins/webservices/soap.php
+ Calling glpi.createObjects on http://localhost/glpi/plugins/webservices/soap.php
+ Calling glpi.doLogout on http://localhost/glpi/plugins/webservices/soap.php
+ Calling glpi.doLogin on http://localhost/glpi/plugins/webservices/soap.php
+ Calling glpi.getObject on http://localhost/glpi/plugins/webservices/soap.php
Array
(
    [name] => WSOAP_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:36:37
    [networks_id] => 0
    [domains_id] => 0
    [manufacturers_id] => 0
    [users_id_tech] => 0
    [entities_id] => 1
    [is_ocs_import] => 0
    [Monitor] => Array
        (
            [1] => Array
                (
                    [name] => WSOAP_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:36:37
                    [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/soap.php