import requests
import csv
Define your API endpoint and credentials for deleting a location
delete_location_base_url = “http://localhost:8000/api/resource/Location/”
api_key = “1d39"
api_secret = "dc*7”
headers = {
“Authorization”: f"token {api_key}:{api_secret}",
“Content-Type”: “application/json”,
}
CSV file path
csv_file_path = “/apps/bench/frappe/apps/delete_process/location_list.csv”
Read CSV file and delete locations
with open(csv_file_path, ‘r’) as file:
reader = csv.DictReader(file)
for row in reader:
# Assuming your CSV has a column named "location"
location_name = row.get('location')
# Skip rows where the location name is not provided
if location_name:
# Check if the location exists before attempting deletion
check_location_api_url = delete_location_base_url + location_name
check_location_response = requests.get(check_location_api_url, headers=headers)
if check_location_response.status_code == 200:
# Location exists, proceed with deletion
delete_location_api_url = delete_location_base_url + location_name
location_response = requests.delete(delete_location_api_url, headers=headers)
if location_response.status_code == 202:
print(f"Location '{location_name}' deleted successfully.")
else:
print(f"Failed to delete location '{location_name}'. Status code: {location_response.status_code}")
print(f"Response text: {location_response.text}")
elif check_location_response.status_code == 404:
print(f"Location '{location_name}' does not exist. Skipping deletion.")
else:
print(f"Failed to check location '{location_name}'. Status code: {check_location_response.status_code}")
print(f"Response text: {check_location_response.text}")
Using this code, I am able to delete location,
then Why I can’t delete Asset?
Anyone can help me?