Set Owner in Create Ticket using API

Hi i am unable to set the “owner” of tickets when using the rest api. All other fields are created with values no problem, except the owner field. I have tried using the username, the email address, upper, lower, proper case, etc, i just cannot get the owner field to populate.

My response is 200 OK, ticket #n created, and i can see in the web interface that the ticket is created, just doesn’t have an owner.

Apache logs. Here are a portion of the access and error logs during my rest call that may contain the clue, i have bolded a line which seems relevant.

==> /var/log/httpd/error_log <==
[Mon Apr 10 06:40:56.838051 2017] [authz_core:error] [pid 28370] [client ipaddr:52306] AH01630: client denied by server configuration: /opt/rt4/share/html/REST/1.0/ticket/new
[29864] [Sun Apr  9 20:40:57 2017] [info]: Successful login for root from ipaddr (/opt/rt4/sbin/../lib/RT/Interface/Web.pm:831)
[29864] [Sun Apr  9 20:40:57 2017] [warning]: Use of uninitialized value $_ in split at /opt/rt4/sbin/../lib/RT/Interface/REST.pm line 288. (/opt/rt4/sbin/../lib/RT/Interface/REST.pm:288)
[29864] [Sun Apr  9 20:40:57 2017] [warning]: Use of uninitialized value $_ in split at /opt/rt4/sbin/../lib/RT/Interface/REST.pm line 288. (/opt/rt4/sbin/../lib/RT/Interface/REST.pm:288)
**[29864] [Sun Apr  9 20:40:57 2017] [error]: Couldn't get principal for an empty user (/opt/rt4/sbin/../lib/RT/User.pm:1282)**
[29864] [Sun Apr  9 20:40:57 2017] [info]: <domain> #233/3210 - Scrip 8 On Create Notify Owner and AdminCcs (/opt/rt4/sbin/../lib/RT/Action/SendEmail.pm:285)
[29864] [Sun Apr  9 20:40:57 2017] [info]: <domain> No recipients found. Not sending. (/opt/rt4/sbin/../lib/RT/Interface/Email.pm:806)
[29864] [Sun Apr  9 20:40:57 2017] [info]: <domain> #233/3210 - Scrip 9 On Create Notify Ccs (/opt/rt4/sbin/../lib/RT/Action/SendEmail.pm:285)
[29864] [Sun Apr  9 20:40:57 2017] [info]: <domain> No recipients found. Not sending. (/opt/rt4/sbin/../lib/RT/Interface/Email.pm:806)
[29864] [Sun Apr  9 20:40:57 2017] [info]: <domain> #233/3210 - Scrip 10 On Create Notify Other Recipients (/opt/rt4/sbin/../lib/RT/Action/SendEmail.pm:285)
[29864] [Sun Apr  9 20:40:57 2017] [info]: <domain> No recipients found. Not sending. (/opt/rt4/sbin/../lib/RT/Interface/Email.pm:806)
[29864] [Sun Apr  9 20:40:57 2017] [info]: Ticket 233 created in queue 'desk' by root (/opt/rt4/sbin/../lib/RT/Ticket.pm:567)

==> /var/log/httpd/access_log <==
ipaddr - - [10/Apr/2017:06:40:56 +1000] "POST /rt/REST/1.0/ticket/new?user=root&pass=*** HTTP/1.1" 200 40 "-" "Mozilla/5.0 (Windows NT; Windows NT 10.0; en-AU) WindowsPowerShell/5.1.14393.953"

Seems there is a parsing error:

[29864] [Sun Apr 9 20:40:57 2017] [warning]: Use of uninitialized value $_ in split at /opt/rt4/sbin/…/lib/RT/Interface/REST.pm line 288. (/opt/rt4/sbin/…/lib/RT/Interface/REST.pm:288)

can you give us the content of the REST request?

Hey thank you for the response. I am traveling and will send the full request later.

I’d like to note also that the owner is NOT set even if I hard code an owner.

http://requestb.in/148itt31?inspect

Heres the request i am making. All of the fields populate the new ticket except for the “owner”

Seems this url is no longer working, it returns “Not found” to me :frowning:

Here is the full content variable

content=id%3A+ticket%2Fnew%0D%0Arequestor%3A+dummy%40email.com%0D%0ASubject%3A+Test+Subject%0D%0Aowner%3A+andrew%0D%0AText%3A+some+test+body+text%0A+Original+Desk+Case+Link%3Ahttp%3A%2F%2Fcase%0D%0APriority%3A+2%0D%0AQueue%3A+desk

Some hints:

  • is andrew a Name of an RT user
  • is andrew account enabled
  • as andrew OwnTicket right on queue “desk”
  • what if you user Owner instead of owner
  • what if you use unix line breaks (%0A) instead of %0D%0A

?

  • is andrew a Name of an RT user
    Yes see below
  • is andrew account enabled
    Yes see below
  • as andrew OwnTicket right on queue "desk"
    Yes
  • what if you user Owner instead of owner
    I have tried upper and lower cased “O”
  • what if you use unix line breaks (%0A) instead of %0D%0A
    I have not tried this, will try.

This is output from /REST/1.0/user/<user-id>

StatusCode        : 200
StatusDescription : OK
Content           : RT/4.4.1 200 Ok
                    
                    id: user/30
                    Password: ********
                    Name: andrew
                    EmailAddress: andrew@domain.com
                    RealName: Andrew Huddleston
                    NickName: andrew

I have resolved this now. A matter of formatting.

If anyone wants PowerShell code for working against the REST Api let me know, im happy to share.

working code

$POSTParams = @{
user= 'user'
pass= '****'
content= "id: ticket/new`nOwner: andrew`nQueue: desk"
}

not working code

$POSTParams = @{
user= 'user'
pass= '****'
content= @"
 id: ticket/new
 Owner: andrew
 Queue: desk
"@
}

Ok, it confirms it’s a problem with line breaks. In RT::Interface::REST::form_parse, the following code is used:

my @lines = split /\n/, $_[0];

should be replaced by:

my @lines = split /\r\n?|\n/, $_[0];

to handle CR, LF OR CRLF lines ending.

Will create a ticket for this.

Done: https://issues.bestpractical.com/Ticket/Display.html?id=32726

Thank you @elacour this is great, you guys are really cool!

Thanks for the support!