Overview
I had the opportunity to bulk delete multiple content items using the Drupal REST API, so this is a memo of the process.
References
For a method to bulk delete content without using the REST API, please refer to the following.
Preparation
First, enable the HTTP Basic Authentication module and the JSON:API module.
Additionally, enable DELETE in REST resources.
/admin/config/services/rest


Execution Example
The following custom library is used.
https://github.com/nakamura196/drupal_tools
You can also review the processing details at the following link.
https://nakamura196.github.io/drupal_tools/
Installation
pip install git+https://github.com/nakamura196/drupal_tools
Preparing the .env File
DRUPAL_URL=http://example.org/drupal
DRUPAL_USERNAME=username
DRUPAL_PASSWORD=password
Execution
Run as follows.
item_ids is a list of unique values corresponding to field_name (in this case, field_item_id).
from drupal_tools.api import DrupalAPIClient
import pandas as pd
def get_item_ids():
# Load a CSV file containing item ids into a DataFrame.
df = pd.read_csv("./uuids.csv")
item_ids = [row["asset_uuid"] for _, row in df.iterrows()]
return item_ids
# Call the function to get the list of item ids.
item_ids = get_item_ids()
# Load Drupal credentials from a .env file using the DrupalAPIClient.
DRUPAL_URL, DRUPAL_USERNAME, DRUPAL_PASSWORD = DrupalAPIClient.load_credentials("../.env")
# Create an instance of the DrupalAPIClient with the loaded credentials.
drupal = DrupalAPIClient(DRUPAL_URL, DRUPAL_USERNAME, DRUPAL_PASSWORD)
field_name = "field_item_id"
nids = drupal.get_nids(item_ids, field_name)
results = drupal.delete_from_nids(nids)
Summary
Please note that there may be bugs, so exercise caution when using this.
I hope this serves as a helpful reference.