Nutrient Balance

In this part we will focus on four endpoint:

  1. “AFS/AvailableCrops” endpoint, which allow the user to get available crops for each nutrient suggestion
  2. “AFS/Nitrogen” endpoint, which allow the user to get fertilization nitrogen advice
  3. “AFS/Phosphorus” endpoint, which allow the user to get fertilization phosphorus advice
  4. “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:

  1. USEREMAIL
  2. APIKEY
  3. nutrient that you would like to get the list of available crops
# Load the libraries
import requests
from requests.auth import HTTPBasicAuth
import pandas as pd

# Define the API parameters setting

nutrient ="nitrogen"

# Define the url of the API

url = "https://www.api.automaticfarmsolutionwebapp.com/AFS/AvailableCrops?nutrient="+nutrient

# 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.get(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 AvailableCrops which allow the user to get available crops for each nutrient suggestion

To use the following example you have to replace:

  1. USEREMAIL
  2. APIKEY
  3. 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

nutrient ="nitrogen"

# Define the url of the API

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

# Set the useremail & Password

USEREMAIL="useremail"
APIKEY="apikey"

# Get the start time to API Call

tic()

# Make the GETs request

r <- GET(
  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()
0.7 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
cont[1:5,]
[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:

  1. USEREMAIL
  2. APIKEY
  3. 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:

  1. USEREMAIL
  2. APIKEY
  3. cropanalyze, the crop that you to get the Nitrogen fertilization advice
  4. expectedyield, the yield expected for that crop in quintals per hectare (e.g. 60, 80)
  5. 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

cropanalyze="Durum_wheat"
expectedyield="60"
titlefertilizer="46"

# Define the url of the API

url = "https://www.api.automaticfarmsolutionwebapp.com/AFS/Nitrogen?cropanalyze="+cropanalyze+"&expectedyield="+expectedyield+"&titlefertilizer="+titlefertilizer

# 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.get(url, 
                         headers=headers,
                         auth=HTTPBasicAuth(USEREMAIL, APIKEY))

# Convert from response to json

data = response.json()

# 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:

  1. USEREMAIL
  2. APIKEY
  3. cropanalyze, the crop that you to get the Nitrogen fertilization advice
  4. expectedyield, the yield expected for that crop in quintals per hectare (e.g. 60, 80)
  5. 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

cropanalyze="Durum_wheat"
expectedyield="60"
titlefertilizer="46"

# Define the url of the API

api_url <- paste0("https://www.api.automaticfarmsolutionwebapp.com/AFS/Nitrogen?cropanalyze=", cropanalyze,"&expectedyield=",expectedyield,"&titlefertilizer=",titlefertilizer)

# Set the useremail & Password

USEREMAIL="useremail"
APIKEY="apikey"

# Get the start time to API Call

tic()

# Make the GETs request

r <- GET(
  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()
0.56 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
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:

  1. USEREMAIL
  2. APIKEY
  3. cropanalyze, the crop that you to get the Nitrogen fertilization advice
  4. expectedyield, the yield expected for that crop in quintals per hectare (e.g. 60, 80)
  5. 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:

  1. USEREMAIL
  2. APIKEY
  3. cropanalyze, the crop that you to get the Phosphorus fertilization advice
  4. expectedyield, the yield expected for that crop in quintals per hectare (e.g. 60, 80)
  5. 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

cropanalyze="Wheat"
expectedyield="60"
titlefertilizer="46"

# Define the url of the API

url = "https://www.api.automaticfarmsolutionwebapp.com/AFS/Phosphorus?cropanalyze="+cropanalyze+"&expectedyield="+expectedyield+"&titlefertilizer="+titlefertilizer

# 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.get(url, 
                         headers=headers,
                         auth=HTTPBasicAuth(USEREMAIL, APIKEY))

# Convert from response to json

data = response.json()
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:

  1. USEREMAIL
  2. APIKEY
  3. cropanalyze, the crop that you to get the Phosphorus fertilization advice
  4. expectedyield, the yield expected for that crop in quintals per hectare (e.g. 60, 80)
  5. 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

cropanalyze="Wheat"
expectedyield="60"
titlefertilizer="46"

# Define the url of the API

api_url <- paste0("https://www.api.automaticfarmsolutionwebapp.com/AFS/Phosphorus?cropanalyze=", cropanalyze,"&expectedyield=",expectedyield,"&titlefertilizer=",titlefertilizer)

# Set the useremail & Password

USEREMAIL="useremail"
APIKEY="apikey"

# Get the start time to API Call

tic()

# Make the GETs request

r <- GET(
  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()
0.59 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
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:

  1. USEREMAIL
  2. APIKEY
  3. cropanalyze, the crop that you to get the Phosphorus fertilization advice
  4. expectedyield, the yield expected for that crop in quintals per hectare (e.g. 60, 80)
  5. 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:

  1. USEREMAIL
  2. APIKEY
  3. cropanalyze, the crop that you to get the Potassium fertilization advice
  4. expectedyield, the yield expected for that crop in quintals per hectare (e.g. 60, 80)
  5. 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

cropanalyze="Wheat"
expectedyield="60"
titlefertilizer="46"

# Define the url of the API

url = "https://www.api.automaticfarmsolutionwebapp.com/AFS/Potassium?cropanalyze="+cropanalyze+"&expectedyield="+expectedyield+"&titlefertilizer="+titlefertilizer

# 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.get(url, 
                         headers=headers,
                         auth=HTTPBasicAuth(USEREMAIL, APIKEY))

# Convert from response to json

data = response.json()
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:

  1. USEREMAIL
  2. APIKEY
  3. cropanalyze, the crop that you to get the Potassium fertilization advice
  4. expectedyield, the yield expected for that crop in quintals per hectare (e.g. 60, 80)
  5. 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

cropanalyze="Wheat"
expectedyield="60"
titlefertilizer="46"

# Define the url of the API

api_url <- paste0("https://www.api.automaticfarmsolutionwebapp.com/AFS/Potassium?cropanalyze=", cropanalyze,"&expectedyield=",expectedyield,"&titlefertilizer=",titlefertilizer)

# Set the useremail & Password

USEREMAIL="useremail"
APIKEY="apikey"

# Get the start time to API Call

tic()

# Make the GETs request

r <- GET(
  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()
1.01 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
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:

  1. USEREMAIL
  2. APIKEY
  3. cropanalyze, the crop that you to get the Potassium fertilization advice
  4. expectedyield, the yield expected for that crop in quintals per hectare (e.g. 60, 80)
  5. 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

Back to top