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 2018-09-02 18:19:40

jaisinghotra
Member
Registered: 2018-09-02
Posts: 1

Create a ticket using python requests any help?

Hi guys, I'm tryung to create a ticket in GLPI, using python requests. My code:

from glpi import GLPI
import requests
url = 'https://hd.integrasky.ru/apirest.php/initSession'
auth = ('username', 'password')
headers = {'App-Token': 'token',
           'Content-Type': 'application/json'}
requests.get(url, auth=auth, headers=headers)
payload = {'input': {'name': 'Проблема', 'content': 'Не работает компьютер', 'entities_id': 29}}
requests.post('http://hd.integrasky.ru/apirest.php/Ticket', json=payload)

But the ticket is not creating, and there is no exception in my script.

Process finished with exit code 0

What I'm doing wrong? Someone can help me?
And should I use encoding to utf-8 to russian text?

Offline

#2 2018-09-06 10:22:15

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

Re: Create a ticket using python requests any help?

initsession should return a session_token.

add this session_token to headers to call other endpoints  ( .../Ticket)


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

#3 2019-03-26 11:43:32

drainlife
Member
Registered: 2019-03-26
Posts: 1

Re: Create a ticket using python requests any help?

Any news? ^^

Offline

#4 2020-12-19 14:25:06

rsilcas
Member
Registered: 2020-12-19
Posts: 1

Re: Create a ticket using python requests any help?

hi

in this code:
--------------------------------
from glpi import GLPI
import requests
url = 'SITE/apirest.php/initSession'
auth = ('username', 'password')
headers = {'App-Token': 'token',
           'Content-Type': 'application/json'}
requests.get(url, auth=auth, headers=headers)  #this GET is when you obtain the token, but you are losing the token, you need to save in a STRING to use in the next line in a HEADER of the POST
----------------------------------------------------


in this line you need to add the token of the last line
----------------------------------------------------
requests.post('http://SITE/apirest.php/Ticket', json=payload)
----------------------------------------------------

i am in this code in this moment, if i win, i will show you

Offline

Board footer

Powered by FluxBB