Customizing Data Sync

Customizing Data Sync

Customizing Data Sync

By default, when a credential is added to a Leaf user, all available data is fetched. However, for certain use cases, it is essential to be able to customize exactly which data will be synchronized to Leaf.

This document outlines how to customize the data that Leaf retrieves at various hierarchical levels.

Filtering by organization

For providers with data organized by organization or company, Leaf allows the selection of specific organizations and limits data sync to just those, reducing unnecessary data.

1 - Configuration

Enabling organization custom data synchronization is possible using the organizationsDataSync configuration.

organizationsDataSync=SELECTED_ONLY

It can be set at API Owner or Leaf user level and it is essential to be defined before the credentials attachment.

2 - Get all organizations

Info: it is available for John Deere only.

After connecting a new John Deere credential, all the organizations available on the provider side can be retrieved using the organizations endpoint.

GET
https://api.withleaf.io/services/usermanagement/api/users/{leafUserId}/{provider}/organizations

Response

[
{
"providerOrgId": "01011000",
"providerOrgName": "Leaf Organization",
"status": "SELECTED"
},
{
"providerOrgId": "123321",
"providerOrgName": "Agriculture Organization",
"status": "PREVIEW"
}
]

With the organizationsDataSync configuration set as "SELECTED_ONLY" all organizations, initially, will have the status "PREVIEW”. It means no other additional data like Field Boundaries or Operations will be fetched from that organization until it is changed to "SELECTED".

The organization selection can be done using the PATCH organization endpoint.

PATCH
https://api.withleaf.io/services/usermanagement/api/users/{leafUserId}/{provider}/organizations/{providerOrgId}/SELECTED

Response:

{
"providerOrgId": "123321",
"providerOrgName": "Agriculture Organization",
"status": "SELECTED"
}

After this request, all data related to the selected organization will be synchronized. The sync process starts immediately after the request, and the fields should be fetched almost immediately.

Filtering by fields

Leaf API enables the selection of fields for scenarios where growers don't want to integrate all their fields and related data. It is possible to use the customDataSync configuration.

customDataSync=true

When it is enabled, all fields are fetched from the provider as "PREVIEW”, which means, it has the attributes but no boundary associated with it. For Deere and Climate, the machine operations from those fields are not fetched as well.

This way, for field selection, the resources can be listed following these instructions:

1 - Listing resources

Important: if the organizationsDataSync configuration is enabled, make sure the organization is selected before checking this endpoint.

Users can select which resources to synchronize including fields, farms, and growers:

Listing fields
GET
https://api.withleaf.io/services/fields/api/fields
view raw list_fields.txt hosted with ❤ by GitHub
Listing farms
GET
https://api.withleaf.io/services/fields/api/farms
view raw list_farms.txt hosted with ❤ by GitHub
Listing growers
GET
https://api.withleaf.io/services/fields/api/growers

You can combine the resources you select, for example using a UI:

Leaf, data infrastructure for agriculture

2 - Enabling Fields

After selecting resources, you can enable fields individually or by grower ID:

Enabling a single field

This endpoint allows a single field to be marked to be synchronized in the next synchronization window.

POST
https://api.withleaf.io/services/fields/api/users/{leafUserId}/fields/{id}/enableSync
Enabling fields by grower list

This endpoint allows multiple fields to be synchronized based on a list of the grower's IDs (id from /growers endpoint).

POST
https://api.withleaf.io/services/fields/api/growers/enableSync

Payload: list of the Leaf grower's ID

{
"growerIds": ["999999", "888888"]
}

Important Notes

New fields are fetched in PREVIEW mode. To sync fields from organizations where data sync is needed, you must enable them. You can either enable a single field or enable fields by grower (see above for details on these).

Preview mode is applied to all providers, so enabling the sync for all desired fields is necessary.

For cases where the endpoint to enable fields per grower is used, avoid making multiple calls sending one grower at a time, instead send them as a list in the payload. It will avoid unnecessary synchronizations.

This tutorial serves as an alternative solution to an organization management feature planned for future releases.

organizationDataSync x customDataSync

organizationDataSync SELECTED_ONLY

customDataSync TRUE

Only SELECTED provider organizations will be retrieved.
All fields will be created in PREVIEW mode and will need to have sync enabled in order for data to be retrieved and processed.

organizationDataSync SELECTED_ONLY

customDataSync TRUE

Only SELECTED provider organizations will be retrieved.
All fields will be created in PREVIEW mode and will need to have sync enabled in order for data to be retrieved and processed.

Ready to begin?

Get a Demo and Start Building Today!