count-only in rest api

Hello,
i try to check with rest api total wifi clients.
for now i’m testing on my HAP ax2 with ROS 7.9.
so on mikrotik i use
/interface/wifiwave2/registration-table/print count-only where ssid=“WIFI GUEST”
but with rest api i try to use
curl -k -u admin:12345678 -X POST https://10.2.1.1:10443/rest/interface/wifiwave2/registration-table/print
i see correct all wifi client (on all ssid)
curl -k -u admin:12345678 -X POST https://10.2.1.1:10443/rest/interface/wifiwave2/registration-table/print --data ‘{“.query”: [“ssid=WIFI GUEST”]}’ -H “content-type: application/json”
to try now i use m laptop windows 11, and i have this error
{“detail”:“Invalid JSON”,“error”:400,“message”:“Bad Request”}curl: (3) bad range in URL position 2:
[ssid=WIFI GUEST]}’
^
and i can’t found documentation to use command “count-only”
can you help me?

thank you

I couldn’t reproduce your exact problem. My below query works as expected:

curl -k -u test:test -X POST https://192.168.1.1/rest/caps-man/registration-table/print --data '{".query": ["ssid=myssid"]}' -H "content-type: application/json"

It returns the same results as this console command:

/caps-man/registration-table/print where ssid="myssid"

I suspect your problem could be caused by the space in SSID. Try changing your SSID so it doesn’t contain spaces to confirm.
Hope this helps.

try to remove the space on SSID name… or add quotes on query :laughing:

POST requires knowing Mikrotik “binary” API…

So the issue is that .query with POST is follows same rules as API, so the end of the .query array describes the and/or/etc. See https://help.mikrotik.com/docs/display/ROS/API#API-Queries

And the “attributes without options” – like print “count-only”, need to be key-values booleans in the REST POST e.g. { …, “count-only”: true }

curl -l -u $myuser -X POST http://$myrouter/rest/ip/address/print --data '{".query": ["disabled=yes","#|"], "count-only": true}'

I think quotes will actually break it… It’s already in it’s own element so the “=” is separator for attributes, and next array element is next thing, so spaces shouldn’t be an issue.

sorry sorry sorry!!!
i’m trying from win pc, and i have error below…
but on linux works fine… :smiley: :smiley: :smiley:


sorry, i understand i change my ssid without spaces…

but now i would ty to monitor netwatch and i try to

curl -k -u admin:12345678 -X POST https://10.2.5.1:10443/rest/tool/netwatch/print --data '{".query": ["host=10.2.5.200"]}' -H "content-type: application/json"

but this is error

{"error":415,"message":"Unsupported Media Type"}curl: (3) bad range in URL position 2:
[host=10.2.5.200]}'
 ^

but here there isn’t spaces…
i thinked to use comment, but there is a lot of spaces, so i used host

instead

curl -k -u admin:12345678 -X POST https://10.2.5.1:10443/rest/tool/netwatch/print

works fine

can you have a suggestion ?
thank you in advance

You first example should work, but doesn’t for me either.

But using the “…/getall”, instead of “…/print” in URL does allow the “.query” string to work. The REST API’s POST methods really are just thin proxy over the “old” API, so all of this stuff largely applies to REST with POST: https://help.mikrotik.com/docs/display/ROS/API#API-Commanddescription

getall
getall command is available where console print command is available (getall is an alias for print).
replies contain =.id=Item internal number property.

To me it’s bug that “print with .query” doesn’t work… but I think the /getall will avoid. e.g. if it’s “alias for print” then it should do same thing, but here it doesn’t…

Sorry I think your problem is just putting a single quote around the URL & I’d use “Content-Type”, not just lowercased version, just to be safe.

curl -k -u admin:12345678 -X POST ‘https://10.2.5.1:10443/rest/tool/netwatch/print’ --data ‘{“.query”: [“host=10.2.5.200”]}’ -H “Content-Type: application/json”

sorry for delay.

i confirm in linux ( almalinux 8.8 ) with curl

curl 7.61.1 (x86_64-redhat-linux-gnu) libcurl/7.61.1 OpenSSL/1.1.1k zlib/1.2.11 brotli/1.0.6 libidn2/2.2.0 libpsl/0.20.2 (+libidn2/2.2.0) libssh/0.9.6/openssl/zlib nghttp2/1.33.0

works fine all commands…

curl -k -u admin:12345678 -X POST https://x.x.x.x:10443/rest/tool/netwatch/print | jq .

and also

curl -k -u admin:12345678 -X POST https://x.x.x.x:10443/rest/tool/netwatch/getall | jq .

same result

works also

curl -k -u admin:12345678 -X POST https://x.x.x.x:10443/rest/tool/netwatch/print --data '{".query": ["host=1.1.1.1"]}' -H "content-type: application/json" | jq . | grep status

and also

curl -k -u admin:12345678 -X POST https://x.x.x.x:10443/rest/interface/wifiwave2/registration-table/print --data '{".query": ["ssid=WIFI GUEST"], "count-only": true}' -H "content-type: application/json" | jq .

of course you can omit | jq .

i try with hap ac2 (ROS 7.11.2) and hap ax2 (ROS 7.11.2)

So it’s working now?

I really would be careful with the quotes on windows. " " isn’t ‟ ” — you’ll note the subtle “smart quotes”…

And I use a single quotes ’ ‘ around the URL on windows too: http…/netwatch/print' — windows paths are weird.

Can’t say either are your problem, but those are the two I know to watch for on Windows.

yes, for comfort when i approach api i used windows,
but my goal is use on linux because i want to use with zabbix server (so on linux).

practically my problem is solved because i use linux.
but if someone want to use on windows still have problem… i think is quote / double quote / ecc…