#!/usr/bin/env python3 """ Wipe all contacts from Resend so the contact list can be rebuilt from scratch. Contacts in Resend are global — this script paginates through all of them and deletes each one by email. Usage: export RESEND_API_KEY="re_..." python wipe_resend_contacts.py # delete all contacts python wipe_resend_contacts.py --dry-run # preview without deleting """ import argparse import os import sys import time import resend def fetch_all_contacts(): """Paginate through all contacts (API returns max 100 per page).""" all_contacts = [] after = None while True: params = {"limit": 100} if after: params["after"] = after response = resend.Contacts.list(params=params) data = response.data if hasattr(response, "data") else response if not data: break all_contacts.extend(data) has_more = response.has_more if hasattr(response, "has_more") else False if not has_more: break # Use last contact's ID as cursor for next page last = data[-1] after = last.id if hasattr(last, "id") else last["id"] return all_contacts def main(): parser = argparse.ArgumentParser(description="Wipe all Resend contacts") parser.add_argument( "--dry-run", action="store_true", help="Show contact count without deleting", ) args = parser.parse_args() api_key = os.environ.get("RESEND_API_KEY") if not api_key: sys.exit("Error: set RESEND_API_KEY environment variable") resend.api_key = api_key # Fetch all contacts (paginated) print("Fetching all contacts...") contacts = fetch_all_contacts() if not contacts: print("No contacts found.") return print(f"Found {len(contacts)} contact(s).") if args.dry_run: print("[DRY RUN] Would delete all of them. Run without --dry-run to proceed.") return # Delete each contact globally by email deleted = 0 failed = 0 for i, contact in enumerate(contacts, 1): c_email = contact.email if hasattr(contact, "email") else contact.get("email", "") c_id = contact.id if hasattr(contact, "id") else contact["id"] try: resend.Contacts.remove(email=c_email) deleted += 1 except Exception: try: resend.Contacts.remove(id=c_id) deleted += 1 except Exception as e: print(f" Failed: {c_email} — {e}") failed += 1 if i % 100 == 0: print(f" Progress: {i}/{len(contacts)}...") time.sleep(0.5) print(f"\nDone. Deleted {deleted}, failed {failed}.") if __name__ == "__main__": main()