Digital Agronomist

In this part we will focus on the endpoint “AFS/DigitalAgronomyConsultant” endpoint, which allow the user to able to ask questions of an always-on digital agronomy consultant

Python

In this example we will test the DigitalAgronomyConsultant which allow the user to get data related to the soil.

To use the following example you have to replace:

  1. USEREMAIL
  2. APIKEY
  3. query, the questions that you want to make to the digital agronomy consultant

With your information and let’s try out the API.

# Load the libraries
import requests
from requests.auth import HTTPBasicAuth
import pandas as pd

# Define the API parameters setting

query="how to protect the tomato from downy mildew"

# Define the url of the API

url = "https://www.api.automaticfarmsolutionwebapp.com/AFS/DigitalAgronomyConsultant?query="+query

# Set the useremail & Password

USEREMAIL="useremail"
APIKEY="apikey"

# Set the headers for the request
headers = {
    "Content-Type": "application/json"
}

# Make the POST request

response = requests.post(url, 
                         headers=headers,
                         auth=HTTPBasicAuth(USEREMAIL, APIKEY))

# Convert from response to json

data = response.json()

# Convert from json to pandas

df = pd.DataFrame(data)

# Let's see the first 5 agricultural products

df.head()

R

In this example we will test the DigitalAgronomyConsultant which allow the user to get data related to the soil.

To use the following example you have to replace:

  1. USEREMAIL
  2. APIKEY
  3. query, the questions that you want to make to the digital agronomy consultant

With your information and let’s try out the API.

# import libraries

library(tictoc)
library(httr)
library(gt)
library(tidyverse)

# Define the API parameters setting

query="how to protect the tomato from downy mildew"

# Define the url of the API

api_url <- paste0("https://www.api.automaticfarmsolutionwebapp.com/AFS/DigitalAgronomyConsultant?query=", query)

api_url<-str_remove_all(api_url, pattern = " ")

# Set the useremail & Password

USEREMAIL="useremail"
APIKEY="apikey"

# Get the start time to API Call

tic()

# Make the POST request

r <- POST(
  api_url,
  httr::authenticate(
    user = Sys.getenv(USEREMAIL),
    password = Sys.getenv(APIKEY)
  )
)

# Print out the seconds needed to create the prescription map

print("The API needed:")
[1] "The API needed:"
toc()
5.66 sec elapsed
# Get the status of the request

httr::status_code(r)
[1] 200
# Print out the list of the Phytofarmaceutical products

cont <- httr::content(r, as = "text", type = "application/json", encoding="UTF-8")
cont<-jsonlite::fromJSON(cont) %>% as.data.frame
gt(cont)
.
1. Remove any infected plants from the garden. 2. Water at the base of the plants instead of from overhead. 3. Avoid watering late in the day. 4. Increase air circulation in the garden or greenhouse by opening windows or using fans. 5. Space plants further apart. 6. Provide adequate drainage and reduce any standing water around the plants. 7. Use a fungicide or biological control. 8. Rotate tomato varieties with unrelated crops.

Node.js

In this example we will test the DigitalAgronomyConsultant which allow the user to get data related to the soil.

To use the following example you have to replace:

  1. USEREMAIL
  2. APIKEY
  3. query, the questions that you want to make to the digital agronomy consultant

With your information and let’s try out the API.

// load libraries

const axios = require('axios');

// Set username e apikey

const username = 'XXXXXXXXXXXXXX';
const password = 'XXXXXXXXXXXXXX';

// set the apiurl

const apiurl='https://www.api.automaticfarmsolutionwebapp.com/AFS/DigitalAgronomyConsultant?query=';

// set the product_name parameter

const query="how to protect the tomato from downy mildew";

// set the apiendpoint

const url = apiurl.concat(query)

const options = {
  method: 'post',
  url: url,
  auth: {
    username: username,
    password: password,
  },
};

axios(options)
  .then(response => {
    console.log('Risposta JSON:', response.data);
  })
  .catch(error => {
    console.error('Errore:', error.message);
  });

Easy - Fast - Customizable

Back to top