3

我正在尝试使用 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:票证/新队列:请求者:主题:抄送:<...> AdminCc:<...> 所有者:<...> 状态:<...> 优先级:<...> InitialPriority:<. ..> FinalPriority:<...> TimeEstimated:<...> 开始:<...> 到期:<...> 文本:CF-:

我花了一整天的时间寻找解决方案。谷歌没有为我找到任何帮助。任何建议和建议将不胜感激。

4

1 回答 1

9

好的,自己找解决办法:| "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.
于 2015-04-09T13:44:38.340 回答