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 2023-12-04 16:50:55

Pullastri
Member
Registered: 2023-11-27
Posts: 2

How can i relate a document with a ticket?

I've tried everything i've find in this forum. Everything keeps failing :(

I need to view the attached documents like tickets opened via mail show.

API call:

https://URL/glpi/apirest.php/Ticket/10006/Document
uploadManifest: "input": {"items_id": "10006", "itemtype" : "Ticket", "id": "5000"}
App-token: xx
sess-token: xx

Thanks in advance

Offline

#2 2023-12-05 01:50:08

cconard96
Moderator
Registered: 2018-07-31
Posts: 2,424
Website

Re: How can i relate a document with a ticket?

In general, the steps are:
1. Create the document itself from a file at "/Document"
2. Create the link at "/Document_Item" with:
    - itemtype: Ticket
    - items_id: {ticket_id}
    - documents_id: {document_id}

Trying to create a Document at "/Ticket/{id}/Document" doesn't actually create the document and link it to the ticket.


GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.

Offline

#3 2023-12-05 16:30:17

Pullastri
Member
Registered: 2023-11-27
Posts: 2

Re: How can i relate a document with a ticket?

Thanks for answering cconrad,

You made me go to the right path!

Your answer is nearly perfect, but in my case I had to do a bit more of researching.

For anyone in the future, here's my approach:

API call: https://<your-glpi-url>/glpi/apirest.php/Document_Item/

Headers:
Session-Token:xxx
App-Token:xxx
Content-Type:application/json

Body:
{
  "input": {
    "items_id": "9955",
    "itemtype": "Ticket",
    "documents_id": "5064",
    "add": "Add"
  }
}


Javascript function:

  async function assignDocToTicket(sessionToken, ticketId, documentId) {
    const uploadManifest = {
      input: {
        items_id: ticketId,
        itemtype: "Ticket",
        documents_id: documentId,
        add: "Add"   
      }
    };
 
    const url = `https://<your-glpi-url>/glpi/apirest.php/Document_Item/`;
 
    try {
      const response = await axios.post(url, uploadManifest, {
        headers: {
          'Content-Type': 'application/json',
          'Session-Token': sessionToken,
          'App-Token': process.env.APP_TOKEN
        }
      });
 
      console.log('assignDocToTicket response:', response.data);
    } catch (error) {
      console.error('Error al asignar documento al ticket:', error);
    }
  }

Offline

Board footer

Powered by FluxBB