How to Access User Total Download, Upload, Data from REST API in /user-manager/user/?

Hello community,

I’m currently working on a project that involves monitoring user data in a system through a REST API. Specifically, I need to retrieve the total download and upload statistics for users, as well as their uptime.

In the past, I was able to access this information using the /user-manager/user/monitor 1,2,3 command. However, I’m now looking for a way to achieve the same results programmatically using the REST API.

I have tried using the following curl request:

curl --location 'https://router/rest/user-manager/user/monitor' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic aXJhbjgwLWFwaTpxMTMy' \
--data '{"numbers":1}'

However, the response I’m getting is not as expected. I’m not receiving any data.

I’ve read through the API documentation, but I couldn’t find any specific endpoints or methods related to user monitoring. I’m wondering if there’s an alternative endpoint or a specific API call that allows me to obtain this data?

If anyone has experience working with this particular REST API or has encountered a similar challenge, I would greatly appreciate your guidance. Any code examples, API references, or pointers in the right direction would be incredibly helpful.

Thank you in advance for your support!

I would like to know either. Run these URLs in method GET always return 400 bad request.

  • /rest/user-manager/user/monitor?numbers=2
  • /rest/user-manager/user/monitor/2
  • /rest/user-manager/user/monitor/*2

However, if I use method POST with body data

{"numbers": [2]}

it returns missing =.id=.

If I use POST body

{".id": "*8"}

it returns empty array – with or without numbers attribute.

I don’t have UM to test, but you need to use POST with “monitor”.

You’re better off using .query with a name= (or any of the attributes, other than “numbers”/“.id”) since you can use “query” for them in one operation. With the “monitor” command, it will buffer results for 60 seconds before returning, so below using “once” so it returns immediately.

Something like this should work, you can change the env at start to test, and has added logging:

USER=admin ROUTER=192.168.88.1 NAME=myuser; curl -l -u $USER -X POST http://$ROUTER/rest/user-manager/user/monitor -H "Content-Type: application/json" --data '{ "once": true, ".query": ["name=$NAME"]}' --trace-ascii /dev/stdout

Sorry but that is not working. Still bad request.

{
“detail”: “missing =.id=”,
“error”: 400,
“message”: “Bad Request”
}

Well, how about trying the .id. I don’t have user manager, but if you have the CLI command that does what you want that be easier to “port” so we know the operation works in CLI first…

But use .id, it look something like this

curl -l -u $USER -X POST http://$ROUTER/rest/user-manager/user/monitor -H "Content-Type: application/json" --data '{ "once": true, ".query": [".id=*8"]}' --trace-ascii /dev/stdout

You’d need replace $USER and $ROUTER with your info, and know the .id to use from the “/user-manager/user/print show-ids” command. You’d don’t just add a * from what’s in a plain “print”, you need “print show-ids” to use the .id field. There is generally no numbers= in REST API (or at least be a bad idea to use if allowed)

edit: .query takes an array of strings, so equals is just part of a string… so “.id=*8” is right – BUT the [“.id”=“*8”] syntax was wrong (I copied yours and forgot to edit)… [ bash’s shell vs routeros escaping starts to get complex quickly – why helpful to know what CLI command does what you want :wink: ]

Sorry but these are not working.

{
    "once": true,
    ".query": [".id=*8"]
}

or

{
    "once": true,
    ".query": ".id=*8"
}

or

{
    "once": true,
    ".query": ".id=*8"
}

All are the same result “bad request” “detail”: “missing =.id=”.

BUT!!
This works!

{
    "once": true,
    ".id": "*8"
}

Result:

[
{
“active-sessions”: “1”,
“active-sub-sessions”: “1”,
“actual-profile”: “xxxxx-xxxxxx”,
“attributes-details”: “Private info Name:xxxxx:string:0xxxxxx”,
“total-download”: “874034635”,
“total-upload”: “48807958”,
“total-uptime”: “1d5h13m23s”
}
]

The value of “.id” that is “*8” from id of user in user manager.

Thank you for suggest for “once” that is required to make it work.

Postman view and error:
https://ibb.co/MSDY2J1

Hi, I need to get user stats too, I tried and failed, I’m using postman for test then use PHP script.

But I’m getting 404, the URL is correct, I’ve tested it to get all users and it worked!!!
but for god knows why, it throws 404 for monitor
I even checked with ChatGPT OpenAI, and still no result…
can anyone help me? does it have sth to do with mikrotik config?

UPDATE: I don’t know how to cancel so I’m just gonna say it, the problem was with the id I was using, apparently it did not exist, I used another one and it worked.

Is there a way to reed all UserManager User-Statistic Date via one request? At the WinBox, you also get all infos listed.

If you have a comma-separated list of .id’s that can be used in user-manager/user/monitor - JSON is still a string for .id - but it can take multiple .id’s

 curl -k -u $USER:$PASSWORD -X POST http://$ROUTEROS/rest/user-manager/user/monitor --json '{".id": "*1,*2", "once": true}'

[{“active-sessions”:“4”,“active-sub-sessions”:“4”,“attributes-details”:“Mikrotik-Group:full:string:0x000000,Mikrotik-Group:full:string:0x00000”,“total-download”:“0”,“total-upload”:“0”,“total-uptime”:“14h47m5s”},{“active-sessions”:“0”,“active-sub-sessions”:“0”,“attributes-details”:“”,“total-download”:“0”,“total-upload”:“0”,“total-uptime”:“0s”}]

But not in ONE call, since the list of .id have to come from another call to GET …/user-manager/user/get or POST …/print & parsed in the comma-separated list used above.