# Load the libraries
import requests
from requests.auth import HTTPBasicAuth
import pandas as pd
# Define the API parameters setting
="how to protect the tomato from downy mildew"
query
# Define the url of the API
= "https://www.api.automaticfarmsolutionwebapp.com/AFS/DigitalAgronomyConsultant?query="+query
url
# Set the useremail & Password
="useremail"
USEREMAIL="apikey"
APIKEY
# Set the headers for the request
= {
headers "Content-Type": "application/json"
}
# Make the POST request
= requests.post(url,
response =headers,
headers=HTTPBasicAuth(USEREMAIL, APIKEY))
auth
# Convert from response to json
= response.json()
data
# Convert from json to pandas
= pd.DataFrame(data)
df
# Let's see the first 5 agricultural products
df.head()
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:
- USEREMAIL
- APIKEY
- query, the questions that you want to make to the digital agronomy consultant
With your information and let’s try out the API.
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:
- USEREMAIL
- APIKEY
- 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
="how to protect the tomato from downy mildew"
query
# Define the url of the API
<- paste0("https://www.api.automaticfarmsolutionwebapp.com/AFS/DigitalAgronomyConsultant?query=", query)
api_url
<-str_remove_all(api_url, pattern = " ")
api_url
# Set the useremail & Password
="useremail"
USEREMAIL="apikey"
APIKEY
# Get the start time to API Call
tic()
# Make the POST request
<- POST(
r
api_url,::authenticate(
httruser = 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
::status_code(r) httr
[1] 200
# Print out the list of the Phytofarmaceutical products
<- httr::content(r, as = "text", type = "application/json", encoding="UTF-8")
cont <-jsonlite::fromJSON(cont) %>% as.data.frame
contgt(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:
- USEREMAIL
- APIKEY
- 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