How to create OTRS Ticket +Article with HTTP Request

1.7k Views Asked by At

I'm not very familiar with PERL and can't translate API documentation into a valid request.

Can you help me?

Documentation of TicketCreate: https://doc.otrs.com/doc/api/otrs/8.0/Perl/Kernel/GenericInterface/Operation/Ticket/TicketCreate.pm.html

The request body is probably correct.

I just couldn't interpret how to format the URL.

{
  "UserLogin": "test",

  "Password": "test",

  "Ticket" : 
  {
    "Title": "test",
    "Queue": "test",
    "Lock": "test",
    "Type": "test",
    "State": "test",
    "Priority": "test",
    "Owner": "test",
    "CustomerUser": "test"
  },

  "Article":
  {
    "Subject" : "test",
    "Body" : "test",
    "ContentType": "text/plain; charset=utf8"       

  }
}

I tried to create valid code/URL, but I couldn't structure it.

The expected result is a ticket created in OTRS with an article (comment) linked.

2

There are 2 best solutions below

0
Roy On

Keep in mind that parameter might be tested for existing entities, like state, queue, etc. If a state with the name test does not exist the request fails.

The HTTP method, URL etc depends on the web service configuration. If you really using version 8 (from your link to the API) I recommend contacting the support.

0
testcaseone On

Your Body looks correct. A curl command could look like this, if this is what you mean by "code":

curl --location --request POST 'http://localhost/otrs/nph-genericinterface.pl/Webservice/testservicename/TicketCreate' \
--header 'Content-Type: application/json' \
--data-raw '{
  "UserLogin": "test",

  "Password": "test",

  "Ticket" : 
  {
    "Title": "test",
    "Queue": "test",
    "Lock": "test",
    "Type": "test",
    "State": "test",
    "Priority": "test",
    "Owner": "test",
    "CustomerUser": "test"
  },

  "Article":
  {
    "Subject" : "test",
    "Body" : "test",
    "ContentType": "text/plain; charset=utf8"       

  }
}'

Your URL would be: http://localhost/otrs/nph-genericinterface.pl/Webservice/NAMEOFTHEWEBSERVIVE/ROUTE. The "ROUTE" is what you enter in the "Network Transport" section, for example "/TicketCreate".

If you really use OTRS 8 instead of the deprecated OTRS 6 Community Edition or the compatible Znuny, that might not be true anymore