Extract specific data with API

Hi,

When using the high level API call FarmOS returns the full dataset. Eg https://myfarm.farmos.net//log.json?type=farm_activity gives all the activities.

I want to extract specific data using the API’s. Example

  1. Extract the activity data for a specific date or a specific asset. OR
  2. Extract Harvest data for a particular animal on a specific date

Secondly, how can sensor data be extracted using API and search criteria as listed above.

Please help with the syntax to do this.

Thanks!
Rajesh

1 Like

Hi @Rajesh - you might find what you’re looking for in these two documentation pages:

General farmOS API: https://farmos.org/development/api/

Sensor Listener API: https://farmos.org/guide/assets/sensors/#farm-sensor-listener

With regard to your specific examples:

Extract the activity data for a specific date or a specific asset.

Logs can be filtered by asset ID using log.json?asset=[asset-id]

Logs can be filtered similarly with their timestamp property - but right now it’s tricky to query logs with a specific date via the API because logs are stored with a timestamp, and the RESTful Web Services module (which provides the farmOS API) does not support “greater than” or “less than” filters in URL queries. My hope is that filtered queries like this will be much easier in farmOS 2.0 with the GraphQL module (work in progress).

There is a patch available for the RESTful Web Services module that is marked as “Needs Review” - if that is merged into the project then it would allow us more flexibility in farmOS 1.x: https://www.drupal.org/project/restws/issues/1910294

how can sensor data be extracted using API and search criteria as listed above

Sensor data has it’s own API (different from logs), which does support timestamp ranges. For more details, see https://farmos.org/guide/assets/sensors/#pulling-data-from-a-listener

1 Like

One way to do this would be to request all the logs for the given animal, and then iterate through them and filter out dates that don’t apply in your own code.

Thanks for the response Mike!

1 Like