I want to delete my grafana board using the api in a simple web page that I have created, I have tried everything but it does not work, help me.
<!DOCTYPE html>
<html>
<head>
<title>Delete Grafana Dashboard</title>
</head>
<body>
<h1>Delete Grafana Dashboard</h1>
<button onclick="deleteDashboard()">Delete Dashboard</button>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>
// Grafana API Configuration
const apiKey = 'your-api-token-here'; // Replace this with your API token
const grafanaBaseUrl = 'https://your-instance.grafana.net/api/'; // Replace this with your Grafana instance URL
const dashboardUid = 'your-uid-here'; // Replace this with the uid of the dashboard you want to delete
// Function to delete the dashboard
async function deleteDashboard() {
try {
// Delete the dashboard
await axios.delete(grafanaBaseUrl + 'dashboards/uid/' + dashboardUid, {
headers: {
'Authorization': `Bearer ${apiKey}`,
'Accept': 'application/json',
'Content-Type': 'application/json'
}
});
alert('Dashboard deleted successfully.');
} catch (error) {
console.error('Error deleting the dashboard:', error);
alert('Error deleting the dashboard. Check the console for more details.');
}
}
</script>
</body>
</html>