2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

OTRSのAPIをつかってみた

Last updated at Posted at 2018-05-03

■はじめに

OTRS6のAPIに関する備忘録です。

■環境

・OTRS-6.0.6

■Webサービスの作成

管理者でログインを行い「設定」「Webサービス」を開く
image.png

「Webサービスを追加」をクリック
image.png

名前と設定のネットワーク・トランスポートを入力して「保存」をクリック
image.png

追加のOparationから「TicketGet」を選択
image.png

名前を入力して「保存して終了」
image.png

追加のOparationから「TicketCreate」を選択
image.png

名前を入力して「保存して終了」
image.png

追加のOparationから「TicketSearch」を選択
image.png

名前を入力して「保存して終了」
image.png

追加のOparationから「SessionCreate」を選択
image.png

名前を入力して「保存して終了」
image.png

ネットワーク・トランスポートの「設定」を開く
image.png
次のように入力して「保存して終了」
image.png

最後に「保存して終了」
image.png

■APIの実行

ログインしてSessionIDを取得します。

■コマンド
curl -s -X POST 'http://localhost/otrs/nph-genericinterface.pl/Webservice/Ticket/login' \
     -d '{ "UserLogin": "ユーザー", "Password": "パスワード"}' | jq '.SessionID'

■実行結果
"vOGk9BGdAR9BIAdJgYartGreHX5nA3kO"

チケットの一覧を取得します。

■コマンド
curl -sG -d 'SessionID=vOGk9BGdAR9BIAdJgYartGreHX5nA3kO' 'http://localhost/otrs/nph-genericinterface.pl/Webservice/Ticket/'  -d 'StateType=Open' -d 'Queues=Misc' | jq '.'

■実行結果
{
  "TicketID": [
    "1"
  ]
}

条件を指定してチケットの一覧を取得します。

■コマンド
curl -sG -d 'SessionID=vOGk9BGdAR9BIAdJgYartGreHX5nA3kO' 'http://localhost/otrs/nph-genericinterface.pl/Webservice/Ticket/' | jq '.'

■実行結果
{
  "TicketID": [
    "1"
  ]
}

チケットの詳細を取得します。

■コマンド
curl -sG -d 'SessionID=vOGk9BGdAR9BIAdJgYartGreHX5nA3kO' 'http://localhost/otrs/nph-genericinterface.pl/Webservice/Ticket/TicketGet/1' | jq '.'

■実行結果
{
  "Ticket": [
    {
      "Age": 4681647,
      "PriorityID": "3",
      "ServiceID": "",
      "Type": "Unclassified",
      "Responsible": "root@localhost",
      "StateID": "1",
      "ResponsibleID": "1",
      "ChangeBy": "1",
      "EscalationTime": "0",
      "OwnerID": "1",
      "Changed": "2018-03-09 22:29:21",
      "TimeUnit": 0,
      "RealTillTimeNotUsed": "0",
      "GroupID": "1",
      "Owner": "root@localhost",
      "CustomerID": null,
      "TypeID": 1,
      "Created": "2018-03-09 22:29:21",
      "Priority": "3 normal",
      "UntilTime": 0,
      "EscalationUpdateTime": "0",
      "Queue": "Raw",
      "QueueID": "2",
      "State": "new",
      "Title": "Welcome to OTRS!",
      "CreateBy": "1",
      "TicketID": "1",
      "StateType": "new",
      "UnlockTimeout": "0",
      "EscalationResponseTime": "0",
      "EscalationSolutionTime": "0",
      "LockID": "1",
      "TicketNumber": "2015071510123456",
      "ArchiveFlag": "n",
      "Lock": "unlock",
      "SLAID": "",
      "CustomerUserID": null
    }
  ]
}

チケットの作成をします。

■コマンド
curl -s -X POST -H "Content-Type:application/json" \
-d "{ \"SessionID\":\"vOGk9BGdAR9BIAdJgYartGreHX5nA3kO\",
      \"Ticket\":
          {\"Title\":\"test-title\", 
           \"Type\": \"Unclassified\",
           \"Queue\":\"Raw\",
           \"State\":\"open\",
           \"Priority\":\"3 normal\",
           \"CustomerUser\":\"test@gmail.com\"},
     \"Article\":{
           \"Subject\":\"test subject\",
           \"Body\":\"test body\",
           \"ContentType\":\"text/plain; charset=utf8\"}
}" 'http://localhost/otrs/nph-genericinterface.pl/Webservice/Ticket/TicketCreate' | jq '.'

■実行結果
{
  "ArticleID": "10",
  "TicketNumber": "2018050397000093",
  "TicketID": "10"
}

以上です。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?