You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2017-07-06 06:03:52

lexcorp
Member
Registered: 2014-09-17
Posts: 64

Web Service | method:glpi.createTicket | xmlrpc error(16): Command not

GLPI Version: 9.1.4
Plugin Web Service Version: 1.7.0

Hello, I'm running the glpi.createTicket method, from an external application using the web services plugin.

If I execute the method passing it as an argument a session hash of the post-only user, it sends me the following error:

+ Calling glpi.createTicket on http://192.168.1.86/glpi/plugins/webservices/xmlrpc.php
xmlrpc error(16): Command not allowed

The webservices.log file throws me the following output:

2017-07-05 22:22:37 [3@5410-PC-OCS]
Execute method:glpi.createTicket (xml-rpc), function:PluginWebservicesMethodHelpdesk::methodCreateTicket, duration:0.109, size:73
2017-07-05 22:22:37 [3@5410-PC-OCS]
Connection: post-only, 192.168.1.86
Protocol: xml-rpc, Method: glpi.createTicket, Function: PluginWebservicesMethodHelpdesk::methodCreateTicket
Params: Array
(
    [session] => 258ur5gp991aao6af2d62nbqq0
    [method] => glpi.createTicket
    [type] => 1
    [category] => 2
    [title] => Test web service
    [content] => This is a test of creation of tickets through web services
)
Compression: Server:/, Config:0, Agent:?
Duration: 0.109
Response size: 73
Response content: Array
(
    [faultCode] => 16
    [faultString] => Command not allowed
)

A simple right to create a ticket is enough?

-------------------------------------------------------------------------------------------------------------------------------------

If I execute the method passing it as a session hash session of the glpi user, it creates the ticket without problems.

Offline

#2 2017-07-06 07:06:01

lexcorp
Member
Registered: 2014-09-17
Posts: 64

Re: Web Service | method:glpi.createTicket | xmlrpc error(16): Command not

I found the problem:

In the file methodhelpdesk.class.php - line: 670

It is validated that the user can assign tickets:

if (!$ticket->canAssign()) {
         return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED);
         $data['_groups_id_assign'] = 0;
}


The user post-only can't assign tickets.

The post-only user has a self-service profile, this profile does not have permissions to be able to assign tickets, therefore does not comply with the validation and throws the error:

xmlrpc error (16): Command not allowed

I am developing a mobile application, from this mobile application users with self-service profile should be able to create tickets.

From the GLPI web interface, users with a self-service profile can create tickets.

From an external mobile application that uses the methods of the GLPI plugin web services, users with a self-service profile can not create tickets.

Last edited by lexcorp (2017-07-06 07:06:47)

Offline

#3 2017-07-06 11:17:54

yllen
GLPI-DEV
From: Sillery (51)
Registered: 2008-01-14
Posts: 15,278

Re: Web Service | method:glpi.createTicket | xmlrpc error(16): Command not

This party is only to assign a ticket so you can't call create ticket with param groupassign
To create ticket you just need to have create right like in GLPI


CentOS 6.5 - CentOS 7.x
PHP 5.6 - PHP 7.x - MySQL 5.6  - MariaDB 10.2 + APC + oOPcache
GLPI from 0.72 to dev version
Certifiée ITIL (ITV2F, ITILF, ITILOSA)

Offline

#4 2017-07-06 14:09:43

lexcorp
Member
Registered: 2014-09-17
Posts: 64

Re: Web Service | method:glpi.createTicket | xmlrpc error(16): Command not

I am using the post-only user, this user has the Self-service profile that can create tickets. However, I continue to receive the error message: xmlrpc error (16): Command not allowed

If I use the tech user. With a Technician profile that can create tickets, I also get the error message: xmlrpc error (16): Command not allowed

If I use a user with a profile that can create and assign tickets for example Hotliner or admin or superadmin, it allows me to create the ticket without problems.

The detail is that most users will have Sel-service profile, which is the profile with which I can not create the ticket.

Greetings.

Offline

#5 2017-07-10 05:12:08

lexcorp
Member
Registered: 2014-09-17
Posts: 64

Re: Web Service | method:glpi.createTicket | xmlrpc error(16): Command not

To make this more interesting, I added a couple lines to this code: In the file methodhelpdesk.class.php - line: 670

if (!$ticket->canAssign()) {
        echo "You don't have Permission to Assign tickets, You can't create a ticket from web services...";
         return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED);
         $data['_groups_id_assign'] = 0;
      }else{
        echo "You have Permission to Assign tickets, Yessss!.. you can create a ticket from web services...";        
      }

And the result is: Usign a user with Self-service profile who can't assign tickets

+ Calling glpi.createTicket on http://192.168.1.86/glpi914/plugins/web … xmlrpc.php

You don't have Permission to Assign tickets, You can't create a ticket from web services...

faultCode 16 faultString Command not allowed + Bad response
---------------------------------------------------------------------------------------------------------------------------
Using a user with Hotliner profile who can assign tickets

+ Calling glpi.createTicket on http://192.168.1.86/glpi914/plugins/web … xmlrpc.php

You have Permission to Assign tickets, Yessss!.. you can create a ticket from web services...

id 14 entities_id 0 name test web service date 2017-07-09 22:03:50 closedate solvedate date_mod 2017-07-09 22:03:50 users_id_lastupdater 6 status 1 users_id_recipient 6 requesttypes_id 7 content This is a proof of ticket creation through web services urgency 3 impact 3 priority 3 itilcategories_id 2 type 1 solutiontypes_id 0 solution global_validation 1 slts_tto_id 0 slts_ttr_id 0 ttr_slalevels_id 0 due_date time_to_own begin_waiting_date sla_waiting_duration 0 waiting_duration 0 close_delay_stat 0 solve_delay_stat 0 takeintoaccount_delay_stat 0 actiontime 0 is_deleted 0 locations_id 0 validation_percent 0 date_creation 2017-07-09 22:03:50 items items_id 0 itemtype slalevels_next_id 0 slalevels_next_date users requester id 21 users_id 6 use_notification 1 alternative_email observer assign groups requester observer assign followups tasks documents events display_history 1 id 552 date_mod 2017-07-09 22:03 user_name hotliner (6) field change Añadir el elemento datatype display_history 1 id 551 date_mod 2017-07-09 22:03 user_name hotliner (6) field Usuario change Añadir un enlace con un elemento: hotliner (6) (Solicitante) datatype validations satisfaction suppliers assign + Bad response

Last edited by lexcorp (2017-07-10 05:14:09)

Offline

#6 2017-07-11 15:48:33

yllen
GLPI-DEV
From: Sillery (51)
Registered: 2008-01-14
Posts: 15,278

Re: Web Service | method:glpi.createTicket | xmlrpc error(16): Command not

how do you call the method (list of params)?


CentOS 6.5 - CentOS 7.x
PHP 5.6 - PHP 7.x - MySQL 5.6  - MariaDB 10.2 + APC + oOPcache
GLPI from 0.72 to dev version
Certifiée ITIL (ITV2F, ITILF, ITILOSA)

Offline

#7 2017-07-12 01:26:10

lexcorp
Member
Registered: 2014-09-17
Posts: 64

Re: Web Service | method:glpi.createTicket | xmlrpc error(16): Command not

Thank you very much for your help Nelly... I am using a PHP script with the following functions:

In the createTicket () function I'm passing this list of parameters:

       $ws_user = ""; //Web Service User in my config is blank
       $ws_pass = ""; //Web Service Password in my config is blank

       $session = "ovq4ec8k9r2r52f6dg5jmo9v64"; //Hashtable user session: post-only
       $type = 1; //Ticket type
       $category = 2; //Ticket Category
       $title = "pruebas web service"; //Title of ticket
       $content = "Esta es una prueba de creacion de tickets a traves de web services"; //Description of ticket

        $args['session'] = $session;
        $args['method'] = "glpi.createTicket";
        $args['type'] = $type;
        $args['category'] = $category;
        $args['title'] = $title;
        $args['content'] = $content;

        if (isset($ws_user)) {
            $args['username'] = $ws_user;
        }

        if (isset($ws_pass)) {
            $args['password'] = $ws_pass;
        }

This is complete PHP Script:

<?php
    //Check if xmlrpc php extension is loaded
    if (!extension_loaded("xmlrpc")) {
        die("Extension xmlrpc not loaded\n");
    }

    //Login user to GLPI - return a Hashtable session
    login();

    //Get ticket type - Incident or Request
    get_tickettype();

    //Get list of categories
    get_ticketcategory();

    //Create new ticket
    crear_ticket();

    function login() {

        global $glpi_user, $glpi_pass, $ws_user, $ws_pass;

        $glpi_user = "post-only";
        $glpi_pass = "postonly";
        $ws_user = "";
        $ws_pass = "";

        $args['method']          = "glpi.doLogin";
        $args['login_name']      = $glpi_user;
        $args['login_password']  = $glpi_pass;

        if (isset($ws_user)) {
            $args['username'] = $ws_user;
        }

        if (isset($ws_pass)) {
            $args['password'] = $ws_pass;
        }

        if ($result = call_glpi($args)) {
            //id of the user
            //name login
            //realname
            //firstname
            //session (this value must be send to other method to set the user context)

            //return $result['session'];
            echo  'ID: '.$result['id'];
            echo "<br>";
            echo  "Usuario: ".$result['name'];
            echo "<br>";
            echo  "Apellido: ".$result['realname'];
            echo "<br>";
            echo  "Nombre: ".$result['firstname'];
            echo "<br>";
            echo  "Hash: ".$result['session'];

            echo "<br>";

        }
        else{
            echo "Something's wrong, does not return anything...";
        }
    }

    function call_glpi($args) {
        global $host,$url,$deflate,$base64;

        $host = '192.168.1.86/glpi914';
        $url = "plugins/webservices/xmlrpc.php";


        // To avoid IDE warning
        $http_response_header = "Content-Type: text/xml";
        echo "+ Calling {$args['method']} on http://$host/$url\n";

        echo "<br>";

        if (isset($args['session'])) {
            $url_session = $url.'?session='.$args['session'];
        } else {
            $url_session = $url;
        }

        $header = "Content-Type: text/xml";

        if (isset($deflate)) {
            $header .= "\nAccept-Encoding: deflate";
        }

        if (isset($base64)) {
            $args['base64'] = $base64;
        }

        $request = xmlrpc_encode_request($args['method'], $args);
        $context = stream_context_create(array('http' => array('method'  => "POST",
                                                               'header'  => $header,
                                                               'content' => $request)));

        $file = file_get_contents("http://$host/$url_session", false, $context);
        if (!$file) {
            die("+ No response\n");
        }
        if (in_array('Content-Encoding: deflate', $http_response_header)) {
            $lenc = strlen($file);
            echo "+ Compressed response : $lenc\n";
            $file = gzuncompress($file);
            $lend = strlen($file);
            echo "+ Uncompressed response : $lend (".round(100.0*$lenc/$lend)."%)\n";
        }

        $response = xmlrpc_decode($file);
        if (!is_array($response)) {
            echo $file;
            die ("+ Bad response\n");
        }

        if (xmlrpc_is_fault($response)) {
            echo("xmlrpc error(".$response['faultCode']."): ".$response['faultString']."\n");
        } else {
            return $response;
        }
    }

    function get_tickettype() {

        global $session, $dropdown;

        $session = "ovq4ec8k9r2r52f6dg5jmo9v64";
        $dropdown = "TicketType";

        $args['session'] = $session;
        $args['method'] = "glpi.listDropdownValues";
        $args['dropdown'] = $dropdown;

        if ($result = call_glpi($args)) {
            //return $result;
            foreach($result as $resultado){
                print_r ($resultado);
            }
            echo "<br>";
        }
        else{
            echo "Something's wrong, does not return anything...";
        }
    }

    function get_ticketcategory() {

        global $session, $dropdown, $interfaz;

        $session = "ovq4ec8k9r2r52f6dg5jmo9v64";
        $dropdown = "ItilCategory";
        $interfaz = "helpdesk";

        $args['session'] = $session;
        $args['method'] = "glpi.listDropdownValues";
        $args['dropdown'] = $dropdown;

        if ($result = call_glpi($args)) {
            //return $result;
            foreach($result as $resultado){
                print_r ($resultado);
            }
            echo "<br>";

        }
        else{
            echo "Something's wrong, does not return anything...";
        }

    }

    function crear_ticket() {

        global $session, $type, $category, $title, $content, $ws_user, $ws_pass;

        $ws_user = "";
        $ws_pass = "";

        $session = "ovq4ec8k9r2r52f6dg5jmo9v64";
        $type = 1;
        $category = 2;
        $title = "pruebas web service";
        $content = "Esta es una prueba de creacion de tickets a traves de web services";

        $args['session'] = $session;
        $args['method'] = "glpi.createTicket";
        $args['type'] = $type;
        $args['category'] = $category;
        $args['title'] = $title;
        $args['content'] = $content;

        if (isset($ws_user)) {
            $args['username'] = $ws_user;
        }

        if (isset($ws_pass)) {
            $args['password'] = $ws_pass;
        }

        if ($result = call_glpi($args)) {
            //return $result;
            foreach($result as $resultado){
                print_r ($resultado);
            }

        }
        else{
            echo "Something's wrong, does not return anything...";
        }
    }

?>

Offline

Board footer

Powered by FluxBB