How to Delete Files On-Demand with cURL

Learn how to call the pdfRest Delete Files API with cURL to instantly remove files you’ve uploaded or generated.
Share this page

Why Delete Files with cURL?

The pdfRest Delete Files API Tool provides a straightforward way to remove files from your storage using a simple API call. This tutorial will guide you through the process of sending an API call to the Delete Files endpoint using cURL, a command-line tool for transferring data with URLs. By leveraging cURL, you can automate file deletion within your pdfRest workflow, making it an essential tool for developers and system administrators.

Consider a scenario where you have uploaded multiple PDF files to the pdfRest service for processing. Once the processing is complete, you may no longer need these files stored in the cloud. Using the Delete Files API, you can efficiently manage your storage by removing unnecessary files.

Delete Files with cURL Code Example

# By default, we use the US-based API service. This is the primary endpoint for global use.
API_URL="https://api.pdfrest.com"

# For GDPR compliance and enhanced performance for European users, you can switch to the EU-based service by uncommenting the URL below.
# For more information visit https://pdfrest.com/pricing#how-do-eu-gdpr-api-calls-work
# API_URL="https://eu-api.pdfrest.com"

curl -X POST "$API_URL/delete" \
  -H "Accept: application/json" \
  -H "Content-Type: multipart/form-data" \
  -H "Api-Key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" \
  -F "ids=xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

Source: GitHub - pdf-rest-api-samples

Breaking Down the Code

The code begins by setting the API_URL variable to the US-based API service endpoint:

API_URL="https://api.pdfrest.com"

This is the default endpoint for global use. If you need to comply with GDPR or require better performance in Europe, you can switch to the EU-based service by uncommenting the relevant line.

The cURL command is used to send a POST request to the Delete Files endpoint:

curl -X POST "$API_URL/delete"

The -X POST option specifies that the request method is POST, which is necessary for the Delete Files operation.

Several headers are included in the request:

-H "Accept: application/json"
-H "Content-Type: multipart/form-data"
-H "Api-Key: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

The Accept header indicates that the client expects a JSON response. The Content-Type header specifies that the request payload is multipart/form-data, which is suitable for sending form data. The Api-Key header contains your unique API key, which authenticates your request.

The -F option is used to specify form data:

-F "ids=xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

This line includes the ids parameter, which is a comma-separated list of file IDs you wish to delete. These IDs must be valid and correspond to files stored in your pdfRest account.

Beyond the Tutorial

In this tutorial, you learned how to send a cURL request to the pdfRest Delete Files API to remove files from the pdfRest Cloud service. This is a powerful way to manage your files programmatically. To explore more functionalities, try out all the pdfRest API Tools in the API Lab. For detailed information on each API, refer to the API Reference Guide.

Note: This example demonstrates a multipart API call. For code samples using JSON payloads, visit GitHub - JSON Payload Examples.

Generate a self-service API Key now!
Create your FREE API Key to start processing PDFs in seconds, only possible with pdfRest.