You are not logged in.
Hello,
I am asking you because I am fed up to search how to do it.
I just want to create a ticket in GLPI using the REST API.
I can initsession but after that, when I am testing a ticket creation, the request seems OK but no ticket is created.
curl -X POST -H 'Content-Type: application/json' -H "Session-Token: xxxxxxxx" -H "App-Token: yyyyyyyyyy" -d '{"input": {"name": "Ticket Name", "content": "Ticket Desc","status":"1","urgency":"1","_disablenotif":true}}' 'http://glpiserver/apirest.php/itilsolution/'
GLPI : 9.4.4
Another question is : how can I find all the field I can use in the request.
I've read the documentation but nothing is talking about that.
Thank you !
SOLUTIONS
Ok for those who needs help :
In powershell :
# GLPI REST API CONFIG :
$AppURL = "http://server/apirest.php/"
$UserToken = "xxxxxxxxx"
$AppToken = "yyyyyyyyy"
$createUrl = "http://server/apirest.php/Ticket"
# session creation
$SessionToken = Invoke-RestMethod "$AppURL/initSession" -Method Get -Headers @{"Content-Type" = "application/json";"Authorization" = "user_token $UserToken";"App-Token"=$AppToken}
# Things to do
$data = @{
"input" = @(
@{
"content" = "Ticket description"
"name" = "Depart Salarie"
"_groups_id_requester" = "1"
"priority" = "4"
"urgency" = "2"
"status" = "1"
"impact" = "3"
}
)
}
$json = $data | ConvertTo-Json
Invoke-RestMethod -Method POST -Uri $createUrl -Headers @{"session-token"=$SessionToken.session_token; "App-Token" = "$AppToken"} -Body $json -ContentType 'application/json'
# Kill of the session
Invoke-RestMethod "$AppURL/killSession" -Headers @{"session-token"=$SessionToken.session_token; "App-Token" = "$AppToken"}
In PS, the json has to be like this :
{
"input": [
{
"content": "Ticket description",
"name": "Depart Salarie",
"_groups_id_requester": "1",
"priority": "4",
"impact": "3",
"urgency": "2",
"status": "1"
}
]
}
####################################
LINUX :
#!/bin/bash
APISESSION=$(curl -s -X GET -H 'Content-Type: application/json' -H "Authorization: user_token: XXXXXXXXX" -H "App-Token: YYYYYYYYY" 'http://SERVER/glpi/apirest.php/initSession' | grep -o -P '(?<=:").*(?=")')
EVENTNAME=$1
TRIGGERSEVERITY=$2
case $2 in
Disaster)
PRIORITY=5
;;
Critical)
PRIORITY=4
;;
High)
PRIORITY=3
;;
esac
curl -H POST \
'http://SERVER/glpi/apirest.php//Ticket/' \
-H 'App-Token: YYYYYYYYY' \
-H 'Content-Type: application/json' \
-H 'Cookie: glpi_token' \
-H 'Host: localhost' \
-H 'Session-Token: '${APISESSION}'' \
-d '{
"input": {
"name": "'"${EVENTNAME}"' (Zabbix)",
"content": "'"${EVENTNAME}"' - Severity :'"${TRIGGERSEVERITY}"'",
"status":"1",
"urgency":"1",
"priority":"'"${PRIORITY}"'",
"_groups_id_requester":"1"
}
}'
curl -X GET \
-H 'Content-Type: application/json' \
-H 'Session-Token: '${APISESSION}'' \
-H "App-Token: YYYYYYYYY" \
'http://SERVER/glpi/apirest.php/killSession'
Last edited by headquaker (2023-01-27 18:22:36)
Offline
While I found it:
curl -X POST -H 'Content-Type: application/json' -H "Session-Token: xxxxxxxx" -H "App-Token: yyyyyyyyyy" -d '{"input": {"name": "Ticket Name", "content": "Ticket Desc","status":"1","urgency":"1"}}' 'http://glpiserver/apirest.php/Ticket/'
Offline
Now I am looking for the field to put a requester
Offline
"_users_id_requester": $users_id.
Trouver la panne avant de réparer...
GLPI10.0.16 (ubuntu 22.04 PHP8.1 Mariadb10.6 ) plugins : comportements 2.7.3 reports 1.16.0 formcreator 2.13.9, datainjection 2.13.5 fields 1.21.9
Offline
Yes I find it thanks but can I change the $users_id ?
Offline
Is it possible to use a ticket template for creation?
Offline
"_users_id_requester": $users_id.
I do not know how to use that, it is not working when I try this :
curl -X POST -H 'Content-Type: application/json' -H "Session-Token: xxxxxxxx" -H "App-Token: yyyyyyyyyy" -d '{"input": {"name": "Ticket Name", "content": "Ticket Desc","status":"1","urgency":"1","_users_id_requester":"1"}}' 'http://glpiserver/apirest.php/Ticket/'
Offline
Arf thats Ok, it was not working because I would like to add a group and not a user -_-
Offline
How to use variables with space and others things into the curl commande because this is not working ..."name": $1,...
Got the error : ["ERROR_JSON_PAYLOAD_INVALID","JSON payload seems not valid"]
Offline
I would like to use a variable like this : CH - Hunenberg - Disponibilité WAN (x.x.x.x)
Offline
Bon voici mon script complet pour aider ceux qui ont du mal
#!/bin/bash
APISESSION=$(curl -s -X GET -H 'Content-Type: application/json' -H "Authorization: user_token: XXXXXXXXX" -H "App-Token: YYYYYYYYY" 'http://SERVER/glpi/apirest.php/initSession' | grep -o -P '(?<=:").*(?=")')
EVENTNAME=$1
TRIGGERSEVERITY=$2
case $2 in
Disaster)
PRIORITY=5
;;
Critical)
PRIORITY=4
;;
High)
PRIORITY=3
;;
esac
curl -H POST \
'http://SERVER/glpi/apirest.php//Ticket/' \
-H 'App-Token: YYYYYYYYY' \
-H 'Content-Type: application/json' \
-H 'Cookie: glpi_token' \
-H 'Host: localhost' \
-H 'Session-Token: '${APISESSION}'' \
-d '{
"input": {
"name": "'"${EVENTNAME}"' (Zabbix)",
"content": "'"${EVENTNAME}"' - Severity :'"${TRIGGERSEVERITY}"'",
"status":"1",
"urgency":"1",
"priority":"'"${PRIORITY}"'",
"_groups_id_requester":"1"
}
}'
curl -X GET \
-H 'Content-Type: application/json' \
-H 'Session-Token: '${APISESSION}'' \
-H "App-Token: YYYYYYYYY" \
'http://SERVER/glpi/apirest.php/killSession'
Offline
Hi bro,
Could you contact me in any way?
Have you been able to troubleshoot your script issue? I have the same idea of wanting to create a
Offline
Hello, I am also wanting to do what you reported. You can indicate how you solved it.
I'm waiting.
Thanks
Offline
What you trying to do ?
Offline
Hi mecmav,
I am looking to use the API to create tickets.
TYPE:
I need the API to provide data for creating tickets.
I do not know where to start.
Thanks
Offline
Hi
I try to create a ticket using API but the response is code 200 without a body. (response: <Response [200]>)
i have no problem to update ticket, get ticket, and search ticket but suddenly i got error when create ticket because the request doesn't return a body
I have checked the ticket is created on the glpi but the request not return anything, it is supposed to return the ticket id i just posted
Does anyone know why is that happen?
Thanks
Last edited by ila (2022-06-30 10:38:53)
Offline
sorry i don't have any idea, glpi,zabbix all thoses products just lacks of help and informations that are precise.
There are plenty of documentation but when it comes to test, it never works...
My code abose is an example to create a ticket but in curl... I am trying to convert it in powershell
Last edited by headquaker (2023-01-27 12:58:38)
Offline
Why i get that ffs error !
Invoke-RestMethod : ["ERROR_BAD_ARRAY","Le paramètre input doit être un tableau d'objets; Afficher la documentation dans votre navigateur à
["ERROR_BAD_ARRAY","The input parameter must be an array of objects
JSON :
{
"input": {
"content": "Ticket description",
"name": "Depart Salarie",
"_groups_id_requester": "1",
"priority": "4",
"urgency": "2",
"status": "1",
"impact": "3"
}
}
Code :
# GLPI REST API CONFIG :
$AppURL = "http://server/apirest.php/"
$UserToken = "xxxxxxxxxx"
$AppToken = "yyyyyyyyyy"
$createUrl = "http://server/apirest.php/Ticket/"
# session creation
$SessionToken = Invoke-RestMethod "$AppURL/initSession" -Method Get -Headers @{"Content-Type" = "application/json";"Authorization" = "user_token $UserToken";"App-Token"=$AppToken}
# Things to do
#$SearchResult = Invoke-RestMethod "$AppURL/Computer/" -Headers @{"session-token"=$SessionToken.session_token; "App-Token" = "$AppToken"}
#$SearchResult | ft -AutoSize -Wrap | ft -AutoSize -Wrap
$jsonBase = @{}
$array = @{}
$data = @{
"name" = "Depart Salarie"
"content" = "Ticket description"
"status" = "1"
"urgency" = "2"
"impact" = "3"
"priority" = "4"
"_groups_id_requester" = "1"
}
$jsonBase.Add("input",$data)
$ticketData = $jsonBase | ConvertTo-Json
$createResult = Invoke-RestMethod -Method POST -Uri $createUrl -Headers @{"session-token"=$SessionToken.session_token; "App-Token" = "$AppToken"} -Body ($ticketData)
# Kill of the session
Invoke-RestMethod "$AppURL/killSession" -Headers @{"session-token"=$SessionToken.session_token; "App-Token" = "$AppToken"}
Last edited by headquaker (2023-01-27 16:12:12)
Offline
Ok for those who needs help :
In powershell :
# GLPI REST API CONFIG :
$AppURL = "http://server/apirest.php/"
$UserToken = "xxxxxxxxx"
$AppToken = "yyyyyyyyy"
$createUrl = "http://server/apirest.php/Ticket"
# session creation
$SessionToken = Invoke-RestMethod "$AppURL/initSession" -Method Get -Headers @{"Content-Type" = "application/json";"Authorization" = "user_token $UserToken";"App-Token"=$AppToken}
# Things to do
$data = @{
"input" = @(
@{
"content" = "Ticket description"
"name" = "Depart Salarie"
"_groups_id_requester" = "1"
"priority" = "4"
"urgency" = "2"
"status" = "1"
"impact" = "3"
}
)
}
$json = $data | ConvertTo-Json
Invoke-RestMethod -Method POST -Uri $createUrl -Headers @{"session-token"=$SessionToken.session_token; "App-Token" = "$AppToken"} -Body $json -ContentType 'application/json'
# Kill of the session
Invoke-RestMethod "$AppURL/killSession" -Headers @{"session-token"=$SessionToken.session_token; "App-Token" = "$AppToken"}
In PS, the json has to be like this :
{
"input": [
{
"content": "Ticket description",
"name": "Depart Salarie",
"_groups_id_requester": "1",
"priority": "4",
"impact": "3",
"urgency": "2",
"status": "1"
}
]
}
If I don't need anything, I'll ask you
Last edited by headquaker (2023-02-01 17:40:42)
Offline