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 2019-12-16 10:37:01

Drumhazzard
Member
Registered: 2011-09-19
Posts: 47

Use Rest API for Upload a Document and Attatch to Ticket

Hi All!!

I'm happy for quering again here hehehe

I need the wisdom of the GLPI wise council wink

I'm triying to make a PHP script that upload a and attatch it to a ticket, but after read some post I have the conclusion that there is no way using the API to upload a document to GLPI.

I have read about people who use other tools to do it.

Is that so? Is there NO way to build a call with curl, for example to do so?

I'm trying something like this:

###########################################################

$headers = glpi_api_sessionStart($site_url,$user_token,$app_token,'a');
   
    $request->tickets_id = $ticket_id;
        $request->name = $nombre;
        $request->filename = $nombre;
        $request->filepath = $path_documento;
       
        $input->input = $request;
   
    $jsonInput = json_encode($input);

###########################################################

The function glpi_api_sessionStart:

###########################################################

function glpi_api_sessionStart($site_url,$user_token,$app_token,$type) {
        $ch = curl_init();
                $url=$site_url . "/initSession?Content-Type=%20application/json&app_token=".$app_token ."&user_token=".$user_token;
                curl_setopt($ch, CURLOPT_URL,$url);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                $json = curl_exec($ch);
        curl_close ($ch);
        $obj = json_decode($json,true);
        $sess_token = $obj['session_token'];

        if ($type == 'a') {
                $headers =array(
                        'Content-Type: multipart/form-data',
                        'App-Token: ' .$app_token,
                        'Session-Token: '.$sess_token,
                        'Accept: application/json'
                );
        } else {
                $headers =array(
                        'Content-Type: application/json',
                        'App-Token: ' .$app_token,
                        'Session-Token: '.$sess_token
                );
        }
        return $headers;
}

###########################################################

When I try to do this, I receive:

["ERROR_UPLOAD_FILE_TOO_BIG_POST_MAX_SIZE","The file seems too big"]

20191216-0833:DEBUG:Variables Recibidas: Ticket_ID: 105949 Path_Documento: docs/image007.jpg Nombre: image007.jpg <--- THIS IS A DEBUG LINE FOR ME, TO CHECK THE VARIABLES

But this is a generic error, the post_max_size in php.ini and other sites it's too much greater than the size of the file I'm tried to upload.

Thanks all for your assistance

Offline

Board footer

Powered by FluxBB