Filtering API by category

Good question. I think we can do most of this with the IS NULL and IS NOT NULL operator on the parent.id path. This works to filter to log category terms that do not have a parent: they are top level but may not actually have children terms that reference them.

Terms without a parent:

api/taxonomy_term/log_category?filter[parent-filter][condition][path]=parent.id&filter[parent-filter][condition][operator]=IS%20NULL

Terms that have a parent:

api/taxonomy_term/log_category?filter[parent-filter][condition][path]=parent.id&filter[parent-filter][condition][operator]=IS%20NOT%20NULL

If you need to know the children that reference them then you would need another request. And this gets complicated if you try to determine which terms are “Nested parents”… but perhaps you can filter by parent.id.parent.id ?

4 Likes

Terms without parents did the trick! I have a user prompt between the two filters so they are two separate requests anyway. Thanks for the help! I am using it in a farmOS API node in node red. It really cuts down on the function code node looping through all the categories to find the parent ones.

3 Likes


Are global variables not allowed in all types of node properties? I have a logID variable setup as global but this API call is not working. Is what I am trying to do not possible or is it my syntax?

1 Like

Hi @Zack, this is probably because of a Node-Red limitation.
I built the farmOS nodes that I think you are using. They are all just subflows and subflow properties are only read at runtime for the creation of that subflow instance so it’s not possible to use variables in this way.

One solution to your problem would be to copy the contents of the subflow to your main flow and hardcode your parameters (don’t do it in a subflow or you will effect all instances).

I may have a better look at this scenario later, but I’m on vacation at the moment.

Long term plan would be to write proper nodes in pure JS which can accept variables but that may be far down the line.

2 Likes