我尝试使用REST API在RT中创建票证。 到目前为止,我可以搜索门票:
$servername="tickets.somedomain"
$u="user=someuser"
$p="pass=P@55w0rd"
$q="search/ticket?query=(Queue='Queue_name')"
$uri="http://" + $servername + "/REST/1.0/" + $q + "&" + $u + "&" + $p
$RT=Invoke-WebRequest -Uri $uri -SessionVariable sess
$rt.Content
但要创造:
$servername = 'http://tickets.somedomain/REST/1.0/ticket/new'
$postParams = @{
user = 'someuser';
pass = 'P@55w0rd';
content = @"
Queue: Queue_name
id: ticket/new
Requestor: some_user_email
Subject: TEST
Status: New
Text: blahblah
"@;
}
$RT = Invoke-WebRequest -Uri $servername -Method Post -Body $postParams
$RT.content
导致:
RT/3.8.8 200 Ok
# Could not create ticket.
# Could not create ticket. Queue not set
或:
$servername="http://tickets.somedomain/REST/1.0/ticket/new?user=someuser&pass=P@55w0rd"
$RT = Invoke-WebRequest -Uri $servername -Body @{Content="Queue: 'queue_name'\nid: new"} -Method Post
$RT.content
由于:
RT/3.8.8 200 Ok
# Required: id, Queue
id: ticket/new
Queue:
Requestor: lukasz.wasko
Subject:
Cc:
AdminCc:
Owner:
Status: new
Priority:
InitialPriority:
FinalPriority:
TimeEstimated: 0
Starts: 2015-04-09 12:55:33
Due: 2015-04-09 12:55:33
Text:
http://requesttracker.wikia.com/wiki/REST#Ticket_Create说:
创建新故障单:在/REST/1.0/ticket/new上发布一个名为" content"的变量,其中包含" key:value"逐行,例如:
测试新的故障单部分
id:ticket / new 队列: 请求: 学科: 抄送:< ...> AdminCc:< ...> 所有者:< ...> 状态:< ...> 优先级:< ...> InitialPriority:< ...> FinalPriority:< ...> 时间估计:< ...> 开始:< ...> 到期日:< ...> 文本: CF-:
我在寻找解决方案时失去了一整天。谷歌没有为我找到任何帮助.. 任何建议和建议将不胜感激。
答案 0 :(得分:8)
好的,我自己找到解决方案:| " queue:queue_name" 必须位于内容变量的末尾:
$servername="http://tickets.somedomain/REST/1.0/ticket/new?user=someuser&`pass=P@55w0rd"
$content = @'
id: ticket/new
Subject: Test
Text: some text
Queue: queue_name
'@
$RT = Invoke-WebRequest -Uri $servername -Body @{content=$content} -Method Post
$RT.content
结果:
RT/<version> 200 Ok
# Ticket <number> created.