Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API: /getMyProfiles response #964

Closed
humboldtux opened this issue Sep 11, 2016 · 14 comments
Closed

API: /getMyProfiles response #964

humboldtux opened this issue Sep 11, 2016 · 14 comments
Milestone

Comments

@humboldtux
Copy link
Contributor

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
Copy link
Contributor

trasher commented Sep 13, 2016

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

@orthagh
Copy link
Contributor

orthagh commented Sep 14, 2016

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

@trasher
Copy link
Contributor

trasher commented Sep 15, 2016

@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 trasher added this to the 9.1 milestone Sep 15, 2016
@humboldtux
Copy link
Contributor Author

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

@trasher
Copy link
Contributor

trasher commented Sep 15, 2016

@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
Copy link
Contributor Author

humboldtux commented Sep 15, 2016

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
Copy link
Contributor

orthagh commented Sep 15, 2016

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
Copy link
Contributor Author

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
Copy link
Contributor

orthagh commented Sep 15, 2016

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
Copy link
Contributor

orthagh commented Sep 15, 2016

Here is, could you update from my fork ?

@humboldtux
Copy link
Contributor Author

Working like charm, thank you @orthagh

@orthagh orthagh reopened this Sep 15, 2016
@orthagh
Copy link
Contributor

orthagh commented Sep 15, 2016

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

@ghost
Copy link

ghost commented Sep 15, 2016

^^

trasher pushed a commit that referenced this issue Sep 15, 2016
Rreview getActiveEntities & getMyProfiles endpoint; fixes #965 and #964
@trasher
Copy link
Contributor

trasher commented Sep 15, 2016

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

@trasher trasher closed this as completed Sep 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants