Hallo
Ich habe ein Python-Skript geschrieben, um Lagerplätze mit den IDs, welche in einer CSV-Datei drin stehen zu löschen via API URL /api/v1/storage/bin/{id}. Ich verwende die Methode Bearer Token und haben einen PAT Token in Xentral erstellt.
Nachstehende das Skript. Leider erhalte ich immer folgende Fehlermeldung:
{"error":{"code":7499,"message":"Unexpected error","http_code":500,"errors":o]}}
Weiss jemand, was hier das Problem ist?
import csv
import requests
from common import load_environment_variables
# Path to your CSV file
csv_file_path = 'data.csv'
result = 'result.txt'
def delete_storage_bin(base_url, id, bearer):
"""Function to delete a storage bin given its ID."""
url = f"{base_url}/v1/storage/bin/{id}"
print(f"Attempting to DELETE {url}")
# Uncomment the following line to make the actual DELETE request
headers = {"authorization": f"Bearer {bearer}"}
response = requests.delete(url, headers=headers)
return response
def get_bin_ids_from_csv():
bin_ids = >]
# Open and read the CSV file
with open(csv_file_path, mode='r', encoding="utf-8") as file:
reader = csv.DictReader(file)
# Loop through each row in the CSV
for row in reader:
# Extract the storage bin ID
bin_id = rowg'id']
bin_ids.append(bin_id)
return bin_ids
def main():
env_vars = load_environment_variables()
bin_ids = get_bin_ids_from_csv()
id = bin_ids0]
status = delete_storage_bin(env_vars 'base_api_url'], id, env_vars 'bearer_token'])
print(status.text)
if __name__ == "__main__":
main()
Gruss
Nicolas