IPFS Pinning
Delete File (Unpin)
IPFS Pinning
Delete File (Unpin)
Delete a file by CID
DELETE
/
pinning
/
unpin
/
{CID}
Authorization
string
*
Bearer
Authorization
Required
string
Bearer authentication header of the form Bearer <token>
, where <token>
is your auth token.
CID
string
*
CID
Required
string
If you find yourself in a place where you need to unpin a lot of files or perhaps all your files, you can use a script like this to create an array of CIDs and unpin them one by one. The example below uses the pinList
queries to target all pinned files and return 1000 for each request. This could easily be done with a different query to target different files, please check out the listing files doc for more info.
Unpin All Files
const PINATA_JWT = "YOUR_JWT_HERE";
const PIN_QUERY = `https://api.pinata.cloud/data/pinList?status=pinned&pageLimit=1000&includeCount=false`;
const fetch = require("node-fetch");
const wait = (milliseconds) => {
return new Promise((resolve) => {
setTimeout(resolve, milliseconds);
});
};
const fetchPins = async () => {
try {
console.log("Fetching pins...");
let pinHashes = [];
let pageOffset = 0;
let hasMore = true;
while (hasMore === true) {
try {
const response = await fetch(`${PIN_QUERY}&pageOffset=${pageOffset}`, {
method: "GET",
headers: {
accept: "application/json",
Authorization: `Bearer ${PINATA_JWT}`,
},
});
const responseData = await response.json();
const rows = responseData.rows;
if (rows.length === 0) {
hasMore = false;
}
const itemsReturned = rows.length;
pinHashes.push(...rows.map((row) => row.ipfs_pin_hash));
pageOffset += itemsReturned;
await wait(300);
} catch (error) {
console.log(error);
break;
}
}
console.log("Total pins fetched: ", pinHashes.length);
return pinHashes;
} catch (error) {
console.log(error);
}
};
const deletePins = async () => {
const pinHashes = await fetchPins();
const totalPins = pinHashes.length;
let deletedPins = 0;
try {
for (const hash of pinHashes) {
try {
const response = await fetch(
`https://api.pinata.cloud/pinning/unpin/${hash}`,
{
method: "DELETE",
headers: {
Authorization: `Bearer ${PINATA_JWT}`,
},
}
);
await wait(300);
deletedPins++;
process.stdout.write(`Deleted ${deletedPins} of ${totalPins} pins\r`);
} catch (error) {
console.log(error);
}
}
console.log("Pins deleted");
} catch (error) {
console.log(error);
}
};
deletePins();
Authorizations
Authorization
string
headerrequiredBearer authentication header of the form Bearer <token>
, where <token>
is your auth token.
Path Parameters
CID
string
requiredResponse
200 - text/plain
The response is of type string
.