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 2024-07-03 20:21:23

leanBorre
Member
Registered: 2024-07-03
Posts: 1

Associate Ticket to a Computer or Vice Versa

Hi everyone,

I'm having a little bit of trouble with associating a computer to a ticket, al done by the API calls. I'm able to create the ticket. But when it comes to associating it to a computer, when i go and check on GLPI not element/item is associated in that ticket. here is how I'm doing it (I'm using the REST client extension on VSCode to make the http calls)

### POST New Ticket associated with the logged user
# @name ticket
POST {{base_url}}/Ticket
Content-Type: application/json
App-Token: {{app_token}}
session-token: {{session_token}}

{
    "input": {
        "name": "Ingreso",
        "content": "Ingreso 123",
        "type": 1,
        "urgency": 2,
        "impact": 2,
        "priority": 2,
        "itilcategories_id": 1,
        "_users_id_requester": {{glpie_user_id}},
    }
}

#response:
HTTP/1.1 201 Created
Date: Wed, 03 Jul 2024 18:11:00 GMT
Content-Type: application/json; charset=UTF-8
Transfer-Encoding: chunked
Connection: close
Server: nginx/1.18.0 (Ubuntu)
Pragma: no-cache
location:{{base_url}}/apirest.php/Ticket/23
Cache-Control: no-store, no-cache, must-revalidate
Expires: Mon, 26 Jul 1997 05:00:00 GMT

{
  "id": 23,
  "message": "Elemento agregado exitosamente: Ingreso (23)"
}

#message is in spanish, saying it succesfully created the Ticket with title "Ingreso" and ID 23

And when i try to associate the computer to the just created ticket i get nothing.

#HTTP Request
POST {{base_url}}/Ticket/{{ticket_id}}/Item_Ticket
Content-Type: application/json
App-Token: {{app_token}}
session-token: {{session_token}}

{
  "input": {
    "items_id": {{item_id}},
    "itemtype": "Computadoras",
    "tikets_id": {{ticket_id}}
  }
}
#"Computadoras" is spanish for Computer (also tried with Computers and got the same result.

#response:

HTTP/1.1 200 OK
Date: Wed, 03 Jul 2024 18:14:11 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: close
Server: nginx/1.18.0 (Ubuntu)
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Content-Encoding: gzip

Although it seems like the response is ok becouse i get a 200 OK. no associated computer is linked on the ticket in GLPI, and also if the association is correct i should get a response body alongside the 200 OK and header messages.

Any insight on this would be very helpfull.

PD. i also tried to associate a Ticket to a computer, creating the ticket such as shown before, but using the url to the association as from the Computer and not the ticket
e.g.:
POST {{base_url}}/Computer/{{item_id}}/Item_Ticket
Content-Type: application/json
App-Token: {{app_token}}
session-token: {{session_token}}

{
  "input": {
    "items_id": {{item_id}},
    "itemtype": "Computadoras",
    "tikets_id": {{ticket_id}}
  }
}

# response

HTTP/1.1 400 Bad Request
Date: Wed, 03 Jul 2024 18:18:32 GMT
Content-Type: application/json; charset=UTF-8
Transfer-Encoding: chunked
Connection: close
Server: nginx/1.18.0 (Ubuntu)
Pragma: no-cache
Cache-Control: no-store, no-cache, must-revalidate
Expires: Mon, 26 Jul 1997 05:00:00 GMT

[
  "ERROR_GLPI_ADD",
  "Duplicate entry 'Computadoras-953-0' for key 'glpi_items_tickets.unicity'"
]

Offline

#2 2024-07-04 02:30:13

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

Re: Associate Ticket to a Computer or Vice Versa

The computer itemtype is "Computer". It has to match the internal PHP class name exactly (english and case-sensitive), not the localized name.


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

Board footer

Powered by FluxBB