IN filter with REST Api

Hello,

Is it possible to use an IN filter with the rest api ?
Something like

frappe.get_all('Project', in_filters=[['Status', ['Open','Closed']]], fields=['name', 'description'])

Thanks,
Benjamien

In api call filters like
https://[“your host name”]/api/resource/Project?filters=[[“status”, “in”,[“Open”,“Closed”]]]&fields=[“name”,“notes”]

That does not seems to work.

I get a message saying “Doctype not found’”

Hi @Benjamien,

Please apply and check it.

frappe.get_all("Project", filters= {"status": ["in", ["Open", "Closed"]] }, fields= ['name', 'notes'])

the field name must be in a small case.
like Status → status

Full syntax for:

from frappe import get_all

filters = {
    "status": ["in", ["Open", "Closed"]]
}

fields = ["name", "notes"]

projects = get_all("Project", filters=filters, fields=fields)

print(projects)

Please set your fieldname and status your according.

Hope you understand.
Thank You!

1 Like

Thank you. This works if I hard-code the filter.
But I’m trying to use this with the api through a whitelist method.
How can I get a list of values send to the whitelist method so it can be used in the filter ?

Please use it.
You can use it in the whitelist method.

Thanks

How can I get a list as parameter in the whitelist method.
I now get a string as parameter and that doesn’t work in the filter
The ids string looks like this: “PROJ-0002”,“PROJ-0003”,“PROJ-0021”,“PROJ-0022”

‘projects’ is empty

@frappe.whitelist()
def get_projectlist(ids):
filters = {
“name”: [“in”,ids]
}

fields = [“name”, “project_name”, “customer”]

projects = frappe.get_all(“Project”, filters=filters, fields=fields)
return projects

Please check its Database API

Thanks

I have read that, but I’m still struggling.

Tried different approaches:

@frappe.whitelist()
def get_projectlist(ids):
data = frappe.db.sql(“”“SELECT name, project_name, customer FROM tabProject WHERE name in (%s)”“”, ids)
return data

and

@frappe.whitelist()

def get_projectlist(ids):

filters = {“name”: [“in”, [ids]] }

fields = [“name”, “project_name”, “customer”]

projects = frappe.get_all(“Project”, filters=filters, fields=fields)

return projects

This is my URL:

[ERPNEXT URL]/api/method/betoled_integration.get_projectlist?ids={“PROJ-0002”,“PROJ-0003”,“PROJ-0021”,“PROJ-0022”,“PROJ-0032”,“PROJ-0028”,“PROJ-0036”,“PROJ-0037”,“PROJ-0038”,“PROJ-0039”,“PROJ-0024”,“PROJ-0034”,“PROJ-0040”,“PROJ-0041”}
I tried both with single and double quotes.

Please check it.

I’m sorry, but I don’t see how this applies to my question ?

What I’m trying to do is get all projects where the name is in a list of names.
So get alle project where the name is in (“PROJ-0002”,“PROJ-0003”,“PROJ-0021”,“PROJ-0022”) for example.
Therefor I need to get the list of names as a parameter to the whitelist method, and in the frappe.get_all method or the frappe.db.sql query
And that is the part that I can’t get working.

I got it working

[ERPNEXT URL]/api/resource/Project?fields=[“name”,“project_name”,“customer”]&filters=[[“Project”,“name”,“in”,“PROJ-0002,PROJ-0003,PROJ-0021,PROJ-0022,PROJ-0032,PROJ-0028,PROJ-0036,PROJ-0037,PROJ-0038,PROJ-0039,PROJ-0024,PROJ-0034,PROJ-0040,PROJ-0041”]]

1 Like