July 29, 2022

duplicate: REST API Calling examples Znuny/OTRS

Learn in this article how to call WebService REST APIs of OTRS / Znuny / OTOBO using cURL.

In the previous articles Access Znuny & OTRS API via REST, Znuny & OTRS REST API Routes and Authenticate to Znuny / OTRS REST API we guide you thru the configuration steps of REST API in the role of the service provider. If you followed the steps your system is accessible via new REST API and awaiting now your cURL accesses of this article

REST API Call

As we import the default configuration of the REST API, the web service introduces new routes which are created in the branch:

http://{{znunyHostName}}/otrs/nph-genericinterface.pl/Webservice/Ticket%20REST%20API

The available routes are described in the article (LINK)REST API Routes(/LINK). As we already know the authentication of the HTTP requests is done via one of two methods:

  1. To authenticate each request with UserLogin and Password

    OR
  2. To authenticate with UserLogin and Password to create Session and authenticate all next calls with SessionID.

Authentication information is sent with request data as options. The data format is given by used HTTP method (i.e. for GET requests it has to be mentioned in Query string; for POST&PATCH in JSON Data). Alternatively starting from the version of Znyny 6.1.2 the authentication information can be posted also via X-OTRS-Header-(UserLogin|CustomerUserLogin|SessionID|Password).

Example: Create a Ticket using user/password authenticated request

Below you can see an example of user/password authenticated request creating a Ticket:

Request:

POST http://{{FQDN}}/otrs/nph-genericinterface.pl/Webservice/Ticket%20REST%20API/Ticket?

Data in the body:

{
"data" : {
    "UserLogin":"{{user}}",
    "Password":"{{pass}}",
    "Ticket":{
        "Title":"Ticket created via REST API - minimal content",
        "Queue":"Raw",
        "StateID": 1 ,
        "PriorityID": 3,
        "CustomerUser":"{{CustomerUser}}"
    },
    "Article":{
        "CommunicationChannel":"Email",
        "Subject":"Test Article created with new Ticket via REST API type Email",
        "Body":"email body.",
        "ContentType":"",
        "Charset":"utf-8",
        "MimeType":"text/plain"
    }
  }
}

Variables:

VariableDescription
{{user}}User name used to authenticate to OTRS authorized to create Ticket.
{{pass}}User’s password
{{FQDN}}The fully qualified domain name of the server with OTRS
{{CustomerUser}}Login name of the Customer for which the Ticket has been open

When converted into cURL the example of UserLogin&Password authenticated creation of a ticket looks like this:

curl --location --request POST 'http://localhost/otrs/nph-genericinterface.pl/Webservice/Ticket%20REST%20API/Ticket' 
--header 'Content-Type: application/json' 
--data-raw '{
    "UserLogin":"userXYZ",
    "Password":"plain-text-password",
    "Ticket":{
        "Title":"Ticket created via REST API - minimal content",
        "Queue":"Raw",
        "StateID": 1 ,
        "PriorityID": 3,
        "CustomerUser":"CustomerUser"
    },
    "Article":{
        "CommunicationChannel":"Email",
        "Subject":"Test Article created with new Ticket via REST API type Email",
        "Body":"email body.",
        "ContentType":"",
        "Charset":"utf-8",
        "MimeType":"text/plain"
    }
}'

Example: Create Ticket using SessionID authentication

The second method to create a ticket is to Create Session and then create a ticket being authenticated with the SessionID.

  1. Create Session and get SessionID
  2. Create Ticket using SessionID authentication

Create Session and get SessionID

Request:

curl --location --request POST 'http://localhost/otrs/nph-genericinterface.pl/Webservice/Ticket%20REST%20API/Session' 
--header 'Content-Type: application/json' 
--data-raw '{
    "UserLogin":"userXYZ",
    "Password":"plain-text-password"
}'

Response:

{
    "SessionID": "Yx9TilyRyGveitmMKrdBy2Q8oqKqA4U2"
}

Create Ticket

CURL example of the SessionID authenticated creation of a ticket:

curl --location --request POST 'http://localhost/otrs/nph-genericinterface.pl/Webservice/Ticket%20REST%20API/Ticket' 
--header 'Content-Type: application/json' 
--data-raw '{
    "SessionID":"Yx9TilyRyGveitmMKrdBy2Q8oqKqA4U2",
    "Ticket":{
        "Title":"Ticket created via REST API - minimal content",
        "Queue":"Raw",
        "StateID": 1 ,
        "PriorityID": 3,
        "CustomerUser":"CustomerL"
    },
    "Article":{
        "CommunicationChannel":"Email",
        "Subject":"Test Article created with new Ticket via REST API type Email",
        "Body":"email body.",
        "ContentType":"",
        "Charset":"utf-8",
        "MimeType":"text/plain"
    }
}'

Related articles

To learn more about OTRS & Znuny REST API routes and request options please see (LINK)REST API Routes(/LINK).

To learn how to setup the REST API in OTRS & Znuny installation please see Access Znuny & OTRS API via REST.

Do you need help with Znuny / OTRS?
We have lot of experiences with OTRS and Znuny and can help you with your issues. Get in touch with us and we will check if and how we can help you.

Leave a Comment

Your email address will not be published. Required fields are marked *

Do you need help with Znuny / OTRS?​

We have lot of experiences with OTRS and Znuny.
We can help you with your issues to solve them.

From giving you support up to implementing integrations to your existing systems.

Get in touch with us and we will check if and how we can help you.​

Get OTRS/Znuny/OTOBO Support
Our support experts prepare themself, by reviewing your business. Please Share your website URL
To get a quick and efficient clearance of your needs, our experts will call you.
We communicate in English.
Maybe we can communicate in your native language too. So please let us know your native written and spoken language.