You are not logged in.
Pages: 1
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
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
Somebody can explain this to me ?
Offline
Anyone?
I'm with this doubt yet
Offline
У меня получилось. Не уверен, что еще актуально, но вдруг кто-то еще попадет на эту страницу в поисках решения как я.
Решение на 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
Pages: 1