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: /getMyProfiles response #964

Closed humboldtux closed 8 years ago

humboldtux commented 8 years ago

I get this answer by requesting /getMyProfiles:

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

{"1":{"name":"Self-Service","entities":[{"id":0,"name":"Root entity","is_recursive":1},{"id":1,"name":"Sub1","is_recursive":0}]},"6":{"name":"Technician","entities":[{"id":0,"name":"Root entity","is_recursive":1}]}}

Where, from the official API documentation, the response should be: [ 1: { 'name': "Self-Service", 'entities': { ... }, ... }, .... ]

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

{ "profiles": [ { "id":1,"name":"Self-Service","entities": [{"id":0,"name":"Root entity","is_recursive":1},{"id":1,"name":"Sub1","is_recursive":0}] }, { "id":6,"name":"Technician","entities": [{"id":0,"name":"Root entity","is_recursive":1}] } ] }

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

Also agree with proposed output, sounds more clear than it is actually.

orthagh commented 8 years ago

Seems ok for me. @newls and @gatemed should take note of this change

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!

humboldtux commented 8 years ago

@trasher nothing new in master regarding this issue. Am i missing something? Should i test against orthagh/glpi?

trasher commented 8 years ago

@humboldtux sorry... this is noit yet in the master, I wanted your feedback before... You can use the orthagh:9.1/apijson.org_compat branch; thank you :)

humboldtux commented 8 years ago

I get:

{
    "myprofiles": [{
        "id": 1,
        "name": "Self-Service",
        "entities": {
            "1": {
                "id": 1,
                "name": "Sub1",
                "is_recursive": 1
            },
            "2": {
                "id": 2,
                "name": "Sub2",
                "is_recursive": 1
            }
        }
    }, {
        "id": 4,
        "name": "Super-Admin",
        "entities": [{
            "id": 0,
            "name": "Root entity",
            "is_recursive": 1
        }]
    }]
}

Where it would be better to have:

{
    "myprofiles": [{
        "id": 1,
        "name": "Self-Service",
        "entities": [{
            "id": 1,
            "name": "Sub1",
            "is_recursive": 1
        }, {
            "id": 2,
            "name": "Sub2",
            "is_recursive": 1
        }]
    }, {
        "id": 4,
        "name": "Super-Admin",
        "entities": [{
            "id": 0,
            "name": "Root entity",
            "is_recursive": 1
        }]
    }]
}
orthagh commented 8 years ago

Hello @humboldtux

Could you explain in detail the diff (and format/indent :) ) ?

On my side, i get the following data (the entities key matches an array and not an object) :

{  
   "myprofiles":[  
      {  
         "id":1,
         "name":"Client - Simple",
         "entities":[  
            {  
               "id":0,
               "name":"Entité racine",
               "is_recursive":1
            }
         ]
      },
      {  
         "id":45,
         "name":"only create ticket",
         "entities":[  
            {  
               "id":0,
               "name":"Entité racine",
               "is_recursive":1
            }
         ]
      },
      {  
         "id":4,
         "name":"super-admin",
         "entities":[  
            {  
               "id":0,
               "name":"Entité racine",
               "is_recursive":1
            },
            {  
               "id":1,
               "name":"1 - Interne Teclib",
               "is_recursive":1
            }
         ]
      },
      {  
         "id":14,
         "name":"TECLIB' Experts",
         "entities":[  
            {  
               "id":0,
               "name":"Entité racine",
               "is_recursive":1
            }
         ]
      },
      {  
         "id":13,
         "name":"TECLIB' Helpdesk",
         "entities":[  
            {  
               "id":0,
               "name":"Entité racine",
               "is_recursive":1
            }
         ]
      }
   ]
}
humboldtux commented 8 years ago

Hi @orthagh Sorry for the indentation, i fixed my previous comment. If you look closely at the output, you will see that the entities array of the first profile is wrong.

orthagh commented 8 years ago

ok i got it, in my case, i have keys 0 & 1, so json_encode consider it as an array, in your cases, id are 1 and 2, and it results in a object transformation. I'll push a fix for that

orthagh commented 8 years ago

Here is, could you update from my fork ?

humboldtux commented 8 years ago

Working like charm, thank you @orthagh

orthagh commented 8 years ago

I reopen, we still need to merge the pull request :)

ghost commented 8 years ago

^^

trasher commented 8 years ago

Fixed in master (the real master, this time ;))