How do I, if possible, filter my activity logs by category?
log/activity?filter[category]=71
71 is my drupal inernal id for the category
How do I, if possible, filter my activity logs by category?
log/activity?filter[category]=71
71 is my drupal inernal id for the category
You can use: /api/log/activity?filter[category.name]=Animals
to filter by the name of the category.
This has a lot of examples: Filtering | JSON:API module | Drupal Wiki guide on Drupal.org
Perfect. Thanks
filter[category.drupal_internal__id]=71
if you have the ID!
I knew there was a way for that too…
I’ve been trying to learn more about filters, but I seem to miss something.
I would say this is correct filter for between dates, but all I get is “Allowed conjunctions: AND, OR.”
msg.payload =
"filter[filtergroup][group][conjuction]=AND"+
"filter[today][condition][path]=timestamp&" +
"filter[today][condition][operator]=%3E&"+
"filter[today][condition][value]=" + unixTimestamp + "&"+
"filter[today][condition][memberof]=filtergroup&"+
"filter[tomorrow][condition][path]=timestamp&" +
"filter[tomorrow][condition][operator]=%3C&" +
"filter[tomorrow][condition][value]=" + (unixTimestamp+84000) + "&"+
"filter[tomorrow][condition][memberof]=filtergroup";
Hmm the only little thing I notice is that your example uses memberof
but the Drupal.org example uses memberOf
(capital “O”). Does that make a difference?
Nah… Then I get “You must provide a valid filter condition. Check that you have set the required keys for your filter.” (Error 500)
Have you tried testing these filters in the browser address bar, or only in Node Red? It may be worth getting it working in the browser as a baseline first, just to be sure there isn’t anything weird going on (formatting, escaping, or otherwise). I don’t expect there would be, but probably better to start simple.
Oh wait are you missing an &
after the AND
?
AH! I found the issue… you spelled conjunction
wrong.
This appears to work in the browser address bar: ?filter[filtergroup][group][conjunction]=AND&filter[today][condition][path]=timestamp&filter[today][condition][operator]=%3E&filter[today][condition][value]=1672835969&filter[today][condition][memberOf]=filtergroup&filter[tomorrow][condition][path]=timestamp&filter[tomorrow][condition][operator]=%3C&filter[tomorrow][condition][value]=1672922369&filter[tomorrow][condition][memberOf]=filtergroup
Ahh… it’s always in the details. Thanks.
Hmm… if I run this filter in the browser, it doesn’t filter anything.
How is that possible? Filters has worked there before.
It works now from Node-Red at least.
Actually, it would be a nice feature if the filter in farmOS could generate such filters.
I tried that at first, but that only works for the table view.
Ah… by “this works” I meant “this doesn’t error”. I didn’t actually examine the results. Maybe my timestamps were wrong or something. As long as it’s working in Node Red now that’s what matters.
Yea those are two different systems. Views (which we defined) vs JSON:API (which comes “out of the box”). No relation, I’m afraid.
Yes indeed. But I run filters in url sometimes. And now it seems not working.
logs/activity?filter[status]=pending
Works on the API, but not in the log view.
It’s not critical.
Ah sorry I should have been more specific… that query string I pasted above “works” when you tack it onto the end of an API endpoint (eg: /api/log/activity
). It does NOT work if you tack it onto the end of the UI path /logs/activity
.
Yea those are two different systems. Views (which we defined) vs JSON:API (which comes “out of the box”). No relation, I’m afraid.
Ah… thanks for clarifying
Hey I’ve been trying to learn API filtering too and thought this was a good spot for this question.
I am having issues when filtering for log categories that don’t have parents or have as the parent.
“/api/taxonomy_term/log_category?filter[parent.name][value]=Admin%20Work”
Works as expected to gives me all categories with the parent Admin Work but I am trying to filter for all Parent categories.
I would expect “/api/taxonomy_term/log_category?filter[parent.id][value]=virtual” to work but I get no results or errors.
Anyone have any thoughts?