> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pinata.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# Delete File (Unpin)

> Delete a file by CID

<Accordion title="Unpin All Files">
  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`](/api-reference/endpoint/ipfs/list-files) 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](/files/listing-files) doc for more info.

  ```javascript Unpin All Files theme={null}
  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();
  ```
</Accordion>


## OpenAPI

````yaml delete /pinning/unpin/{CID}
openapi: 3.0.0
info:
  title: Pinata API
  description: ''
  termsOfService: https://www.pinata.cloud/terms-conditions
  contact:
    name: Pinata Team
    email: team@pinata.cloud
  version: 1.0.0
servers:
  - url: https://api.pinata.cloud
security:
  - bearerAuth: []
paths:
  /pinning/unpin/{CID}:
    delete:
      summary: Delete File (Unpin)
      description: Delete a file by CID
      parameters:
        - name: CID
          in: path
          required: true
          style: simple
          explode: false
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            text/plain:
              schema:
                type: string
                example: OK
      security:
        - bearerAuth: []
      servers:
        - url: https://api.pinata.cloud
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````