Load the libraries
import requests
from requests.auth import HTTPBasicAuth
import pandas as pd
# Define the url of the API
url = "https://www.api.automaticfarmsolutionwebapp.com/AFS/ListPhytopharmaceuticalsProductName"
# Set the useremail & Password
USEREMAIL="useremail"
APIKEY="password"
# Set the headers for the request
headers = {
"Content-Type": "application/json"
}
# Make the GET 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, columns=["Products"])
# Let's see the first 5 agricultural products
df.head()Phytofarmaceutical
In this part we will focus on two endpoint:
- “AFS/ListPhytopharmaceuticalsProductName” endpoint, which allow the user to get the list of the phytofarmaceutical product registered in our system and get information about it.
- “AFS/AFS/Phytopharmaceuticals” endpoint, which allow the user to get all the information of the phytofarmaceutical product selected from the previouse list.
ListPhytopharmaceuticalsProductName
Python
In this example we will test the ListPhytopharmaceuticalsProductName endpoint which allow the user to get the list of the phytofarmaceutical product registered in our system
To use the following example you have to replace:
- USEREMAIL
- APIKEY
With your information and let’s try out the API.
R
In this example we will test the ListPhytopharmaceuticalsProductName endpoint which allow the user to get the list of the phytofarmaceutical product registered in our system
To use the following example you have to replace:
- USEREMAIL
- APIKEY
With your information and let’s try out the API.
# import libraries
library(tictoc)
library(httr)
library(tidyverse)
# Define the url of the API
api_url <- "https://www.api.automaticfarmsolutionwebapp.com/AFS/ListPhytopharmaceuticalsProductName?"
# Set the useremail & Password
USEREMAIL="useremail"
APIKEY="apikey"
# Get the start time to API Call
tic()
# Make the GET 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()2.05 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<-cont[1:5,]
cont[1] "enovit" "contrax stange" "quintamon" "agroxone 96"
[5] "tmtd-amonn"
Node.js
In this example we will test the ListPhytopharmaceuticalsProductName endpoint which allow the user to get the list of the phytofarmaceutical product registered in our system
To use the following example you have to replace:
- USEREMAIL
- APIKEY
With your information and let’s try out the API.
// Load Libraries
const fs = require('fs');
const axios = require('axios');
// Set the useremail & passowrd
const useremail = 'XXXXXXXXXXXXXXXXXXXXXXX';
const apikey = 'XXXXXXXXXXXXXXXXXXXXXXX';
// Set API Url
const apiEndpoint='https://www.api.automaticfarmsolutionwebapp.com/AFS/ListPhytopharmaceuticalsProductName?';
(async () => {
try {
const authHeader = `Basic ${Buffer.from(`${useremail}:${apikey}`).toString('base64')}`;
const response = await axios.get(apiEndpoint, {
headers: {
'Content-Type': 'application/json',
'Authorization': authHeader
}
});
const resultGeoJSON = response.data;
console.log('Answer From the API:', resultGeoJSON);
} catch (err) {
console.error('Error:', err.message);
}
})();Phytopharmaceuticals
Python
In this example we will test the ListPhytopharmaceuticalsProductName endpoint which allow the user to get the list of the phytofarmaceutical product registered in our system
To use the following example you have to replace:
- USEREMAIL
- APIKEY
- product_name, that you want to visualize (the complete list of Phytopharmaceuticals can be obtained by using the ListPhytopharmaceuticalsProductName enpoint)
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 product that you want
product="enovit"
# Define the url of the API
url = "https://www.api.automaticfarmsolutionwebapp.com/AFS/Phytopharmaceuticals?product_name="+product
# 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 ListPhytopharmaceuticalsProductName endpoint which allow the user to get the list of the phytofarmaceutical product registered in our system
To use the following example you have to replace:
- USEREMAIL
- APIKEY
- product_name, that you want to visualize (the complete list of Phytopharmaceuticals can be obtained by using the ListPhytopharmaceuticalsProductName enpoint)
With your information and let’s try out the API.
# import libraries
library(tictoc)
library(httr)
library(tidyverse)
library(gt)
# Define the product that you want
product="enovit"
# Define the url of the API
api_url <- paste0("https://www.api.automaticfarmsolutionwebapp.com/AFS/Phytopharmaceuticals?product_name=", product)
# 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()2.61 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)| NUMERO_REGISTRAZIONE | PRODOTTO | IMPRESA | SEDE_LEGALE_IMPRESA | CAP_SEDE_LEGALE_IMPRESA | CITTA_SEDE_LEGALE_IMPRESA | PROVINCIA_SEDE_LEGALE_IMPRESA | SEDE_AMMINISTRATIVA_IMPRESA | CAP_SEDE_AMMINISTRATIVA_IMPRESA | CITTA_SEDE_AMMINISTRATIVA_IMPRESA | PROVINCIA_SEDE_AMMINISTRATIVA_IMPRESA | DATA_REGISTRAZIONE | SCADENZA_AUTORIZZAZIONE | INDICAZIONI_DI_PERICOLO | ATTIVITA | CODICE_FORMULAZIONE | DESCRIZIONE_FORMULAZIONE | SOSTANZE_ATTIVE | CONTENUTO_PER_100G_DI_PRODOTTO | IP | PFnPO | PFnPE | STATO_AMMINISTRATIVO | MOTIVO_DELLA_REVOCA | DATA_DECRETO_REVOCA | DATA_DECORRENZA_REVOCA |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | enovit | SIPCAM S.P.A. | VIA CARROCCIO, 8 | 20123 | MILANO | MILANO | VIA SEMPIONE, 195 | 20016 | PERO | MILANO | 1970-04-14 | - | - | - | DP | POLVERE | THIOPHANATE-METHYL | - | NO | NO | NO | Revocato | - | - | 30511 |
Node.js
In this example we will test the Phytopharmaceuticals endpoint which allow the user to get the list of the phytofarmaceutical product registered in our system
To use the following example you have to replace:
- USEREMAIL
- APIKEY
- product_name, that you want to visualize (the complete list of Phytopharmaceuticals can be obtained by using the ListPhytopharmaceuticalsProductName enpoint)
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/Phytopharmaceuticals?product_name=';
// set the product_name parameter
const product_name='enovit'
// set the apiendpoint
const url = apiurl.concat(product_name)
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