Skip to main content
import { getToken } from "./get_auth_token.js";

const bulkDelete = async () => {
const apiToken = await getToken();
const assetsIDs = await getListOffAllDataAssets(apiToken);
const deleteResponseCollection = [];
for (const assetID of assetsIDs) {
const response = await deleteDataAsset(apiToken, assetID);
deleteResponseCollection.push({ assetID, response });
}
};

const getListOffAllDataAssets = (token) => {
const url = "https://maestro.dadosfera.ai/catalog?size=500&page=1&order=asc&pipeline_id=4848345b-3237-413f-b63e-27f70d0bb3e2";

return fetch(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `${token}`,
},
})
.then((response) => {
if (response.ok) return response.json();
else throw response.statusText;
})
.then((data) => {
const assetsIDs = [];
data.data_assets.forEach((asset) => {
assetsIDs.push(asset.id);
});
return assetsIDs;

});
};

const deleteDataAsset = (token, assetID) => {
const url = `https://maestro.dadosfera.ai/catalog/data-asset/${assetID}`;

return fetch(url, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
Authorization: `${token}`,
},
})
.then((response) => {
if (response.ok) return response.json();
else throw response.statusText;
});
};
{"success":true}

Get API auth token

For any API request it is necessary to have the authentication token, this recipe demonstrates how to get it.

Get the list of data assets IDs

Get the list of data assets IDs you want to delete. In this case we are deleting all assets generated from a certain pipeline

Delete data assets

Using the list of IDs execute a loop to delete calling the data assets delete route.

Observation of requests

Note that the functions that make the requests have a configuration and request pattern.