Load the librariesimport requests
from requests.auth import HTTPBasicAuth
import pandas as pd
# Define the url of the API
= "https://www.api.automaticfarmsolutionwebapp.com/AFS/ListPhytopharmaceuticalsProductName"
url
# Set the useremail & Password
="useremail"
USEREMAIL="password"
APIKEY
# Set the headers for the request
= {
headers "Content-Type": "application/json"
}
# Make the GET 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, columns=["Products"])
df
# 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
<- "https://www.api.automaticfarmsolutionwebapp.com/AFS/ListPhytopharmaceuticalsProductName?"
api_url
# Set the useremail & Password
="useremail"
USEREMAIL="apikey"
APIKEY
# Get the start time to API Call
tic()
# Make the GET 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()
2.05 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:5,]
cont 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
="enovit"
product
# Define the url of the API
= "https://www.api.automaticfarmsolutionwebapp.com/AFS/Phytopharmaceuticals?product_name="+product
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()
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
="enovit"
product
# Define the url of the API
<- paste0("https://www.api.automaticfarmsolutionwebapp.com/AFS/Phytopharmaceuticals?product_name=", product)
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()
2.61 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)
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