REST 2.0 and creating users

Hi, I’m having trouble creating users via the REST 2.0 interface in RT 5.0.0

I’m posting the following JSON to /user, but I always get the response “Could not create user”:
{ “EmailAddress”: “”,
“RealName”: “A Person”,
“Disabled”: “0”,
“id”: “user/new”,
“Gecos”: “aperson”,
“Name”: “aperson”

I’m authenticating using a token for ‘root’.

From looking at the source code, I can see the message comes from RT, as opposed to the REST extension. I’ve tried many combinations of parameters, but none work. I know not all the above are mandatory.

Is there any resource to determine what parameters are accepted?
What am I doing wrong?

Take a look in your logs and see if there’s a warning from RT - looking in lib/RT/ for RT 5.0.0 all bar one of the places that generates the ``Could not create user" message also log a critical warning which might help you find what aspect is going wrong.

Also I’m not sure if you need the id field for REST2.0 user creation - you don’t for creating tickets.

I’ve anonymised the log, but here it is:
[26784] [Tue Dec 15 23:11:49 2020] [info]: RT::User::CanonicalizeUserInfoFromExternalAuth returning Disabled: , EmailAddress:, Gecos: NSURNAME, Name: NSURNAME, NickName: , Privileged: , RealName: Not Anthony, token: (/app/rt5/sbin/…/lib/RT/
[26784] [Tue Dec 15 23:11:49 2020] [warning]: DBD::mysql::st execute failed: Unknown column ‘token’ in ‘field list’ at /usr/local/share/perl5/DBIx/SearchBuilder/ line 603. (/usr/local/share/perl5/DBIx/SearchBuilder/
[26784] [Tue Dec 15 23:11:49 2020] [warning]: RT::Handle=HASH(0xac78120) couldn’t execute the query ‘INSERT INTO Users (NickName, RealName, EmailAddress, Creator, Gecos, Password, LastUpdatedBy, Created, id, Name, token, LastUpdated) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)’ at /usr/local/share/perl5/DBIx/SearchBuilder/ line 616.
DBIx::SearchBuilder::Handle::SimpleQuery(‘RT::Handle=HASH(0xac78120)’, ‘INSERT INTO Users (NickName, RealName, EmailAddress, Creator,…’, ‘’, ‘Not Anthony’, ‘’, 14, ‘NSURNAME’, ‘NO-PASSWORD’, 14, …) called at /usr/local/share/perl5/DBIx/SearchBuilder/ line 369
DBIx::SearchBuilder::Handle::Insert(‘RT::Handle=HASH(0xac78120)’, ‘Users’, ‘NickName’, ‘’, ‘RealName’, ‘Not Anthony’, ‘EmailAddress’, ‘’, ‘Creator’, …) called at /usr/local/share/perl5/DBIx/SearchBuilder/Handle/ line 36
DBIx::SearchBuilder::Handle::mysql::Insert(‘RT::Handle=HASH(0xac78120)’, ‘Users’, ‘NickName’, ‘’, ‘RealName’, ‘Not Anthony’, ‘EmailAddress’, ‘’, ‘Creator’, …) called at /usr/local/share/perl5/DBIx/SearchBuilder/ line 1320
DBIx::SearchBuilder::Record::Create(‘RT::User=HASH(0xd663a38)’, ‘NickName’, ‘’, ‘RealName’, ‘Not Anthony’, ‘Creator’, 14, ‘EmailAddress’, ‘’, …) called at /app/rt5/sbin/…/lib/RT/ line 316
RT::Record::Create(‘RT::User=HASH(0xd663a38)’, ‘id’, 274, ‘NickName’, ‘’, ‘RealName’, ‘Not Anthony’, ‘EmailAddress’, ‘’, …) called at /app/rt5/sbin/…/lib/RT/ line 196
RT::User::Create(‘RT::User=HASH(0xd663a38)’, ‘NickName’, ‘’, ‘Privileged’, 0, ‘RealName’, ‘Not Anthony’, ‘EmailAddress’, ‘’, …) called at /app/rt5/sbin/…/lib/RT/REST2/Resource/Record/ line 423
RT::REST2::Resource::Record::Writable::create_record(‘RT::REST2::Resource::User=HASH(0xaea8d88)’, ‘HASH(0xd652340)’) called at /app/rt5/sbin/…/lib/RT/REST2/Resource/Record/ line 442
RT::REST2::Resource::Record::Writable::create_resource(‘RT::REST2::Resource::User=HASH(0xaea8d88)’, ‘HASH(0xd652340)’) called at /app/rt5/sbin/…/lib/RT/REST2/Resource/Record/ line 161
RT::REST2::Resource::Record::Writable::from_json(‘RT::REST2::Resource::User=HASH(0xaea8d88)’) called at /usr/local/share/perl5/Web/Machine/FSM/ line 613
Web::Machine::FSM::States::n11(‘RT::REST2::Resource::User=HASH(0xaea8d88)’, ‘Plack::Request=HASH(0xacaff70)’, ‘Plack::Response=HASH(0xb3cdcb0)’, ‘HASH(0xb3c85e8)’) called at /usr/local/share/perl5/Web/Machine/ line 62
Web::Machine::FSM::try {…} () called at /usr/local/share/perl5/Try/ line 102
eval {…} called at /usr/local/share/perl5/Try/ line 93
Try::Tiny::try(‘CODE(0xac74d40)’, ‘Try::Tiny::Catch=REF(0xd3fa240)’) called at /usr/local/share/perl5/Web/Machine/ line 129
Web::Machine::FSM::run(‘Web::Machine::FSM=HASH(0xacaff58)’, ‘RT::REST2::Resource::User=HASH(0xaea8d88)’) called at /usr/local/share/perl5/Web/ line 93
Web::Machine::call(‘Web::Machine=HASH(0xad06708)’, ‘HASH(0xd620fe8)’) called at /app/rt5/sbin/…/lib/RT/REST2/ line 117
RT::REST2::Dispatcher::ANON(‘HASH(0xd620fe8)’) called at /app/rt5/sbin/…/lib/RT/REST2/Middleware/ line 70
RT::REST2::Middleware::Auth::call(‘RT::REST2::Middleware::Auth=HASH(0xac39fe0)’, ‘HASH(0xd620fe8)’) called at /usr/local/share/perl5/Plack/ line 50
Plack::Component::ANON(‘HASH(0xd620fe8)’) called at /app/rt5/sbin/…/lib/RT/REST2/Middleware/ line 65
RT::REST2::Middleware::Log::call(‘RT::REST2::Middleware::Log=HASH(0xac3e6a0)’, ‘HASH(0xd620fe8)’) called at /usr/local/share/perl5/Plack/ line 50
Plack::Component::ANON(‘HASH(0xd620fe8)’) called at /app/rt5/sbin/…/lib/RT/REST2/Middleware/ line 62
RT::REST2::Middleware::ErrorAsJSON::call(‘RT::REST2::Middleware::ErrorAsJSON=HASH(0xac3e838)’, ‘HASH(0xd620fe8)’) called at /usr/local/share/perl5/Plack/ line 50
Plack::Component::ANON(‘HASH(0xd620fe8)’) called at /usr/local/share/perl5/Plack/App/ line 71
Plack::App::URLMap::call(‘Plack::App::URLMap=HASH(0xa40e6e8)’, ‘HASH(0xd620fe8)’) called at /usr/local/share/perl5/Plack/ line 50
Plack::Component::ANON(‘HASH(0xd620fe8)’) called at /usr/local/share/perl5/Plack/ line 145
eval {…} called at /usr/local/share/perl5/Plack/ line 145
Plack::Util::run_app(‘CODE(0xa6f7388)’, ‘HASH(0xd620fe8)’) called at /usr/local/share/perl5/Plack/Handler/ line 147
Plack::Handler::FCGI::run(‘Plack::Handler::FCGI=HASH(0xac477f0)’, ‘CODE(0xa6f7388)’) called at /usr/local/share/perl5/Plack/ line 84
Plack::Loader::run(‘Plack::Loader=HASH(0xa6cccb0)’, ‘Plack::Handler::FCGI=HASH(0xac477f0)’) called at /usr/local/share/perl5/Plack/ line 279
Plack::runner::run(‘RT::PlackRunner=HASH(0xa40cbe0)’) called at /app/rt5/sbin/…/lib/RT/ line 150
eval {…} called at /app/rt5/sbin/…/lib/RT/ line 150
RT::PlackRunner::run(‘RT::PlackRunner=HASH(0xa40cbe0)’) called at /app/rt5/sbin/rt-server.fcgi line 162 (/usr/share/perl5/vendor_perl/
[26784] [Tue Dec 15 23:11:49 2020] [error]: Could not create a new user - NickName–RealName-Not (/app/rt5/sbin/…/lib/RT/

It appears to be getting all the way to the SQL INSERT, which is failing. The field that stands out is ‘token’ which, although I can’t check yet, doesn’t look like a user field. token was passed as part of the URL.

I can confirm the above will result in a failed create

curl --location --request POST 'http://MyRT/REST/2.0/user' \
--header 'Authorization: Basic cm9vdDpwYXNzd29yZA==' \
--header 'Content-Type: application/json' \
--data-raw '{ "EmailAddress": "",
"RealName": "A Person",
"Disabled": "0",
"Gecos": "aperson",
"Name": "aperson"

works for me

So I’m struggling with two issues here. One is that I can only manage to authenticate using ‘?token=’ in the URL (not as a header), and the second is that when I put ?token into the URL, it makes it through to the SQL INSERT. So…

curl -X POST -H “Content-Type: application/json” -H “Authorization: token #token#>” -d ‘{ “EmailAddress”: “”, “Name”: “aperson”}’ ‘http://URL/REST/2.0/user

Fails with an unauthorized error, whilst:

curl -X POST -H “Content-Type: application/json” -d ‘{ “EmailAddress”: “”, “Name”: “aperson”}’ ‘http://URL/REST/2.0/user?token=#token#

Fails with logged entry:
[Wed Dec 16 04:43:39 2020] [warning]: RT::Handle=HASH(0xba84860) couldn’t execute the query ‘INSERT INTO Users (EmailAddress, Creator, Password, LastUpdatedBy, Created, id, token, Name, LastUpdated) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)’ at /usr/local/share/perl5/DBIx/SearchBuilder/ line 616.

Which appears to be attempting to insert data into the field ‘token’ in Users, which does not exist.

(Note: using http temporarily to allow capturing of web requests)

You may need to add this apache config

That’s interesting. I’ll get that put in when we get back to work in January.

Thanks :slight_smile: