Archive for julho, 2019

Add Document To GLPI thru API (PHP)

<?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;
}

?>

1 Comment more...

Associate Document To Ticket (Document_Item) thru GLPI Shell Example

#!/bin/sh

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/'


Add ticket to GLPI thru API (REST) with PHP Example

<?php

$ch = curl_init();

$fields='{"input": {"name": "Titulo ABCD","content": "Descricao 1234"}}';

curl_setopt($ch, CURLOPT_URL, 'http://localhost/glpi/apirest.php/Ticket/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Session-Token: 6c4f680e5581ca31008809b3236f6ac4';
$headers[] = 'App-Token: 7mvDUHjK21WB19banyJJNWTegjpEQlwslVODeOPJ';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);

var_dump($result);
?>


  • Publicidade

  • Redes Sociais

    Facebook  Twitter
  • Estatísticas

    Page Views (desde março de 2010):

    Estatísticas detalhadas
  • Novidades por e-mail!

    Digite seu e-mail:


    Fique tranquilo. Seu e-mail não será usado para outros fins, e você poderá se descadastrar quando quizer.

    Eu!

    Tiago Passos
    Todo o conteúdo desse site esta licenciado sob a licença Creative Commons 3.0 (CC BY 3.0). Você pode copiar e modificar o conteúdo desde que cite o autor.
    iDream theme by Templates Next | Powered by WordPress