REST2 - user ids

Greetings.
When querying REST2 API for users, it returns the list of found users in the following format:

    "items": [
          {
             "type": "user",
             "_url": "https://MY-RT/REST/2.0/user/test@example.org",
             "id": "test@example.org"
          },
          {
             "type": "user",
             "_url": "https://MY-RT/REST/2.0/user/another_user@example.org",
             "id": "another_user@example.org"
          },
        ...etc

The point is, the ids are returned as email addresses, not as actual numeric ids. Is this a problem with my RT installation? If it is the expected behavior - what was the reason for this and how can I make API return the numeric ids instead of emails for user ids?

What happens if you follow the URL provided for each user?

If the URL doesn’t contain any whitespaces - it returns the expected user object. If there is a whitespace in the URL (which happens if the user doesn’t have an email set, but does have a set RealName, the example would be https://MY-RT/REST/2.0/user/John Doe) - it returns 404. Searching for numeric ids (like [{"field": "id", "operator": ">=", "value": 12345}]returns just the list of all users.

What query/endpoint are you using to get the original result? Which version of RT and REST2?

RT version is 4.4.4
REST2 version seems to be 1.09, according to GitHub - bestpractical/rt-extension-rest2 (we are using the latest version from there)
The described format is returned anywhere where there can be users in response. For example:

POST https://MY-RT/REST/2.0/users/


[
    {
        "field": "id",
        "operator": ">=",
        "value": 1000
    },
    {
        "field": "id",
        "operator": "<=",
        "value": 1100
    }
]


The response is as described in the first post.

GET https://MY-RT/REST/2.0/group/123456

...
"Members": [
      {
         "_url": "https://MY-RT/REST/2.0/user/support@example.com",
         "id": "support@example.com",
         "type": "user"
      },
      {  // this user doesnt have an email set
         "type": "user",
         "id": "John Doe",
         "_url": "https://MY-RT/REST/2.0/user/John Doe"
      },
      {
         "_url": "https://MY-RT/REST/2.0/user/jd@example.com",
         "type": "user",
         "id": "jd@example.com"
      },
      {
         "_url": "https://MY-RT/REST/2.0/group/554525",
         "id": "554525",
         "type": "group"
      },
...

I can confirm I see emails/usernames in the ID field, something like:

{
            "type": "user",
            "_url": "http://SOME-RT/REST/2.0/user/hello world",
            "id": "hello world"
},

Depending on what you’re using to call the endpoint you most likely need to replace the spaces:

curl -X GET -H "Content-Type: application/json" -u root:password 'http://Some-RT:80/REST/2.0/user/hello%20world'

Using Postman it doesn’t seem like I need to but using Curl requires %20 in place of the space in the username.

try this!

http://Some-RT:80/REST/2.0/users?fields=id

You can request additional fields on search results:

http://Some-RT:80/REST/2.0/users?fields=id,Name,EmailAddress

Wow, this actually worked! It still doesn’t resolve the issue with not being able to search based on user ids, but this already helps a lot. Thank you!

You can use the user ID value in place of the username

I’m aware of that (actually used some pretty dirty webpage parsing to extract numeric ids from ticket roles to get the users from API before), but this doesn’t work for queries like

POST https://MY-RT/REST/2.0/users

[
  {
    "field": "id",
    "operator": ">=",
    "value": 1000
  },
  {
    "field": "id",
    "operator": "<=",
    "value": 1300
  }
]

As such queries seem to be looking at usernames rather than numeric ids. In case provided above it returns all the RT users, not only those with their ids between 1000 and 1300 (as it stands now, “total” key in response to this example query contains the value of 21060).

I can confirm that behavior, seems to be a bug

At least now I know that this isn’t a problem with my RT config. Thank you for your help!

Hello, is there a place where one can see all the bugs submited to RT development team and how they being resolved?
All I could find is an email address for correspondence…
Thanks

There’s Best Practical’s own RT instance that you can access to read as a guest.

1 Like

Are robots allowed here?

I hope not. They’re posting wrong and irrelevant information. This isn’t the first one I’ve seen.