Skip to main content

Delete File

To delete a file with the bArchive API, utilize the deleteFile method from the SDK.


Sample Code Snippet

Here is a JavaScript code snippet demonstrating the use of the deleteFile method:

import { Barchive, Network } from 'edeXa-sdk';

async function removeFile() {
const barchive = new Barchive({
...settings,
authorization: `Bearer ${token}`,
});
const settings = {
network: Network.SANDBOX, // or Network.MAINNET for the mainnet network
};

const dataToDeleteFile = {
id: FILE_ID,
}

try {
const deleteFileResponse = await barchive.deleteFile(dataToDeleteFile);
// Handle success
} catch (error) {
// Handle error
}
}


Key Points to Note

  • Asynchronous Function: The deleteFile function is an asynchronous (async) function, which uses await to pause execution until the barchive.deleteFile promise resolves. If the promise resolves successfully, the response for updating the file will be logged. In the event of an error, it will be caught and reported using console.error.
  • Token Replacement: Ensure to substitute token in the Authorization header with your actual token, obtained from the response of the authentication method.
  • File ID Replacement: Make sure to replace FILE_ID with the actual file ID you received after using the addFile method.

Request Parameters

ParameterRequiredTypeDescription
authorizationYesStringEnter your authentication token
idYesNumberEnter the id of the file you want to delete

Response Format

KeyTypeDescription
statusnumberStatus code of the response
messageStringResponse message