@azure-rest/agrifood-farming v1.0.0-beta.2
Azure FarmBeats REST client library for JavaScript
FarmBeats is a B2B PaaS offering from Microsoft that makes it easy for AgriFood companies to build intelligent digital agriculture solutions on Azure. FarmBeats allows users to acquire, aggregate, and process agricultural data from various sources (farm equipment, weather, satellite) without the need to invest in deep data engineering resources. Customers can build SaaS solutions on top of FarmBeats and leverage first class support for model building to generate insights at scale.
Use FarmBeats client library for JavaScript to do the following.
- Create & update farmers, farms, fields, seasonal fields and boundaries.
- Ingest satellite and weather data for areas of interest.
- Ingest farm operations data covering tilling, planting, harvesting and application of farm inputs.
Please rely heavily on the service's documentation and our REST client docs to use this library
Source code | Package (NPM) | API reference documentation| Product documentation
Getting started
Currently supported environments
- Node.js version 14.x.x or higher
Prerequisites
- You must have an Azure subscription.
- AgriFood (FarmBeats) resource - Install FarmBeats
Install the @azure-rest/agrifood-farming
package
Install the Azure FarmBeats rest client library for JavaScript with npm
:
npm install @azure-rest/agrifood-farming
Create and authenticate a FarmBeats
REST Client
To use an Azure Active Directory (AAD) token credential, provide an instance of the desired credential type obtained from the @azure/identity library.
To authenticate with AAD, you must first npm
install @azure/identity
.
After setup, you can choose which type of credential from @azure/identity
to use.
As an example, DefaultAzureCredential
can be used to authenticate the client:
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
Use the returned token credential to authenticate the client:
import FarmBeats from "@azure-rest/agrifood-farming";
import { DefaultAzureCredential } from "@azure/identity";
const client = FarmBeats(
"https://<farmbeats resource name>.farmbeats.azure.net",
new DefaultAzureCredential()
);
Key concepts
REST Client
This client is one of our REST clients. We highly recommend you read how to use a REST client here.
Farm Hierarchy
Farm hierarchy is a collection of below entities.
- Farmer - is the custodian of all the agronomic data.
- Farm - is a logical collection of fields and/or seasonal fields. They do not have any area associated with them.
- Field - is a multi-polygon area. This is expected to be stable across seasons.
- Seasonal field - is a multi-polygon area. To define a seasonal boundary we need the details of area (boundary), time (season) and crop. New seasonal fields are expected to be created for every growing season.
- Boundary - is the actual multi-polygon area expressed as a geometry (in geojson). It is normally associated with a field or a seasonal field. Satellite, weather and farm operations data is linked to a boundary.
- Cascade delete - Agronomic data is stored hierarchically with farmer as the root. The hierarchy includes Farmer -> Farms -> Fields -> Seasonal Fields -> Boundaries -> Associated data (satellite, weather, farm operations). Cascade delete refers to the process of deleting any node and its subtree.
Scenes
Scenes refers to images normally ingested using satellite APIs. This includes raw bands and derived bands (Ex: NDVI). Scenes may also include spatial outputs of an inference or AI/ML model (Ex: LAI).
Farm Operations
Fam operations includes details pertaining to tilling, planting, application of pesticides & nutrients, and harvesting. This can either be manually pushed into FarmBeats using APIs or the same information can be pulled from farm equipment service providers like John Deere.
Examples
Create a Farmer
Once you have authenticated and created the client object as shown in the Authenticate the client section, you can create a farmer within the FarmBeats resource like this:
import FarmBeats from "@azure-rest/agrifood-farming";
import { DefaultAzureCredential } from "@azure/identity";
const client = FarmBeats(
"https://<farmbeats resource name>.farmbeats.azure.net",
new DefaultAzureCredential()
);
const farmerId = "test_farmer";
const result = await client.path("/farmers/{farmerId}", farmerId).patch({
body: {
name: "Contoso Farmer",
description: "Your custom farmer description here",
status: "Active",
properties: { foo: "bar", "numeric one": 1, "1": "numeric key" },
},
// Set the content-type of the request
contentType: "application/merge-patch+json",
});
if (result.status !== "200" && result.status !== "201") {
throw result.body.error;
}
console.log(`Created Farmer: ${result.body.name}`);
List Farmers
import FarmBeats from "@azure-rest/agrifood-farming";
import { DefaultAzureCredential } from "@azure/identity";
const client = FarmBeats(
"https://<farmbeats resource name>.farmbeats.azure.net",
new DefaultAzureCredential()
);
const result = await client.path("/farmers").get();
if (result.status !== "200") {
throw result.body.error?.message;
}
let farmers: Farmer[] = result.body.value ?? [];
let skipToken = result.body.skipToken;
// Farmer results may be paginated. In case there are more than one page of farmers
// the service would return a skipToken that can be used for subsequent request to get
// the next page of farmers. Here we'll keep calling until the service stops returning a
// skip token which means that there are no more pages.
while (skipToken) {
const page = await client.path("/farmers").get({ queryParameters: { $skipToken: skipToken } });
if (page.status !== "200") {
throw page.body.error;
}
farmers.concat(page.body.value ?? []);
skipToken = page.body.skipToken;
}
// Lof each farmer id
farmers.forEach((farmer) => {
console.log(farmer.id);
});
Additional Samples
For additional samples, please refer to the samples folder
Troubleshooting
Logging
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the AZURE_LOG_LEVEL
environment variable to info
. Alternatively, logging can be enabled at runtime by calling setLogLevel
in the @azure/logger
:
import { setLogLevel } from "@azure/logger";
setLogLevel("info");
For more detailed instructions on how to enable logs, you can look at the @azure/logger package docs.
Next steps
Additional documentation
For more extensive documentation on the FarmBeats, see the FarmBeats documentation on docs.microsoft.com.
Contributing
If you'd like to contribute to this library, please read the contributing guide to learn more about how to build and test the code.
Related projects
2 days ago
3 days ago
4 days ago
7 days ago
8 days ago
9 days ago
10 days ago
14 days ago
15 days ago
16 days ago
17 days ago
18 days ago
22 days ago
1 month ago
2 months ago
3 months ago
3 months ago
4 months ago
4 months ago
4 months ago
5 months ago
6 months ago
6 months ago
7 months ago
8 months ago
8 months ago
7 months ago
7 months ago
7 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago