# Load the libraries
import requests
import pandas as pd
# Set the token from the environment variable
= "yourtoken"
token
# Set the domain
= "https://fruitkountbackend.automaticfarmsolutionwebapp.com/"
domain
# Set the endpoint
= "sensors/list/"
endpoint
# Create the API URL
= f"{domain}{endpoint}"
api_url
# Make the GET request with Bearer Authentication
= {
headers "Authorization": f"Bearer {token}"
}
# Make the GET Request
= requests.get(api_url, headers=headers)
response
# Print out the status code of the GET request
print(response.status_code)
# Convert from response to json
= response.json()
data
# Convert from json to pandas
= pd.DataFrame(data)
df
# Let's see the first data
df.head()
FruitKount - First API Request
In this section we will explore basic API Endpoint that allow to get several information like:
List of sensors linked - /sensors/list/
Number of sensors - /sensors/number-sensors/
Sensor Detail - /sensors/{id_sensor}/
Sensor Data by ID Sensor - /sensors/sensor-data/{id_sensor}/
Dates available for Sensor - /sensors/date-sensor-data-acquisition/{id_sensor}/
Sensor Data by Date - /sensors/sensor-data-by-date/{id_sensor}/{date}/
List of Sensors
This endpoint allow to get the list of sensors related to your account.
Python
R
library(httr)
library(geojsonio)
library(mapview)
# Set the token from the environment variable
<- Sys.getenv("token")
token
# Set the domain
<- "https://fruitkountbackend.automaticfarmsolutionwebapp.com/"
domain
# Set the endpoint
<- "sensors/list/"
endpoint
# Create the API URL
<- paste0(domain, endpoint)
api_url
# Make the GET request
<- GET(
response
api_url,add_headers(Authorization = paste("Bearer", token))
)
# Check the status code of the response
print(response$status_code)
[1] 200
# Check the content of the response
<- httr::content(response, as = "text", type = "application/json", encoding = "UTF-8")
cont <- jsonlite::fromJSON(cont) %>% as.data.frame()
cont
# Print out the results
print(cont$id_sensor)
[1] 1 2
Node.js
const axios = require('axios');
const fs = require('fs');
const path = require('path'); // For cross-platform file path handling
// Set user token
const token = 'yourtoken';
// Set API base URL and endpoint
const apiUrl = 'https://fruitkountbackend.automaticfarmsolutionwebapp.com/';
const endpoint = 'sensors/list/';
const apiEndpoint = apiUrl.concat(endpoint);
// Output file path
const outputFilePath = path.resolve(__dirname, 'output.json'); // Resolve to current directory
// Function to make the GET request
async function makeGetRequest() {
try {
const response = await axios.get(apiEndpoint, {
headers: {
'Authorization': `Bearer ${token}`,
,
};
})
// Print the status code
console.log('Status Code:', response.status);
// Check if the response contains data
if (response.data) {
// Write response data to a file
.writeFileSync(outputFilePath, JSON.stringify(response.data, null, 2), 'utf-8');
fsconsole.log('Response data saved to:', outputFilePath);
else {
} console.log('No data found in the response.');
}catch (error) {
} console.error('An error occurred:', error.message);
if (error.response) {
console.error('Response status:', error.response.status);
console.error('Response data:', error.response.data);
}
}
}
// Execute the function
makeGetRequest();
Number of Sensors
This endpoint allow to get the number of sensors related to your account.
Python
# Load the libraries
import requests
import pandas as pd
# Set the token from the environment variable
= "yourtoken"
token
# Set the domain
= "https://fruitkountbackend.automaticfarmsolutionwebapp.com/"
domain
# Set the endpoint
= "sensors/number-sensors/"
endpoint
# Create the API URL
= f"{domain}{endpoint}"
api_url
# Make the GET request with Bearer Authentication
= {
headers "Authorization": f"Bearer {token}"
}
# Make the GET Request
= requests.get(api_url, headers=headers)
response
# Print out the status code of the GET request
print(response.status_code)
# Convert from response to json
= response.json()
data
print(data)
R
library(httr)
library(geojsonio)
library(mapview)
# Set the token from the environment variable
<- Sys.getenv("token")
token
# Set the domain
<- "https://fruitkountbackend.automaticfarmsolutionwebapp.com/"
domain
# Set the endpoint
<- "sensors/number-sensors/"
endpoint
# Create the API URL
<- paste0(domain, endpoint)
api_url
# Make the GET request
<- GET(
response
api_url,add_headers(Authorization = paste("Bearer", token))
)
# Check the status code of the response
print(response$status_code)
[1] 200
# Check the content of the response
<- httr::content(response, as = "text", type = "application/json", encoding = "UTF-8")
cont <- jsonlite::fromJSON(cont) %>% as.data.frame()
cont
# Print out the results
print(cont)
count
1 2
Node.js
const axios = require('axios');
const fs = require('fs');
const path = require('path'); // For cross-platform file path handling
// Set user token
const token = 'yourtoken';
// Set API base URL and endpoint
const apiUrl = 'https://fruitkountbackend.automaticfarmsolutionwebapp.com/';
const endpoint = 'sensors/number-sensors/';
const apiEndpoint = apiUrl.concat(endpoint);
// Output file path
const outputFilePath = path.resolve(__dirname, 'output.json'); // Resolve to current directory
// Function to make the GET request
async function makeGetRequest() {
try {
const response = await axios.get(apiEndpoint, {
headers: {
'Authorization': `Bearer ${token}`,
,
};
})
// Print the status code
console.log('Status Code:', response.status);
// Check if the response contains data
if (response.data) {
// Write response data to a file
.writeFileSync(outputFilePath, JSON.stringify(response.data, null, 2), 'utf-8');
fsconsole.log('Response data saved to:', outputFilePath);
else {
} console.log('No data found in the response.');
}catch (error) {
} console.error('An error occurred:', error.message);
if (error.response) {
console.error('Response status:', error.response.status);
console.error('Response data:', error.response.data);
}
}
}
// Execute the function
makeGetRequest();
Sensor Detail
This endpoint allow to get the detail of one sensor related to your account.
In order to use this endpoint you have to provide one API Parameter:
- id_sensor, which is the sensor id of your device
Python
# Load the libraries
import requests
import pandas as pd
# Set the token from the environment variable
= "yourtoken"
token
# Set the domain
= "https://fruitkountbackend.automaticfarmsolutionwebapp.com/"
domain
# Set the endpoint
= "sensors/sensor-detail/"
endpoint
# Set API parameters
="1"
id_sensor
# Create the API URL
= f"{domain}{endpoint}{id_sensor}"
api_url
# Make the GET request with Bearer Authentication
= {
headers "Authorization": f"Bearer {token}"
}
# Make the GET Request
= requests.get(api_url, headers=headers)
response
# Print out the status code of the GET request
print(response.status_code)
# Convert from response to json
= response.json()
data
print(data)
R
library(httr)
library(geojsonio)
library(mapview)
# Set the token from the environment variable
<- Sys.getenv("token")
token
# Set the domain
<- "https://fruitkountbackend.automaticfarmsolutionwebapp.com/"
domain
# Set the endpoint
<- "sensors/sensor-detail/"
endpoint
# Set the API Parameters
="1"
id_sensor
# Create the API URL
<- paste0(domain, endpoint, id_sensor)
api_url
# Make the GET request
<- GET(
response
api_url,add_headers(Authorization = paste("Bearer", token))
)
# Check the status code of the response
print(response$status_code)
[1] 200
# Check the content of the response
<- httr::content(response, as = "text", type = "application/json", encoding = "UTF-8")
cont <- jsonlite::fromJSON(cont) %>% as.data.frame()
cont
# Print out the results
print(cont[,1:10])
id id_sensor created_at changed_at last_request_at
1 1 1 2025-01-08 2025-01-08 2025-01-08T10:44:33.765065Z
number_of_request is_deleted date_production date_invoice date_delivery
1 2 FALSE 2025-01-08 2025-01-08 2025-01-08
Node.js
const axios = require('axios');
const fs = require('fs');
const path = require('path'); // For cross-platform file path handling
// Set user token
const token = 'yourtoken';
// Set API base URL and endpoint
const apiUrl = 'https://fruitkountbackend.automaticfarmsolutionwebapp.com/';
const endpoint = "sensors/sensor-detail/";
// Set the API Parameters
const id_sensor="1";
// Set the API Url
const apiEndpoint = apiUrl.concat(endpoint, id_sensor);
// Output file path
const outputFilePath = path.resolve(__dirname, 'output.json'); // Resolve to current directory
// Function to make the GET request
async function makeGetRequest() {
try {
const response = await axios.get(apiEndpoint, {
headers: {
'Authorization': `Bearer ${token}`,
,
};
})
// Print the status code
console.log('Status Code:', response.status);
// Check if the response contains data
if (response.data) {
// Write response data to a file
.writeFileSync(outputFilePath, JSON.stringify(response.data, null, 2), 'utf-8');
fsconsole.log('Response data saved to:', outputFilePath);
else {
} console.log('No data found in the response.');
}catch (error) {
} console.error('An error occurred:', error.message);
if (error.response) {
console.error('Response status:', error.response.status);
console.error('Response data:', error.response.data);
}
}
}
// Execute the function
makeGetRequest();
Sensor Data by id_sensor
This endpoint allow to get the data of one sensor related to your account.
In order to use this endpoint you have to provide one API Parameter:
- id_sensor, which is the sensor id of your device
Python
# Load the libraries
import requests
import pandas as pd
# Set the token from the environment variable
= "yourtoken"
token
# Set the domain
= "https://fruitkountbackend.automaticfarmsolutionwebapp.com/"
domain
# Set the endpoint
= "sensors/sensor-data/"
endpoint
# Set API parameters
="1"
id_sensor
# Create the API URL
= f"{domain}{endpoint}{id_sensor}"
api_url
# Make the GET request with Bearer Authentication
= {
headers "Authorization": f"Bearer {token}"
}
# Make the GET Request
= requests.get(api_url, headers=headers)
response
# Print out the status code of the GET request
print(response.status_code)
# Convert from response to json
= response.json()
data
# Convert from json to pandas
= pd.DataFrame(data)
df
# Let's see the first data
df.head()
R
library(httr)
library(geojsonio)
library(mapview)
# Set the token from the environment variable
<- Sys.getenv("token")
token
# Set the domain
<- "https://fruitkountbackend.automaticfarmsolutionwebapp.com/"
domain
# Set the endpoint
<- "sensors/sensor-data/"
endpoint
# Set the API Parameters
="1"
id_sensor
# Create the API URL
<- paste0(domain, endpoint, id_sensor)
api_url
# Make the GET request
<- GET(
response
api_url,add_headers(Authorization = paste("Bearer", token))
)
# Check the status code of the response
print(response$status_code)
[1] 200
# Check the content of the response
<- httr::content(response, as = "text", type = "application/json", encoding = "UTF-8")
cont <- jsonlite::fromJSON(cont) %>% as.data.frame()
cont
# Print out the results
print(head(cont[, 1:14]))
id id_sensor id_acquisition x_coord y_coord z_coord date
1 1 1 1 13.40823 43.59725 13.40823 2024-08-12T07:23:22Z
2 2 1 2 13.40823 43.59719 13.40823 2024-08-12T07:23:33Z
3 3 1 3 13.40822 43.59714 13.40822 2024-08-12T07:23:44Z
4 4 1 4 13.40819 43.59705 13.40819 2024-08-12T07:23:55Z
5 5 1 5 13.40817 43.59698 13.40817 2024-08-12T07:24:06Z
6 6 1 6 13.40815 43.59690 13.40815 2024-08-12T07:24:18Z
crop count width height group_acquisition area distance
1 vineyard 0.5 0 0 1 NA 10
2 vineyard 3.0 0 0 1 NA 10
3 vineyard 3.0 0 0 1 NA 10
4 vineyard 2.0 0 0 1 NA 10
5 vineyard 3.5 0 0 1 NA 10
6 vineyard 4.0 0 0 1 NA 10
Node.js
const axios = require('axios');
const fs = require('fs');
const path = require('path'); // For cross-platform file path handling
// Set user token
const token = 'yourtoken';
// Set API base URL and endpoint
const apiUrl = 'https://fruitkountbackend.automaticfarmsolutionwebapp.com/';
const endpoint = "sensors/sensor-data/";
// Set the API Parameters
const id_sensor="1";
// Set the API Url
const apiEndpoint = apiUrl.concat(endpoint, id_sensor);
// Output file path
const outputFilePath = path.resolve(__dirname, 'output.json'); // Resolve to current directory
// Function to make the GET request
async function makeGetRequest() {
try {
const response = await axios.get(apiEndpoint, {
headers: {
'Authorization': `Bearer ${token}`,
,
};
})
// Print the status code
console.log('Status Code:', response.status);
// Check if the response contains data
if (response.data) {
// Write response data to a file
.writeFileSync(outputFilePath, JSON.stringify(response.data, null, 2), 'utf-8');
fsconsole.log('Response data saved to:', outputFilePath);
else {
} console.log('No data found in the response.');
}catch (error) {
} console.error('An error occurred:', error.message);
if (error.response) {
console.error('Response status:', error.response.status);
console.error('Response data:', error.response.data);
}
}
}
// Execute the function
makeGetRequest();
Dates available for Sensor
This endpoint allow to get the dates available of one sensor related to your account.
In order to use this endpoint you have to provide one API Parameter:
- id_sensor, which is the sensor id of your device
Python
# Load the libraries
import requests
import pandas as pd
# Set the token from the environment variable
= "yourtoken"
token
# Set the domain
= "https://fruitkountbackend.automaticfarmsolutionwebapp.com/"
domain
# Set the endpoint
= "sensors/date-sensor-data-acquisition/"
endpoint
# Set API parameters
="1"
id_sensor
# Create the API URL
= f"{domain}{endpoint}{id_sensor}"
api_url
# Make the GET request with Bearer Authentication
= {
headers "Authorization": f"Bearer {token}"
}
# Make the GET Request
= requests.get(api_url, headers=headers)
response
# Print out the status code of the GET request
print(response.status_code)
# Convert from response to json
= response.json()
data
# Convert from json to pandas
= pd.DataFrame(data)
df
# Let's see the first data
df.head()
R
library(httr)
library(geojsonio)
library(mapview)
# Set the token from the environment variable
<- Sys.getenv("token")
token
# Set the domain
<- "https://fruitkountbackend.automaticfarmsolutionwebapp.com/"
domain
# Set the endpoint
<- "sensors/date-sensor-data-acquisition/"
endpoint
# Set the API Parameters
="1"
id_sensor
# Create the API URL
<- paste0(domain, endpoint, id_sensor)
api_url
# Make the GET request
<- GET(
response
api_url,add_headers(Authorization = paste("Bearer", token))
)
# Check the status code of the response
print(response$status_code)
[1] 200
# Check the content of the response
<- httr::content(response, as = "text", type = "application/json", encoding = "UTF-8")
cont <- jsonlite::fromJSON(cont) %>% as.data.frame()
cont
# Print out the dates
print(cont$date)
[1] "2024-08-12T07:23:22Z" "2024-08-17T07:05:34Z"
Node.js
const axios = require('axios');
const fs = require('fs');
const path = require('path'); // For cross-platform file path handling
// Set user token
const token = 'yourtoken';
// Set API base URL and endpoint
const apiUrl = 'https://fruitkountbackend.automaticfarmsolutionwebapp.com/';
const endpoint = "sensors/date-sensor-data-acquisition/";
// Set the API Parameters
const id_sensor="1";
// Set the API Url
const apiEndpoint = apiUrl.concat(endpoint, id_sensor);
// Output file path
const outputFilePath = path.resolve(__dirname, 'output.json'); // Resolve to current directory
// Function to make the GET request
async function makeGetRequest() {
try {
const response = await axios.get(apiEndpoint, {
headers: {
'Authorization': `Bearer ${token}`,
,
};
})
// Print the status code
console.log('Status Code:', response.status);
// Check if the response contains data
if (response.data) {
// Write response data to a file
.writeFileSync(outputFilePath, JSON.stringify(response.data, null, 2), 'utf-8');
fsconsole.log('Response data saved to:', outputFilePath);
else {
} console.log('No data found in the response.');
}catch (error) {
} console.error('An error occurred:', error.message);
if (error.response) {
console.error('Response status:', error.response.status);
console.error('Response data:', error.response.data);
}
}
}
// Execute the function
makeGetRequest();
Sensor Data by Date
This endpoint allow to get the data sensor related to one date
In order to use this endpoint you have to provide two API Parameter:
- id_sensor, which is the sensor id of your device
- date, which is the date of the acquisition that the device performed
Python
import requests
import pandas as pd
# Set the token from the environment variable
= "yourtoken"
token
# Set the domain
= "https://fruitkountbackend.automaticfarmsolutionwebapp.com/"
domain
# Set the endpoint
= "sensors/sensor-data-by-date/"
endpoint
# Set API parameters
="1"
id_sensor="2024-08-12T07:23:22Z"
date
# Create the API URL
= f"{domain}{endpoint}{id_sensor}/{date}"
api_url
# Make the GET request with Bearer Authentication
= {
headers "Authorization": f"Bearer {token}"
}
# Make the GET Request
= requests.get(api_url, headers=headers)
response
# Print out the status code of the GET request
print(response.status_code)
# Convert from response to json
= response.json()
data
# Convert from json to pandas
= pd.DataFrame(data)
df
# Let's see the first data
df.head()
R
library(httr)
library(geojsonio)
library(mapview)
# Set the token from the environment variable
<- Sys.getenv("token")
token
# Set the domain
<- "https://fruitkountbackend.automaticfarmsolutionwebapp.com/"
domain
# Set the endpoint
<- "sensors/sensor-data-by-date/"
endpoint
# Set the API Parameters
="1"
id_sensor="2024-08-12T07:23:22Z"
date
# Create the API URL
<- paste0(domain, endpoint, id_sensor, "/", date, "/")
api_url
# Make the GET request
<- GET(
response
api_url,add_headers(Authorization = paste("Bearer", token))
)
# Check the status code of the response
print(response$status_code)
[1] 200
# Check the content of the response
<- httr::content(response, as = "text", type = "application/json", encoding = "UTF-8")
cont <- jsonlite::fromJSON(cont) %>% as.data.frame()
cont
# Print out the data
print(head(cont[, 1:14]))
id id_sensor id_acquisition x_coord y_coord z_coord date
1 1 1 1 13.40823 43.59725 13.40823 2024-08-12T07:23:22Z
2 2 1 2 13.40823 43.59719 13.40823 2024-08-12T07:23:33Z
3 3 1 3 13.40822 43.59714 13.40822 2024-08-12T07:23:44Z
4 4 1 4 13.40819 43.59705 13.40819 2024-08-12T07:23:55Z
5 5 1 5 13.40817 43.59698 13.40817 2024-08-12T07:24:06Z
6 6 1 6 13.40815 43.59690 13.40815 2024-08-12T07:24:18Z
crop count width height group_acquisition area distance
1 vineyard 0.5 0 0 1 NA 10
2 vineyard 3.0 0 0 1 NA 10
3 vineyard 3.0 0 0 1 NA 10
4 vineyard 2.0 0 0 1 NA 10
5 vineyard 3.5 0 0 1 NA 10
6 vineyard 4.0 0 0 1 NA 10
Node.js
const axios = require('axios');
const fs = require('fs');
const path = require('path'); // For cross-platform file path handling
// Set user token
const token = 'yourtoken';
// Set API base URL and endpoint
const apiUrl = 'https://fruitkountbackend.automaticfarmsolutionwebapp.com/';
const endpoint = "sensors/sensor-data-by-date/";
// Set the API Parameters
const id_sensor="1";
const date="2024-08-12T07:23:22Z";
// Set the API Url
const apiEndpoint = apiUrl.concat(endpoint, id_sensor, "/", date);
// Output file path
const outputFilePath = path.resolve(__dirname, 'output.json'); // Resolve to current directory
// Function to make the GET request
async function makeGetRequest() {
try {
const response = await axios.get(apiEndpoint, {
headers: {
'Authorization': `Bearer ${token}`,
,
};
})
// Print the status code
console.log('Status Code:', response.status);
// Check if the response contains data
if (response.data) {
// Write response data to a file
.writeFileSync(outputFilePath, JSON.stringify(response.data, null, 2), 'utf-8');
fsconsole.log('Response data saved to:', outputFilePath);
else {
} console.log('No data found in the response.');
}catch (error) {
} console.error('An error occurred:', error.message);
if (error.response) {
console.error('Response status:', error.response.status);
console.error('Response data:', error.response.data);
}
}
}
// Execute the function
makeGetRequest();