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 2020-01-15 14:11:27

wtralui
Member
Registered: 2019-12-07
Posts: 25

Open Call With Assigned Document ~ API Rest

Is there any way to open an automatic ticket (via script / API rest) with a document already assigned to it?

Offline

#2 2020-01-15 21:37:23

mecmav
Member
From: Brasil
Registered: 2019-03-22
Posts: 326

Re: Open Call With Assigned Document ~ API Rest

wtralui wrote:

Is there any way to open an automatic ticket (via script / API rest) with a document already assigned to it?

It's a good question.

I think you need first open ticket to generate an ID, after with this ID you can make the relationship with an any document.

The relation of the document with the ticket must be done after the ticket opened.

I'm not sure about it, but the devs of GLPI can answer that with more precision.

Offline

#3 2020-01-16 14:59:18

wtralui
Member
Registered: 2019-12-07
Posts: 25

Re: Open Call With Assigned Document ~ API Rest

mecmav wrote:
wtralui wrote:

Is there any way to open an automatic ticket (via script / API rest) with a document already assigned to it?

It's a good question.

I think you need first open ticket to generate an ID, after with this ID you can make the relationship with an any document.

The relation of the document with the ticket must be done after the ticket opened.

I'm not sure about it, but the devs of GLPI can answer that with more precision.


Greetings.

So friend, I already have a script that opens the ticket completely, generating me the ID and etc .. I have also made a script in which uploads the file on the GLPI server, the problem is that I am unable to associate ( via script) the document to the open ticket

Some references that I followed but I was not successful:

curl -X POST \
-H 'Content-Type: application/json' \
-H "Session-Token: bvb01r0anhqe4vqrtft2du4lh1" \
-H "App-Token: jYPzF6c9j9pTDBdZXwIBsGxzoGhoWyef4wXUAsr2" \
-d '{"input": {"itemtype": "Ticket", "documents_id": "31", "items_id": "4"}}' \
'http://localhost/glpi/apirest.php/Document_Item/'

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

<?php

    $sessiontoken = "k7uhook39qa4abb0naot8p25r4";
    $url = "localhost/glpi";
    $apptoken = "jYPzF6c9j9pTDBdZXwIBsGxzoGhoWyef4wXUAsr2";
    $filename = "/tmp/image4.png";

$file = file_get_contents($filename);
 
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "http://".$url."/apirest.php/Document/",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "——WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name=\"uploadManifest\"
 
{\"input\": {\"tickets_id\": \"4\",\"name\": \"01Chamado 1234567bc\", \"_filename\" : [\”$filename\”]}}
——WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: multipart/form-data; name=\"ab\"; filename=\"$filename\";
Content-Type: image/png;
 
$file
——WebKitFormBoundary7MA4YWxkTrZu0gW–",
  CURLOPT_HTTPHEADER => array(
    "app-token: $apptoken",
    "cache-control: no-cache",
    "content-type: multipart/form-data; boundary=—-WebKitFormBoundary7MA4YWxkTrZu0gW",
    "postman-token: 3cc7a7f0-2f01-36dc-8ccc-a8b263d2e26c",
    "session-token: $sessiontoken"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

?>

Offline

#4 2020-01-16 15:21:26

mecmav
Member
From: Brasil
Registered: 2019-03-22
Posts: 326

Re: Open Call With Assigned Document ~ API Rest

wtralui wrote:
mecmav wrote:
wtralui wrote:

Is there any way to open an automatic ticket (via script / API rest) with a document already assigned to it?

It's a good question.

I think you need first open ticket to generate an ID, after with this ID you can make the relationship with an any document.

The relation of the document with the ticket must be done after the ticket opened.

I'm not sure about it, but the devs of GLPI can answer that with more precision.


Greetings.

So friend, I already have a script that opens the ticket completely, generating me the ID and etc .. I have also made a script in which uploads the file on the GLPI server, the problem is that I am unable to associate ( via script) the document to the open ticket

Some references that I followed but I was not successful:

curl -X POST \
-H 'Content-Type: application/json' \
-H "Session-Token: sess_token" \
-H "App-Token: app-token" \
-d '{"input": {"itemtype": "Ticket", "documents_id": "31", "items_id": "4"}}' \
'http://localhost/glpi/apirest.php/Document_Item/'

your input need an user which will make the insertion by using "users_id": "id of a user"

next time you need hide your values <--

I can see you have a bad URL. To make a relation between document and ticket you need this URL http://IP-GLPI/apirest.php/Document/1/Document_Item/

where "1" after slashes can be any number (I don't know why, but works). This URL it's to do the relationship.

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

<?php

    $sessiontoken = "sess_token";
    $url = "localhost/glpi";
    $apptoken = "app-token";
    $filename = "/tmp/image4.png";

$file = file_get_contents($filename);
 
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "http://".$url."/apirest.php/Document/",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "——WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name=\"uploadManifest\"
 
{\"input\": {\"tickets_id\": \"4\",\"name\": \"01Chamado 1234567bc\", \"_filename\" : [\”$filename\”]}}
——WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: multipart/form-data; name=\"ab\"; filename=\"$filename\";
Content-Type: image/png;
 
$file
——WebKitFormBoundary7MA4YWxkTrZu0gW–",
  CURLOPT_HTTPHEADER => array(
    "app-token: $apptoken",
    "cache-control: no-cache",
    "content-type: multipart/form-data; boundary=—-WebKitFormBoundary7MA4YWxkTrZu0gW",
    "postman-token: 3cc7a7f0-2f01-36dc-8ccc-a8b263d2e26c",
    "session-token: $sessiontoken"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

?>

Did you try make this tests first by Postman ?
After things works, you can put in a script to make the dirty work.

Last edited by mecmav (2020-01-16 15:24:18)

Offline

Board footer

Powered by FluxBB