Sample Automation: Submit Deletion Requests from a CSV (Python)

This example shows how to automate deletion requests using the Create Compliance Data Deletion Request (POST /compliance/requests/create-request) endpoint.

It reads a CSV containing emails, phones, or both, and submits one request per row.


CSV template

Save the following file as a .csv.

emails,phones
[email protected],+1-555-010-1010
[email protected],+1-555-020-2020

Notes

  • Column headers must be exactly: emails,phones
  • Either emails or phones (or both) may be provided per row
  • At least one value is required per row to trigger a deletion request

Python example script

Best practice: Store your API key in an environment variable instead of hardcoding it.

import csv
import requests
import os

API_URL = "https://api.triplewhale.com/api/v2/compliance/requests/create-request"
SHOP_DOMAIN = "madisonbraids.myshopify.com"

# 🔐 Best practice: store API key as an environment variable
API_KEY = os.getenv("TRIPLE_WHALE_API_KEY")

if not API_KEY:
    raise RuntimeError("Please set the TRIPLE_WHALE_API_KEY environment variable.")

def send_deletion_request(email, phone):
    payload = {
        "shop": SHOP_DOMAIN
    }

    if email:
        payload["emails"] = [email]

    if phone:
        payload["phones"] = [phone]

    headers = {
        "accept": "application/json",
        "content-type": "application/json",
        "x-api-key": API_KEY
    }

    response = requests.post(API_URL, json=payload, headers=headers, timeout=30)

    if response.ok:
        return "success", response.text
    else:
        return "failure", f"{response.status_code}: {response.text}"


def main():
    input_path = input("Enter path to CSV file: ").strip()
    output_path = "output.csv"

    with open(input_path, newline="", encoding="utf-8") as infile, \
         open(output_path, "w", newline="", encoding="utf-8") as outfile:

        reader = csv.DictReader(infile)
        fieldnames = reader.fieldnames + ["status", "message"]
        writer = csv.DictWriter(outfile, fieldnames=fieldnames)
        writer.writeheader()

        for row in reader:
            email = row.get("emails", "").strip()
            phone = row.get("phones", "").strip()

            if not email and not phone:
                row["status"] = "failure"
                row["message"] = "No email or phone provided"
            else:
                try:
                    status, message = send_deletion_request(email, phone)
                    row["status"] = status
                    row["message"] = message
                except Exception as e:
                    row["status"] = "failure"
                    row["message"] = str(e)

            writer.writerow(row)

    print(f"Done. Results written to {output_path}")


if __name__ == "__main__":
    main()

How to run the script

  1. Set your API key as an environment variable.

macOS / Linux

export TRIPLE_WHALE_API_KEY="YOUR_API_KEY"

Windows (PowerShell)

$env:TRIPLE_WHALE_API_KEY="YOUR_API_KEY"
  1. Install dependencies (if needed):
pip install requests
  1. Run the script:
python deletion_requests_from_csv.py

When prompted, enter the path to your CSV file.
Results will be written to output.csv, with status and message columns added for each row.


Common use cases

Automated deletion (one-by-one)

When an individual customer submits a deletion request (for example, via a support ticket), you can run this script with a CSV containing a single email and/or phone value to submit the request via the API.

Batch processing

If you receive a batch of deletion requests (for example, exported from a privacy tool), you can populate the CSV template and run the script to submit one request per row.

This example is provided to illustrate how the endpoint works. It does not include retry logic, rate-limit backoff, concurrency controls, or additional validation that may be required in a production environment.