Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not exec 'User List' query API #8916

Closed
timiil opened this issue Nov 22, 2017 · 4 comments
Closed

Can not exec 'User List' query API #8916

timiil opened this issue Nov 22, 2017 · 4 comments

Comments

@timiil
Copy link

timiil commented Nov 22, 2017

Description:

i am trying to query users with some simple condition, just like 'all active users'.

when i try to #1:

curl -H "X-Auth-Token: tz7L_ajNPk7KMbsdzmLP0prlGn_HNJ874pHJP7JCqIb" \
     -H "X-User-Id: oPn8LFLNaaZ3SokQP" \
     http://localhost:3380/api/v1/users.list

that is ok. no error, just return the full users list.

#2 shot:

curl -H "X-Auth-Token: tz7L_ajNPk7KMbsdzmLP0prlGn_HNJ874pHJP7JCqIb" \
>      -H "X-User-Id: oPn8LFLNaaZ3SokQP" \
>      http://localhost:3380/api/v1/users.list?query={active:true}
{
  "success": false,
  "error": "Invalid query parameter provided: \"active:true\" [error-invalid-query]",
  "errorType": "error-invalid-query"

#3 shot:

curl -H "X-Auth-Token: tz7L_ajNPk7KMbsdzmLP0prlGn_HNJ874pHJP7JCqIb" \
>      -H "X-User-Id: oPn8LFLNaaZ3SokQP" \
>      http://localhost:3380/api/v1/users.list?query='{active:true}'
{
  "success": false,
  "error": "Invalid query parameter provided: \"active:true\" [error-invalid-query]",
  "errorType": "error-invalid-query"

please let me know what is the correct manner about the query string, thanks very much!

Server Setup Information:

  • Version of Rocket.Chat Server: 0.60.0-develop
  • Operating System: debian
  • Deployment Method(snap/docker/tar/etc): docker
  • Number of Running Instances: 1
  • DB Replicaset Oplog:
  • Node Version: 8.8.1
@rusty-1-shaun
Copy link

Hi @timiil you need to use the --data-urlencode option to specify the query parameters as well as ensure that curl processes the request as a GET (-G). Here is an example of a curl query that works.

curl -s -G \
     -H "X-Auth-Token: ${TOKEN}" \
     -H "X-User-Id: ${USER_ID}" \
     -H "Accepts: application/json" \
     --data-urlencode 'fields={ "username":1, "status":1 }' \
     --data-urlencode 'query={"username":{"$regex":"us"}}' \
     https://myrocketchat.com/api/v1/users.list
{
  "users": [
    {
      "username": "peter",
      "status": "online",
      "_id": "xxxxxxWpdSgcYksN"
    },
    {
      "username": "justine",
      "status": "online",
      "_id": "xxxxxxa6xmZF3TNT2"
    },
    {
      "username": "rusty",
      "status": "online",
      "_id": "xxxxxxxL9Jit9wLy5r"
    },
    {
      "username": "susan",
      "status": "offline",
      "_id": "xxxxxxxQjCjfgPg9GN"
    },
    {
      "username": "brown",
      "status": "offline",
      "_id": "xxxxxxxxxsjiPjpAJ3"
    }
  ],
  "count": 5,
  "offset": 0,
  "total": 5,
  "success": true
}

@graywolf336
Copy link
Contributor

Yes, the query param expects a valid json object to be passed.

@timiil
Copy link
Author

timiil commented Nov 30, 2017

@Rusty-1 , as your above code , your query condition is not effect. either online or offline has come ...

thanks for your reply

@mhow2
Copy link

mhow2 commented May 11, 2021

On https://developer.rocket.chat/api/rest-api/query-and-fields-info, it's mentioned:

To only return the usernames for users, you would do something like this:
http://localhost:3000/api/v1/users.list?fields={ "username": 1 }

However, if you issue something like (with an Admin token):

curl -G -H "X-Auth-Token: xx" -H "X-User-Id: xx" --data-urlencode 'fields={"status":1}' https://myrc/api/v1/users.list

You'll get all the fields, not only status. @graywolf336 , @Rusty-1 could you clarify what is the expected behavior ?

Or is it something that relates with the word "all" in the sentence in https://developer.rocket.chat/api/rest-api/methods/users/list ?

Gets all of the users in the system and their information...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants