azure-sdk-for-js/sdk/agrifood/agrifood-farming-rest
Jeremy Meng a28e8f0795 [EngSys] move to vendored version of cross-env via dev-tool
***NO_CI***

- apply the transformation

- update samples' README
2024-11-02 00:48:06 +00:00
..
review [eslint-plugin] add rule "@typescript-eslint/consistent-type-imports": "warn" 2024-10-30 15:48:52 +00:00
samples [EngSys] move to vendored version of cross-env via dev-tool 2024-11-02 00:48:06 +00:00
samples-dev [EngSys] standardize OSS copyright header 2024-08-27 13:01:38 -07:00
src [eslint-plugin] add rule "@typescript-eslint/consistent-type-imports": "warn" 2024-10-30 15:48:52 +00:00
swagger Post release automated changes for agrifood releases (#24978) 2023-03-20 20:12:56 +00:00
test/public [eslint-plugin] add rule "@typescript-eslint/consistent-type-imports": "warn" 2024-10-30 15:48:52 +00:00
CHANGELOG.md Post release automated changes for agrifood releases (#24978) 2023-03-20 20:12:56 +00:00
README.md Increment minimum supported node version to 16 2023-10-09 21:09:54 +00:00
api-extractor.json FarmBeats REST Client (#15209) 2021-05-26 16:13:59 -07:00
assets.json migrate rlc test recordings (#26427) 2023-07-07 16:50:30 +08:00
eslint.config.mjs Apply automated migration to eslint flat config 2024-08-22 11:43:19 -07:00
karma.conf.js [EngSys] standardize OSS copyright header 2024-08-27 13:01:38 -07:00
package.json [EngSys] move to vendored version of cross-env via dev-tool 2024-11-02 00:48:06 +00:00
sample.env [AgriFood] Updating client for 2022-11-01-preview API version (#23189) 2023-02-23 21:54:21 +00:00
tsconfig.json [EngSys] remove tsconfig.package.json 2024-07-16 13:27:25 +00:00

README.md

Microsoft Azure Data Manager for Agriculture REST client library for JavaScript

Microsoft Azure Data Manager for Agriculture is a B2B PaaS offering from Microsoft that makes it easy for AgriFood companies to build intelligent digital agriculture solutions on Azure.Data Manager for Agriculture acquire, aggregate, and process agricultural data from various sources (farm equipment, weather, satellite) without the need to invest in deep dataengineering resources. Customers can build SaaS solutions on top of Data Manager for Agriculture and leverage first class support for model building to generate insights at scale.

Use Data Manager for Agriculture client library for JavaScript to do the following.

  • Create & update parties, 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

Key links:

Getting started

Currently supported environments

Prerequisites

Install the @azure-rest/agrifood-farming package

Install the Data Manager for Agriculture rest client library for JavaScript with npm:

npm install @azure-rest/agrifood-farming

Create and authenticate a Microsoft Azure Data Manager for Agriculture 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.

  • Party - 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 party as the root. The hierarchy includes Party -> 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 Party

Once you have authenticated and created the client object as shown in the Authenticate the client section, you can create a party within the Data Manager for Agriculture resource like this:

import FarmBeats, { isUnexpected } from "@azure-rest/agrifood-farming";
import { DefaultAzureCredential } from "@azure/identity";

const client = FarmBeats(
  "https://<farmbeats resource name>.farmbeats.azure.net",
  new DefaultAzureCredential()
);

const partyId = "test_party";
const result = await farmbeatsClient.path("/parties/{partyId}", partyId).patch({
  body: {
    name: "Contoso Party",
    description: "Your custom party 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 (isUnexpected(result)) {
  throw result.body.error;
}

const party = result.body;
console.log(`Created Party: ${party.name}`);

List Parties

import FarmBeats, { isUnexpected } from "@azure-rest/agrifood-farming";
import { DefaultAzureCredential } from "@azure/identity";

const client = FarmBeats(
  "https://<farmbeats resource name>.farmbeats.azure.net",
  new DefaultAzureCredential()
);

const response = await farmbeatsClient.path("/parties").get();

if (isUnexpected(response)) {
  throw response.body.error;
}

const parties = paginate(farmbeatsClient, response);

// Log each party id
for await (const party of parties) {
  const partyOutput = party;
  console.log(partyOutput.id);
}

Additional Samples

For additional samples, please refer to the [samples folder][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.

Impressions