Soil data

In this part we will focus on the endpoint “AFS/SoilDataPoint” endpoint, which allow the user to get data related to the soil.

Python

In this example we will test the SoilDataPoint 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. long, Longitudinal coordinate (WGS 84) of the site whose weather data you want to receive (example: 13.3123)
  4. lat, Latitude coordinate (WGS 84) of the site whose weather data you want to receive (example: 42.4560)

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

longi="13.3123"
lat="42.4560"

# Define the url of the API

url = "https://www.api.automaticfarmsolutionwebapp.com/AFS/SoilDataPoint?long="+longi+"&lat="+lat

# 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 SoilDataPoint 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. long, Longitudinal coordinate (WGS 84) of the site whose weather data you want to receive (example: 13.3123)
  4. lat, Latitude coordinate (WGS 84) of the site whose weather data you want to receive (example: 42.4560)

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

longi="13.3123"
lat="42.4560"

# Define the url of the API

api_url <- paste0("https://www.api.automaticfarmsolutionwebapp.com/AFS/SoilDataPoint?long=", longi, "&lat=",lat)

# 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()
1.69 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)
Argilla Sabbia Limo Bulk_density Azoto Sostanza_organica pH
26 35 40 1.3 2.4 34.6 7

Node.js

In this example we will test the SoilDataPoint 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. long, Longitudinal coordinate (WGS 84) of the site whose weather data you want to receive (example: 13.3123)
  4. lat, Latitude coordinate (WGS 84) of the site whose weather data you want to receive (example: 42.4560)

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/SoilDataPoint?long=';

// set the product_name parameter

const longi="13.3123";
const lat="42.4560";

// set the apiendpoint

const url = apiurl.concat(longi, "&lat=", lat)

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