Destructive example: the source lists only page 1 (up to 500 assets), filtered by an example
pipeline_id. Replace that ID and review the selected assets before callingbulkDelete(). This is not a complete paginated export. Save the authentication helper asget_auth_token.jsand use Node.js 18+ with ES modules enabled. The response block below is the source's illustrative placeholder, not the function's return shape.
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 });
}
return deleteResponseCollection;
};
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; the authorization 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.