# Remove a do-not-call entry. Only do this when the entry was added by mistake. Python 3.9+ with requests.
import os
import sys

import requests

base = os.environ.get("RELATIONSAI_API_BASE", "https://voice-api.relationsai.com/v1")
entry_id = os.environ.get("DNC_ENTRY_ID") or sys.exit("Set DNC_ENTRY_ID to the entry id (dnc_...)")

r = requests.delete(
    f"{base}/dnc-entries/{entry_id}",
    headers={
        "Authorization": f"Bearer {os.environ['RELATIONSAI_API_KEY']}",
    },
    timeout=30,
)
body = r.json()
if not r.ok:
    err = body["error"]
    sys.exit(f"{err['code']}: {err['message']} (request {err['request_id']})")
print(f"Removed {body['id']} deleted={body['deleted']}")
