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-10-29 15:53:51

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

Make relation of document to a ticket

I read these topics https://forum.glpi-project.org/viewtopic.php?id=170101 and this https://forum.glpi-project.org/viewtopic.php?id=156404.
These topics are about relationing computer and items from knowbase.

I need help for that:
Case example:

I have a ticket in GLPI created by user. That ticket contain an any ID. Next step it's add a document (uploaded by API), and it's generated on Management>Documents with an ID. Until here, all fine.

Now, what I need is, by API, make a relation between the document uploaded (in this case ID = 13) with the ticket (ID = 400).

I am confused to understand if a php script will be needed or if everything will be done natively by the API.

How to do that?

Offline

#2 2019-10-30 00:14:30

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

Re: Make relation of document to a ticket

I did what I needed.
To do I needed to use the glpi_documents_items table.

To do only need Run a first request on Postman, resulting the insert file in glpi. For now, I have an generated ID in the glpi_document table.

Now we need to run a second request to make the relation id of the resulting first request with id of the ticket.

yourglpi / apirest.php / Document / 1 / Document_Item /

{
"input": {
"documents_id": "id",       // change "id" for the corresponding number id of the document in the table glpi_documents
"items_id": "id",              // id of the item, for table that you use at select itemtype
"itemtype": "Ticket",       // can be a ticket, or computer, any object
"entities_id": "0",           // id of corresponding entity that I want to insert
"users_id": ""                // id of the user that will display in the GLPI GUI
}
}

But I can't understand one thing: Why I can insert correct file in the glpi using any ID in the URL yourglpi / apirest.php / Document / 1 / Document_Item / ??

If I replace the value 1 instead 2 or 3 (any value) after "/ Document /", the request is executed normally. Even if I don't have the ID that we entered.

Why this happens ??

Anyone?

Offline

#3 2019-10-31 19:55:22

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

Re: Make relation of document to a ticket

Somebody can explain this to me ?

Offline

#4 2019-11-14 21:51:07

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

Re: Make relation of document to a ticket

Anyone?
I'm with this doubt yet

Offline

#5 2022-02-19 17:47:03

russian_bigboss
Member
Registered: 2022-02-19
Posts: 1

Re: Make relation of document to a ticket

У меня получилось. Не уверен, что еще актуально, но вдруг кто-то еще попадет на эту страницу в поисках решения как я.
Решение на javascript такое:

// javascript solution
function assignDocToTicket (sessToken = '<key>', ticketId = 7, documentId = 16) {
    var uploadManifest = {
        input: {
            items_id: ticketId,
            itemtype: "Ticket",
            id: documentId
        }
    }
    var xhr = new XMLHttpRequest(); 
    xhr.addEventListener("readystatechange", function() {
      if(this.readyState === 4) {
        console.log('assignDocToTicket responseText = ', this.responseText);
      }
    });
    var url = "/Ticket/" + documentId + "/Document";
    xhr.open("POST", "http://<glpi address(ip or domain name)>/apirest.php" + url, true);
    xhr.setRequestHeader("Session-Token", sessToken);
    xhr.setRequestHeader("Content-Type", 'application/json');
    xhr.send(JSON.stringify(uploadManifest));
}
assignDocToTicket();

Offline

Board footer

Powered by FluxBB