pat
January 27, 2023, 10:23am
1
Think I’ll need some help with this one.
I understand (I think) how the filters are build, and how they work. But it’s not so clear how to reference the asset in the filter.
I want to get all observation logs connected to a specific asset.
What till the [PATH] be in this case?
1 Like
When you say connected, do you mean referenced by the logs’ asset field? Or are you also trying to include assets that are referenced as locations, as quantity adjustments, etc?
2 Likes
If you just mean the logs’ asset field, you can do one of these;
https://example.farm/api/log/activity?filter[asset.id]=51550d0b-05b3-40fa-b875-62a04e5f3079
https://example.farm/api/log/activity?filter[asset.meta.drupal_internal__target_id]=1234
https://example.farm/api/log/activity?filter[asset.drupal_internal__id]=1234
3 Likes
Similarly for locations and quantities;
https://example.farm/api/log/activity?filter[location.id]=51550d0b-05b3-40fa-b875-62a04e5f3079
https://example.farm/api/log/activity?filter[location.meta.drupal_internal__target_id]=1234
https://example.farm/api/log/activity?filter[location.drupal_internal__id]=1234
https://example.farm/api/log/activity?filter[quantity.inventory_asset.id]=51550d0b-05b3-40fa-b875-62a04e5f3079&include=quantity
https://example.farm/api/log/activity?filter[quantity.inventory_asset.meta.drupal_internal__target_id]=1234&include=quantity
https://example.farm/api/log/activity?filter[quantity.inventory_asset.drupal_internal__id]=1234&include=quantity
To do all those at the same time - i.e. find logs referencing an asset via any of those fields - you can combine them all into a single query;
https://example.farm/api/log/activity?
filter[any-group][group][conjunction]=OR
&filter[by-asset][condition][path]=asset.id
&filter[by-asset][condition][value]=51550d0b-05b3-40fa-b875-62a04e5f3079
&filter[by-asset][condition][memberOf]=any-group
&filter[by-location][condition][path]=location.id
&filter[by-location][condition][value]=51550d0b-05b3-40fa-b875-62a04e5f3079
&filter[by-location][condition][memberOf]=any-group
&filter[by-quantity][condition][path]=quantity.inventory_asset.id
&filter[by-quantity][condition][value]=51550d0b-05b3-40fa-b875-62a04e5f3079
&filter[by-quantity][condition][memberOf]=any-group
Obviously, you’d have to repeat whichever query suites your use-case for each of the log types and possibly combine the results somehow.
3 Likes
pat
January 27, 2023, 4:00pm
5
Symbioquine:
If you just mean the logs’ asset field, you can do one of these;
https://example.farm/api/log/activity?filter[asset.id]=51550d0b-05b3-40fa-b875-62a04e5f3079
https://example.farm/api/log/activity?filter[asset.meta.drupal_internal__target_id]=1234
https://example.farm/api/log/activity?filter[asset.drupal_internal__id]=1234
That’s the one.
Many thanks for great examples.
2 Likes