Delete Field

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:

  1. USEREMAIL
  2. APIKEY
  3. fieldnumber, the id of the field that you want to delete
#| eval: false

# Load the libraries

import requests
from requests.auth import HTTPBasicAuth

# Define the API call parameters

fieldnumber="1" # the fieldnumber to delete

# Define the url of the API

url = "https://www.api.automaticfarmsolutionwebapp.com/AFS/DeleteField?fieldnumber="+fieldnumber

# Set the useremail & Password

USEREMAIL="useremail"
APIKEY="apikey"

# Set the headers for the request

headers = {
    "Content-Type": "application/json"
}

# Make the POST request with the GeoJSON data as the request body

response = requests.delete(url, 
                         headers=headers,
                         auth=HTTPBasicAuth(USEREMAIL, APIKEY))
                      
# if the following line is 200 so the field was successfully deleted
print(response.status_code)
400

R

In order to use the endpoint you have to set the following parameter:

  1. USEREMAIL
  2. APIKEY
  3. fieldnumber, the id of the field that you want to delete
# Load the library

library(httr)

# Define the user and password

USEREMAIL="useremail"
APIKEY="apikey"

# Define the fieldnumber to delete

fieldnumber<-1

# Define the endpoint

api_endpoint <- "https://www.api.automaticfarmsolutionwebapp.com/AFS/DeleteField?fieldnumber=" 

# Define the API Call

API_URL<-paste0(api_endpoint, fieldnumber)

# Make the API Call

response <- DELETE(
  API_URL,
  httr::authenticate(
    user = USEREMAIL,
    password = APIKEY
  )
)

# Check the status if 200, the field was deleted

response$status_code

Node.js

In order to use the endpoint you have to set the following parameter:

  1. USEREMAIL
  2. APIKEY
  3. fieldnumber, the id of the field that you want to delete
// Load Libraries

const fs = require('fs');
const axios = require('axios');

// Set the useremail & passowrd

const useremail = 'XXXXXXXXXXXXX';
const apikey = 'XXXXXXXXXXXXX';

// Set the API Parameter

const fieldnumber="1";

// Set API Url

const api_url='https://www.api.automaticfarmsolutionwebapp.com/AFS/DeleteField?';

// Set endpoint Url

const 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);
  }
})();
Back to top