# Load the libraries
import requests
from requests.auth import HTTPBasicAuth
import pandas as pd
# Define the API parameters setting
="nitrogen"
nutrient
# Define the url of the API
= "https://www.api.automaticfarmsolutionwebapp.com/AFS/AvailableCrops?nutrient="+nutrient
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.get(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()
Nutrient Balance
In this part we will focus on four endpoint:
- “AFS/AvailableCrops” endpoint, which allow the user to get available crops for each nutrient suggestion
- “AFS/Nitrogen” endpoint, which allow the user to get fertilization nitrogen advice
- “AFS/Phosphorus” endpoint, which allow the user to get fertilization phosphorus advice
- “AFS/Potassium” endpoint, which allow the user to get fertilization potassium advice
AvailableCrops
Python
In this example we will test the AvailableCrops which allow the user to get available crops for each nutrient suggestion
To use the following example you have to replace:
- USEREMAIL
- APIKEY
- nutrient that you would like to get the list of available crops
R
In this example we will test the AvailableCrops which allow the user to get available crops for each nutrient suggestion
To use the following example you have to replace:
- USEREMAIL
- APIKEY
- nutrient that you would like to get the list of available crops
# import libraries
library(tictoc)
library(httr)
library(gt)
library(tidyverse)
# Define the API parameters setting
="nitrogen"
nutrient
# Define the url of the API
<- paste0("https://www.api.automaticfarmsolutionwebapp.com/AFS/AvailableCrops?nutrient=", nutrient)
api_url
# Set the useremail & Password
="useremail"
USEREMAIL="apikey"
APIKEY
# Get the start time to API Call
tic()
# Make the GETs request
<- GET(
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()
0.7 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
cont1:5,] cont[
[1] "Kiwi" "Garlic" "Apricot" "Orange" "Asparagus"
Node.js
In this example we will test the AvailableCrops which allow the user to get available crops for each nutrient suggestion
To use the following example you have to replace:
- USEREMAIL
- APIKEY
- nutrient that you would like to get the list of available crops
// 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/AvailableCrops?nutrient=';
// set the product_name parameter
const nutrient="nitrogen";
// set the apiendpoint
const url = apiurl.concat(nutrient)
const options = {
method: 'get',
url: url,
auth: {
username: username,
password: password,
,
};
}
axios(options)
.then(response => {
console.log('Risposta JSON:', response.data);
}).catch(error => {
console.error('Errore:', error.message);
; })
Nitrogen
Python
In this example we will test the Nitrogen which allow the user to get nitrogen fertilization advice for each crop
To use the following example you have to replace:
- USEREMAIL
- APIKEY
- cropanalyze, the crop that you to get the Nitrogen fertilization advice
- expectedyield, the yield expected for that crop in quintals per hectare (e.g. 60, 80)
- titlefertilizer, the percentage title of the nutrient within fertilizer you intend to use (10, 40)
# Load the libraries
import requests
from requests.auth import HTTPBasicAuth
import pandas as pd
# Define the API parameters setting
="Durum_wheat"
cropanalyze="60"
expectedyield="46"
titlefertilizer
# Define the url of the API
= "https://www.api.automaticfarmsolutionwebapp.com/AFS/Nitrogen?cropanalyze="+cropanalyze+"&expectedyield="+expectedyield+"&titlefertilizer="+titlefertilizer
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.get(url,
response =headers,
headers=HTTPBasicAuth(USEREMAIL, APIKEY))
auth
# Convert from response to json
= response.json()
data
# Convert from json to pandas
data
R
In this example we will test the Nitrogen which allow the user to get nitrogen fertilization advice for each crop
To use the following example you have to replace:
- USEREMAIL
- APIKEY
- cropanalyze, the crop that you to get the Nitrogen fertilization advice
- expectedyield, the yield expected for that crop in quintals per hectare (e.g. 60, 80)
- titlefertilizer, the percentage title of the nutrient within fertilizer you intend to use (10, 40)
library(tictoc)
library(httr)
library(gt)
library(tidyverse)
# Define the API parameters setting
="Durum_wheat"
cropanalyze="60"
expectedyield="46"
titlefertilizer
# Define the url of the API
<- paste0("https://www.api.automaticfarmsolutionwebapp.com/AFS/Nitrogen?cropanalyze=", cropanalyze,"&expectedyield=",expectedyield,"&titlefertilizer=",titlefertilizer)
api_url
# Set the useremail & Password
="useremail"
USEREMAIL="apikey"
APIKEY
# Get the start time to API Call
tic()
# Make the GETs request
<- GET(
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()
0.56 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
cont cont
.
1 297.3913
Node.js
In this example we will test the Nitrogen which allow the user to get nitrogen fertilization advice for each crop
To use the following example you have to replace:
- USEREMAIL
- APIKEY
- cropanalyze, the crop that you to get the Nitrogen fertilization advice
- expectedyield, the yield expected for that crop in quintals per hectare (e.g. 60, 80)
- titlefertilizer, the percentage title of the nutrient within fertilizer you intend to use (10, 40)
// 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/Nitrogen?cropanalyze=';
// set the product_name parameter
const cropanalyze="Durum_wheat";
const expectedyield="60";
const titlefertilizer="46";
// set the apiendpoint
const url = apiurl.concat(cropanalyze, "&expectedyield=", expectedyield, "&titlefertilizer=", titlefertilizer)
const options = {
method: 'get',
url: url,
auth: {
username: username,
password: password,
,
};
}
axios(options)
.then(response => {
console.log('Answer JSON:', response.data);
}).catch(error => {
console.error('Error:', error.message);
; })
Phosphorus
Python
In this example we will test the Phosphorus which allow the user to get nitrogen fertilization advice for each crop
To use the following example you have to replace:
- USEREMAIL
- APIKEY
- cropanalyze, the crop that you to get the Phosphorus fertilization advice
- expectedyield, the yield expected for that crop in quintals per hectare (e.g. 60, 80)
- titlefertilizer, the percentage title of the nutrient within fertilizer you intend to use (10, 40)
# Load the libraries
import requests
from requests.auth import HTTPBasicAuth
import pandas as pd
# Define the API parameters setting
="Wheat"
cropanalyze="60"
expectedyield="46"
titlefertilizer
# Define the url of the API
= "https://www.api.automaticfarmsolutionwebapp.com/AFS/Phosphorus?cropanalyze="+cropanalyze+"&expectedyield="+expectedyield+"&titlefertilizer="+titlefertilizer
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.get(url,
response =headers,
headers=HTTPBasicAuth(USEREMAIL, APIKEY))
auth
# Convert from response to json
= response.json()
data data
R
In this example we will test the Phosphorus which allow the user to get nitrogen fertilization advice for each crop
To use the following example you have to replace:
- USEREMAIL
- APIKEY
- cropanalyze, the crop that you to get the Phosphorus fertilization advice
- expectedyield, the yield expected for that crop in quintals per hectare (e.g. 60, 80)
- titlefertilizer, the percentage title of the nutrient within fertilizer you intend to use (10, 40)
library(tictoc)
library(httr)
library(gt)
library(tidyverse)
# Define the API parameters setting
="Wheat"
cropanalyze="60"
expectedyield="46"
titlefertilizer
# Define the url of the API
<- paste0("https://www.api.automaticfarmsolutionwebapp.com/AFS/Phosphorus?cropanalyze=", cropanalyze,"&expectedyield=",expectedyield,"&titlefertilizer=",titlefertilizer)
api_url
# Set the useremail & Password
="useremail"
USEREMAIL="apikey"
APIKEY
# Get the start time to API Call
tic()
# Make the GETs request
<- GET(
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()
0.59 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
cont cont
.
1 104.3478
Node.js
In this example we will test the Phosphorus which allow the user to get nitrogen fertilization advice for each crop
To use the following example you have to replace:
- USEREMAIL
- APIKEY
- cropanalyze, the crop that you to get the Phosphorus fertilization advice
- expectedyield, the yield expected for that crop in quintals per hectare (e.g. 60, 80)
- titlefertilizer, the percentage title of the nutrient within fertilizer you intend to use (10, 40)
// 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/Phosphorus?cropanalyze=';
// set the product_name parameter
const cropanalyze="Wheat";
const expectedyield="60";
const titlefertilizer="46";
// set the apiendpoint
const url = apiurl.concat(cropanalyze, "&expectedyield=", expectedyield, "&titlefertilizer=", titlefertilizer)
const options = {
method: 'get',
url: url,
auth: {
username: username,
password: password,
,
};
}
axios(options)
.then(response => {
console.log('Answer JSON:', response.data);
}).catch(error => {
console.error('Error:', error.message);
; })
Potassium
Python
In this example we will test the Potassium which allow the user to get nitrogen fertilization advice for each crop
To use the following example you have to replace:
- USEREMAIL
- APIKEY
- cropanalyze, the crop that you to get the Potassium fertilization advice
- expectedyield, the yield expected for that crop in quintals per hectare (e.g. 60, 80)
- titlefertilizer, the percentage title of the nutrient within fertilizer you intend to use (10, 40)
# Load the libraries
import requests
from requests.auth import HTTPBasicAuth
import pandas as pd
# Define the API parameters setting
="Wheat"
cropanalyze="60"
expectedyield="46"
titlefertilizer
# Define the url of the API
= "https://www.api.automaticfarmsolutionwebapp.com/AFS/Potassium?cropanalyze="+cropanalyze+"&expectedyield="+expectedyield+"&titlefertilizer="+titlefertilizer
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.get(url,
response =headers,
headers=HTTPBasicAuth(USEREMAIL, APIKEY))
auth
# Convert from response to json
= response.json()
data data
R
In this example we will test the Potassium which allow the user to get nitrogen fertilization advice for each crop
To use the following example you have to replace:
- USEREMAIL
- APIKEY
- cropanalyze, the crop that you to get the Potassium fertilization advice
- expectedyield, the yield expected for that crop in quintals per hectare (e.g. 60, 80)
- titlefertilizer, the percentage title of the nutrient within fertilizer you intend to use (10, 40)
library(tictoc)
library(httr)
library(gt)
library(tidyverse)
# Define the API parameters setting
="Wheat"
cropanalyze="60"
expectedyield="46"
titlefertilizer
# Define the url of the API
<- paste0("https://www.api.automaticfarmsolutionwebapp.com/AFS/Potassium?cropanalyze=", cropanalyze,"&expectedyield=",expectedyield,"&titlefertilizer=",titlefertilizer)
api_url
# Set the useremail & Password
="useremail"
USEREMAIL="apikey"
APIKEY
# Get the start time to API Call
tic()
# Make the GETs request
<- GET(
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()
1.01 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
cont cont
.
1 104.3478
Node.js
In this example we will test the Potassium which allow the user to get nitrogen fertilization advice for each crop
To use the following example you have to replace:
- USEREMAIL
- APIKEY
- cropanalyze, the crop that you to get the Potassium fertilization advice
- expectedyield, the yield expected for that crop in quintals per hectare (e.g. 60, 80)
- titlefertilizer, the percentage title of the nutrient within fertilizer you intend to use (10, 40)
// 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/Potassium?cropanalyze=';
// set the product_name parameter
const cropanalyze="Wheat";
const expectedyield="60";
const titlefertilizer="46";
// set the apiendpoint
const url = apiurl.concat(cropanalyze, "&expectedyield=", expectedyield, "&titlefertilizer=", titlefertilizer)
const options = {
method: 'get',
url: url,
auth: {
username: username,
password: password,
,
};
}
axios(options)
.then(response => {
console.log('Answer JSON:', response.data);
}).catch(error => {
console.error('Error:', error.message);
; })
Easy - Fast - Customizable