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-25 09:49:35

headquaker
Member
Registered: 2015-03-23
Posts: 40

[SOLVED][BY ME AS USUAL]GLPI - Ticket Creation Help

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

#2 2019-10-25 10:33:07

headquaker
Member
Registered: 2015-03-23
Posts: 40

Re: [SOLVED][BY ME AS USUAL]GLPI - Ticket Creation Help

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

#3 2019-10-25 10:37:23

headquaker
Member
Registered: 2015-03-23
Posts: 40

Re: [SOLVED][BY ME AS USUAL]GLPI - Ticket Creation Help

Now I am looking for the field to put a requester

Offline

#4 2019-10-25 10:42:54

LaDenrée
HELPER
Registered: 2012-11-19
Posts: 6,146

Re: [SOLVED][BY ME AS USUAL]GLPI - Ticket Creation Help

"_users_id_requester": $users_id.


Trouver la panne avant de réparer...
GLPI10.0.10 (ubuntu 22.04 PHP8.1  Mariadb10.6 ) plugins : comportements 2.7.2 reports 1.16.0 formcreator 2.13.8, datainjection 2.13.4 fields 1.21.6

Offline

#5 2019-10-25 10:57:07

headquaker
Member
Registered: 2015-03-23
Posts: 40

Re: [SOLVED][BY ME AS USUAL]GLPI - Ticket Creation Help

Yes I find it thanks but can I change the $users_id ?

Offline

#6 2019-10-25 11:59:41

headquaker
Member
Registered: 2015-03-23
Posts: 40

Re: [SOLVED][BY ME AS USUAL]GLPI - Ticket Creation Help

Is it possible to use a ticket template for creation?

Offline

#7 2019-10-25 12:59:14

headquaker
Member
Registered: 2015-03-23
Posts: 40

Re: [SOLVED][BY ME AS USUAL]GLPI - Ticket Creation Help

LaDenrée wrote:

"_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

#8 2019-10-25 13:16:39

headquaker
Member
Registered: 2015-03-23
Posts: 40

Re: [SOLVED][BY ME AS USUAL]GLPI - Ticket Creation Help

Arf thats Ok, it was not working because I would like to add a group and not a user -_-

Offline

#9 2019-10-25 15:52:53

headquaker
Member
Registered: 2015-03-23
Posts: 40

Re: [SOLVED][BY ME AS USUAL]GLPI - Ticket Creation Help

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

#10 2019-10-25 16:00:41

headquaker
Member
Registered: 2015-03-23
Posts: 40

Re: [SOLVED][BY ME AS USUAL]GLPI - Ticket Creation Help

I would like to use a variable like this : CH - Hunenberg - Disponibilité WAN (x.x.x.x)

Offline

#11 2019-10-29 10:41:55

headquaker
Member
Registered: 2015-03-23
Posts: 40

Re: [SOLVED][BY ME AS USUAL]GLPI - Ticket Creation Help

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

#12 2019-12-08 15:37:15

wtralui
Member
Registered: 2019-12-07
Posts: 25

Re: [SOLVED][BY ME AS USUAL]GLPI - Ticket Creation Help

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

#13 2021-03-21 04:35:24

mkdalmam
Member
Registered: 2021-03-21
Posts: 9

Re: [SOLVED][BY ME AS USUAL]GLPI - Ticket Creation Help

Hello, I am also wanting to do what you reported. You can indicate how you solved it.
I'm waiting.
Thanks

Offline

#14 2021-04-16 17:19:30

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

Re: [SOLVED][BY ME AS USUAL]GLPI - Ticket Creation Help

What you trying to do ?

Offline

#15 2021-04-30 16:18:07

mkdalmam
Member
Registered: 2021-03-21
Posts: 9

Re: [SOLVED][BY ME AS USUAL]GLPI - Ticket Creation Help

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

#16 2022-06-30 10:34:28

ila
Member
Registered: 2022-03-10
Posts: 11

Re: [SOLVED][BY ME AS USUAL]GLPI - Ticket Creation Help

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

#17 2023-01-27 12:53:21

headquaker
Member
Registered: 2015-03-23
Posts: 40

Re: [SOLVED][BY ME AS USUAL]GLPI - Ticket Creation Help

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

#18 2023-01-27 16:11:00

headquaker
Member
Registered: 2015-03-23
Posts: 40

Re: [SOLVED][BY ME AS USUAL]GLPI - Ticket Creation Help

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

#19 2023-01-27 18:19:20

headquaker
Member
Registered: 2015-03-23
Posts: 40

Re: [SOLVED][BY ME AS USUAL]GLPI - Ticket Creation Help

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 smile

Last edited by headquaker (2023-02-01 17:40:42)

Offline

Board footer

Powered by FluxBB