API to retrieve record count?

Can’t seem to find it anyway; is it possible to call an API to get the count of a DocType given a set of conditions?

I tried:

api/resource/User?fields=["count (*)"]

and I get:

Field not permitted in query: count (*)

If not possible I guess I need to get all needed records in JSON and count it from there…

Anyone please?

Hi @charleslcso,

You haven’t mentioned the field name.

I haven’t any more idea but try and check it.

import requests

response = requests.get('https://your-erpnext-instance.com/api/resource/User?fields=["name"]&filters=[["enabled", "=", "1"]]')
data = response.json()
record_count = len(data['data'])

print("Total Record:", record_count)


Otherwise, check it.

/api/resource/User?fields=["count(name)"]&filters=[["enabled", "=", "1"]]

I hope this helps.

Thank You!


This works!

Nice and thank you!