Create a task to a ticket in GLPI through API

830 Views Asked by At

This is the code I'm using. I'm getting a blank return string from the reader.ReadToEnd No errors

The function GetSessionCode gets the correct session-token cause it works in creating the ticket. Base URL = http://localhost/apirest.php/

The JSON I enter is:

{"input": {"task": {"name": "New task", "groups_id_tech": 0, "description": "create task test", "begin_date": "2023-09-04 14:32:53", "due_date": "2023-09-04 14:32:53", "taskcategories_id": 0, "users_id_tech": 11, "itemtype": "Ticket", "items_id": 24}}}

Ticket 24 exists
UsersID 11 also exists

Dim request As HttpWebRequest = DirectCast(WebRequest.Create(BaseURL & "Ticket/" & TicketID & "/ITILSolution"), HttpWebRequest)
        request.Method = "POST"
        request.Headers.Add("App-Token", AppToken)
        request.Headers.Add("Session-Token", GetSessionCode)
        request.ContentType = "application/json"
        Dim jsonBytes As Byte() = Encoding.UTF8.GetBytes(JsonString)
        Using requestStream As Stream = request.GetRequestStream()
            requestStream.Write(jsonBytes, 0, jsonBytes.Length)
        End Using
        Try
            Using response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
                Using reader As New StreamReader(response.GetResponseStream())
                    Return reader.ReadToEnd()
                End Using
            End Using
        Catch ex As WebException
            Return "ERROR"
        End Try

When I open the ticket in GLPI there is no task connected (visible). Please advise.

0

There are 0 best solutions below