In this part we will focus on the “AFS/DeleteField” endpoint, which allow the user to delete previouse field that have request to be monitored.
Python
In order to use the endpoint you have to set the following parameter:
USEREMAIL
APIKEY
fieldnumber, the id of the field that you want to delete
#| eval: false# Load the librariesimport requestsfrom requests.auth import HTTPBasicAuth# Define the API call parametersfieldnumber="1"# the fieldnumber to delete# Define the url of the APIurl ="https://www.api.automaticfarmsolutionwebapp.com/AFS/DeleteField?fieldnumber="+fieldnumber# Set the useremail & PasswordUSEREMAIL="useremail"APIKEY="apikey"# Set the headers for the requestheaders = {"Content-Type": "application/json"}# Make the POST request with the GeoJSON data as the request bodyresponse = requests.delete(url, headers=headers, auth=HTTPBasicAuth(USEREMAIL, APIKEY))# if the following line is 200 so the field was successfully deletedprint(response.status_code)
400
R
In order to use the endpoint you have to set the following parameter:
USEREMAIL
APIKEY
fieldnumber, the id of the field that you want to delete
# Load the librarylibrary(httr)# Define the user and passwordUSEREMAIL="useremail"APIKEY="apikey"# Define the fieldnumber to deletefieldnumber<-1# Define the endpointapi_endpoint <-"https://www.api.automaticfarmsolutionwebapp.com/AFS/DeleteField?fieldnumber="# Define the API CallAPI_URL<-paste0(api_endpoint, fieldnumber)# Make the API Callresponse <-DELETE( API_URL, httr::authenticate(user = USEREMAIL,password = APIKEY ))# Check the status if 200, the field was deletedresponse$status_code
Node.js
In order to use the endpoint you have to set the following parameter:
USEREMAIL
APIKEY
fieldnumber, the id of the field that you want to delete
// Load Librariesconst fs =require('fs');const axios =require('axios');// Set the useremail & passowrdconst useremail ='XXXXXXXXXXXXX';const apikey ='XXXXXXXXXXXXX';// Set the API Parameterconst fieldnumber="1";// Set API Urlconst api_url='https://www.api.automaticfarmsolutionwebapp.com/AFS/DeleteField?';// Set endpoint Urlconst apiEndpoint = api_url.concat("fieldnumber=", fieldnumber);(async () => {try {const authHeader =`Basic ${Buffer.from(`${useremail}:${apikey}`).toString('base64')}`;const response =await axios.delete(apiEndpoint, {headers: {'Content-Type':'application/json','Authorization': authHeader } });console.log('Answer From the API:', response.data); } catch (err) {console.error('Error:', err.message); }})();