SuiteCRM V8 API "AND" and "OR" in the same query

I’m trying to do a filter with API V8 that searches the title and description for a word and returns where its found in the title or description. So far I’ve got that, but need to add an AND that the results are only status = Published.

I’m not sure if its possible or I just don’t know the nomenclature. Here’s what I’ve got so far:

{{suitecrm.url}}/legacy/Api/V8/module/AOK_KnowledgeBase?fields[AOK_KnowledgeBase]=name,description,status&sort=name&filter[operator]=or&filter[name][like]=%settings%&filter[description][like]=%settings%

I get all results where name or desc contains “settings” but I want to limit to published articles only. Is this possible? Anyone done this?

if I add
&filter[operator]=and&filter[status][eq]=published_public

It seems to change the whole expresson to AND and I only get kb articles with settings in title AND descriptons AND published.

I think it should work:

{{suitecrm.url}}/legacy/Api/V8/module/AOK_KnowledgeBase
?fields[AOK_KnowledgeBase]=name,description,status
&sort=name
&filter[operator]=and
&filter[1][operator]=or
&filter[1][name][like]=%settings%
&filter[1][description][like]=%settings%
&filter[2][status][eq]=published_public

LOL, this is one of those cases where ChatGPT has no idea what its talking about.

haha okay, I do not know. Maybe you have use two APIs or something like this:

GET {{suitecrm.url}}/legacy/Api/V8/module/AOK_KnowledgeBase?
fields[AOK_KnowledgeBase]=name,description,status&
sort=name&
filter[operator]=and&
filter[status][eq]=published_public&
filter[name][like]=%settings%&
filter[description][like]=%settings%

That is a query for pubic AND settings in name AND settings in description.

What i want is public AND (settings in name OR settings in description)

Try out if you can use brackets in the API call. It is just a wild guess haha.

No you cannot add brackets. I’m really looking for someone who has experience with this and has tried it and can either confirm NO it’s not possible or YES, here’s how to do it.

Hi Paul,

I believe you’re right.
The documentation is very thin there, but the code might leave some clues: SuiteCRM-Core/public/legacy/lib/API/JsonApi/v1/Filters at 4b79be7c7113af3d285f5eb537977ab336eef786 · SuiteCRM/SuiteCRM-Core · GitHub

Since it’s not possible to nest filters via the API, the logic shouldn’t work:
Is it (or(and)) or (and(or))
I’ve tried with mixing and and or and just moving filters to the front or to the rear, but the output wasn’t as expected.

Here, you might need to fallback to GraphQL, if you wan to retrieve in one request.

Thanks for trying @BastianHammer I came to the same conclusion. I tried a 100 different ways and concluded you can use AND or OR but not both. This is unfortunate because it forces me to do processing on the client side I don’t want to. However, I mostly got working what I needed to with V8.

I didn’t want to go GraphQL route because I want what I’m working on to be backwards compatible to SuiteCRM 7.

Mostly I’ve found the V8 API pretty robust, except for filtering records, being able to do more complex queries would be beneficial.

I know I can write my own endpoint, but really wanted the applicaiton I’m working on to not require any SuiteCRM code customizations.