glpi-project / glpi

GLPI is a Free Asset and IT Management Software package, Data center management, ITIL Service Desk, licenses tracking and software auditing.
https://glpi-project.org
GNU General Public License v3.0
4.24k stars 1.29k forks source link

API: /getActiveEntities response #965

Closed humboldtux closed 8 years ago

humboldtux commented 8 years ago

I get this answer by requesting /getActiveEntities:

$ curl -H "Session-Token: 7r7436i0u4m0qqdn0v5rc43el5" 'http://glpi.lan:8080/apirest.php/getActiveEntities'

{"active_entity":1,"active_entity_recursive":true,"active_entities":{"1":1,"2":2}}

Where, from the official API documentation, the response should be: {"active_entity":1,"active_entity_recursive":true,"active_entities":[{"1":1},{"2":2}]}

Even better, could the reponse of this endpoint be changed to:

{"active_entity":{"id":1,"active_entity_recursive":true,"active_entities":[{"id":1},{"id":2}]}}

It follows http://jsonapi.org/, and is easier to parse.

I'm using Master. Server configuration:

Informations

sur le système, l'installation et la configuration [code]

GLPI 9.1-RC2-114-g975ad0f ( => /var/www/html/glpi.git)

Server

Operating system: Linux debian 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt25-2+deb8u3 (2016-07-02) x86_64 PHP 5.6.24-0+deb8u1 apache2handler (Core, PDO, Phar, Reflection, SPL, SimpleXML, Zend OPcache, apache2handler, bcmath, bz2, calendar, ctype, curl, date, dba, dom, ereg, exif, fileinfo, filter, ftp, gd, gettext, hash, iconv, json, libxml, mbstring, mhash, mysql, mysqli, openssl, pcre, pdo_mysql, posix, readline, session, shmop, soap, sockets, standard, sysvmsg, sysvsem, sysvshm, tokenizer, wddx, xml, xmlreader, xmlwriter, zip, zlib) Setup: max_execution_time="30" memory_limit="128M" post_max_size="8M" safe_mode="" session.save_handler="files" upload_max_filesize="2M" Software: Apache/2.4.10 (Debian) (Apache/2.4.10 (Debian) Server at glpi.lan Port 8080) Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36 Server Software: (Debian) Server Version: 5.5.50-0+deb8u1 Server SQL Mode: Parameters: root@localhost/glpi Host info: Localhost via UNIX socket

OK/var/www/html/glpi.git/config : OK OK/var/www/html/glpi.git/files : OK OK/var/www/html/glpi.git/files/_dumps : OK OK/var/www/html/glpi.git/files/_sessions : OK OK/var/www/html/glpi.git/files/_cron : OK OK/var/www/html/glpi.git/files/_graphs : OK OK/var/www/html/glpi.git/files/_lock : OK OK/var/www/html/glpi.git/files/_plugins : OK OK/var/www/html/glpi.git/files/_tmp : OK OK/var/www/html/glpi.git/files/_rss : OK OK/var/www/html/glpi.git/files/_uploads : OK OK/var/www/html/glpi.git/files/_pictures : OK OK/var/www/html/glpi.git/files/_log : OK Web access to files directory is protectedWeb access to files directory is protected : OK

Libraries

htmLawed version 1.1.21 in (/var/www/html/glpi.git/lib/htmlawed) phpCas version 1.3.4 in (/var/www/html/glpi.git/vendor/jasig/phpcas/source) PHPMailer version 5.2.16 in (/var/www/html/glpi.git/vendor/phpmailer/phpmailer) ZetaComponent ezcGraph installed in (/var/www/html/glpi.git/vendor/zetacomponents/graph/src): OK Zend Framework in (/var/www/html/glpi.git/vendor/zendframework/zend-loader/src) SimplePie version 1.4.1 in (/var/www/html/glpi.git/vendor/simplepie/simplepie/library) TCPDF version 6.2.12 in (/var/www/html/glpi.git/vendor/tecnickcom/tcpdf) ircmaxell/password-compat in (/var/www/html/glpi.git/vendor/ircmaxell/password-compat/lib). Compatitility: Ok iacaml/autolink in (/var/www/html/glpi.git/vendor/iamcal/lib_autolink) sabre/vobject in (/var/www/html/glpi.git/vendor/sabre/vobject/lib) guzzlehttp/guzzle in ()`

trasher commented 8 years ago

I agree with changing the response, that sounds more logical to me.

trasher commented 8 years ago

@humboldtux changes have been made to the master branch; could you please test it and close this ticket if it is ok for you? Many thanks!

trasher commented 8 years ago

This is on the orthagh:9.1/apijson.org_compat branch, not on the master; sorry for the confusion.

humboldtux commented 8 years ago

I get:

{
    "active_entity": {
        "id": 1,
        "active_entity_recursive": true,
        "active_entities": [1, 2]
    }
}

Where

{
    "active_entity": {
        "id": 1,
        "active_entity_recursive": true,
        "active_entities": [{
            "id": 1
        }, {
            "id": 2
        }]
    }
}

would be easier to parse.

orthagh commented 8 years ago

still on my fork, you should have an array instead of an object on key active_entities

trasher commented 8 years ago

Fixed in the master, the real one! :)

humboldtux commented 8 years ago

@orthagh, whether from updated master or your fork, i'm still getting

{
    "active_entity": {
        "id": 1,
        "active_entity_recursive": true,
        "active_entities": [1, 2]
    }
}

Is it the definitive response you want to return? not:

{
    "active_entity": {
        "id": 1,
        "active_entity_recursive": true,
        "active_entities": [{
            "id": 1
        }, {
            "id": 2
        }]
    }
}
orthagh commented 8 years ago

It shouldn't : https://github.com/glpi-project/glpi/commit/406f0fe85967f4dcfff4cea0c4e9129ea099d778#diff-e01cdca9469fc2d2fa8a60ea83250903R303

It's now on this repo master

trasher commented 8 years ago

Using latest master, I still have the incorrect output:

{
  "active_entity": {
    "id": 0,
    "active_entity_recursive": 1,
    "active_entities": [
      0,
      1,
      2,
      3
    ]
  }
}
orthagh commented 8 years ago

oh ok, i missed you want this kind of output