简体   繁体   中英

Creating tickets on RT via REST API with Powershell

I'm trying to create ticket in RT using REST API. So far I can searching tickets:

$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

But creating:

$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

Resulting in:

RT/3.8.8 200 Ok
# Could not create ticket.
# Could not create ticket. Queue not set

or:

$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

Resulting:

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 said:

to create a new ticket: post on /REST/1.0/ticket/new with a variable named "content", containing "key: value" line by line, example:

Testing the new ticket section

id: ticket/new Queue: Requestor: Subject: Cc: <...> AdminCc: <...> Owner: <...> Status: <...> Priority: <...> InitialPriority: <...> FinalPriority: <...> TimeEstimated: <...> Starts: <...> Due: <...> Text: CF-:

I lost a whole day on the search for a solution. Google didn't find any help for me.. Any advice and suggestions will be greatly appreciated.

OK, just find solution myself :| "queue: queue_name" MUST be at the end of content variable:

$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

Result:

RT/<version> 200 Ok
# Ticket <number> created.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM