■はじめに
OTRS6のAPIに関する備忘録です。
■環境
・OTRS-6.0.6
■Webサービスの作成
名前と設定のネットワーク・トランスポートを入力して「保存」をクリック
追加のOparationから「TicketCreate」を選択
追加のOparationから「TicketSearch」を選択
追加のOparationから「SessionCreate」を選択
ネットワーク・トランスポートの「設定」を開く
次のように入力して「保存して終了」
■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"
}
以上です。