import requests
# Set the email and password
= "email"
email = "password"
password
# Set the domain
= "https://fruitkountbackend.automaticfarmsolutionwebapp.com/"
domain
# Set the endpoint
= "authentication/token/"
endpoint
# Create the API URL
= domain + endpoint
api_url
# Create the JSON body element
= {
body "email": email,
"password": password
}
# Set headers for the request
= {
headers "Content-Type": "application/json"
}
# Make the POST request
= requests.post(api_url, json=body, headers=headers)
response
# Check the status code
print(f"Status Code: {response.status_code}")
if response.status_code == 200:
# Convert the response to JSON
= response.json()
response_json
# Print out the token key item
= response_json.get("token", None)
token if token:
print(f"Token: {token}")
else:
print("Token not found in the response.")
else:
print(f"Error: {response.text}")
FruitKount - Getting Started
Welcome to the FruitKount API Documentation.
This API is the cloud service that allow to access the acquired data of our IoT system based on artificial intelligence that count each individual production unit (bunch, apple, peach, pear) and also determines its weight and its relative position.
If you would like to learn more, please visit our website
We developed this API with the following principles:
Easy to use
Safe
Ready to be integrated with third-party platforms
We at Automatic Farm Solution, we believe in collaboration, and we are ready to support you in order to Test / Integrate our API.
If you need any help/support please don’t hesitate to send us an email to info@automaticfarmsolution.com. One operator will help you as soon as we can.
All the API Documentation will be provided in three different programming languages which are:
- Python
- R
- Node.js
Let’s Get Started
In order to start to use our API:
you have to register to our App, please to go Register Page in order to register. After the registration you should receive an email in order to confirm your detail. After this you are ready to go.
moreover you should have a sensors linked to your account. If you don’t have any sensors and you would like to test out the system, please send us an email to info@automaticfarmsolution.com by asking to add one of our sensor
I will now show you how to:
Authenticate
Get your account information
Authentication
Our API follows the JSON Web Token in order to authenticate.
So before to make any requests, you should first get the JSON Web Token and then set it as Bearer Authentication Code.
In order to get the Bearer Authentication Code you have to login first. In order to use the authentication/login/ endpoint you need to provide as body of the POST request these elements:
- Password
After getting the Bearer authentication code you have to pass it each time that you are making a request to our API
Python
R
library(httr)
library(tidyverse)
# Set the email and password
<- Sys.getenv("useremail")
email <- Sys.getenv("password")
password
# Set the domain
<- "https://fruitkountbackend.automaticfarmsolutionwebapp.com/"
domain
# Set the endpoint
<- "authentication/token/"
endpoint
# Create the API URL
<- paste0(domain, endpoint)
api_url
# Create the JSON body with email and password
<- list(email = email,
json_body password = password)
# Make the POST request
<- POST(
response
api_url,body = json_body,
encode = "json", # Ensures the body is sent as JSON
content_type_json() # Sets the Content-Type header to application/json
)
# Check the status code of the response
print(response$status_code)
[1] 200
# Check the content
<- httr::content(response, as = "text", type = "application/json", encoding="UTF-8")
cont <-jsonlite::fromJSON(cont) %>% as.data.frame
cont
# The following is the Bearer code that you have to use for each request
# print(cont$token)
Node.js
const axios = require('axios');
const fs = require('fs');
const path = require('path'); // For cross-platform file path handling
// Set user email and password
const useremail = 'useremail';
const password = 'password';
// Set API base URL and endpoint
const apiUrl = 'https://fruitkountbackend.automaticfarmsolutionwebapp.com/';
const endpoint = 'authentication/token/';
const apiEndpoint = apiUrl.concat(endpoint);
// Payload for the POST request
const payload = {
email: useremail,
password: password,
;
}
// Output file path
const outputFilePath = path.resolve(__dirname, 'output.json'); // Resolve to current directory
// Function to make the POST request
async function makePostRequest() {
try {
const response = await axios.post(apiEndpoint, payload, {
headers: {
'Content-Type': 'application/json',
,
}responseType: 'json',
;
})
// Print the token key item from the JSON response
if (response.data && response.data.token) {
console.log('Token:', response.data.token);
else {
} console.log('Token not found in 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);
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
makePostRequest();
User Details
Now let’s get your account information in order to check if you are well setted to make your first API request.
If the response give to you a status code as 200 - You are ready to make your first API Request
If the response give to you a status code different than 200 - You are NOT ready to make your first API Request - If you need help or support please send us an email to info@automaticfarmsolution.com
Python
import os
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
= "authentication/user-detail/"
endpoint
# Create the API URL
= f"{domain}{endpoint}"
api_url
# Make the GET request with Bearer Authentication
= {
headers "Authorization": f"Bearer {token}"
}
= requests.get(api_url, headers=headers)
response
# Check the status code of the response
print(response.status_code)
# Check the content of the response
if response.status_code == 200:
= response.json() # Parse JSON response into a Python dict
cont
print(cont)
else:
print("Failed to retrieve data. Status code:", response.status_code)
R
library(httr)
library(tidyverse)
# Set the token from the environment variable
<- Sys.getenv("token")
token
# Set the domain
<- "https://fruitkountbackend.automaticfarmsolutionwebapp.com/"
domain
# Set the endpoint
<- "authentication/user-detail/"
endpoint
# Create the API URL
<- paste0(domain, endpoint)
api_url
# Make the GET request with Bearer Authentication
<- 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 user details
# print(cont)
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 = 'authentication/user-detail/';
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();