Skip to Content

Webhooks

Download notebook (.ipynb)

Register an HTTPS endpoint for Indox events, then read, update, rotate its secret, list its deliveries and delete it. Set WEBHOOK_URL to your own endpoint. Nothing is sent to it unless SEND_TEST_DELIVERY = True.

Config

Add your settings to the repo .env (local) or Colab Secrets — this cell reads them with get(...): INDOX_API_KEY (your ak_… key) and INDOX_BASE_URL (https://indox.org; the SDK adds /api/v1/… itself). A missing key stops here with its name.

import json, logging, re, sys, tempfile from pathlib import Path REPO = Path.cwd().parents[1] sys.path[:0] = [str(REPO), str(REPO / "languages" / "python")] try: from google.colab import userdata get = userdata.get except ImportError: from tools.env import require_env as get from indox_client import Indox logging.basicConfig(format="→ %(message)s", force=True) logging.getLogger("urllib3.connectionpool").setLevel(logging.DEBUG) def _mask(record): record.msg = re.sub(r"/(public|sign)/[^/ ]+", r"/\1/***", record.getMessage()) record.args = () return True logging.getLogger("urllib3.connectionpool").addFilter(_mask) def show(data, limit=2500): print(json.dumps(data, indent=2, default=str)[:limit]) client = Indox(api_key=get("INDOX_API_KEY"), base_url=get("INDOX_BASE_URL")) start_credits = client.billing.credits_balance()["credit_amount"] SAMPLES = REPO / "colab" out = Path(tempfile.mkdtemp()) WEBHOOK_URL = "https://example.com/indox-webhook" SEND_TEST_DELIVERY = False
created = client.webhooks.create( {"url": WEBHOOK_URL, "events": ["conversion.completed", "credits.low"], "description": "SDK notebook"} ) hook = created["webhook"] show(hook) assert created["secret"] and hook["url"] == WEBHOOK_URL
hooks = client.webhooks.list() show(hooks) assert hook["id"] in [h["id"] for h in hooks]
fetched = client.webhooks.get(hook["id"]) show(fetched) assert fetched["events"] == hook["events"]
updated = client.webhooks.update(hook["id"], {"description": "SDK notebook (paused)", "is_active": False}) show(updated) assert updated["is_active"] is False
rotated = client.webhooks.rotate_secret(hook["id"]) show({"masked_secret": rotated["masked_secret"]}) assert rotated["secret"] != created["secret"]
deliveries = client.webhooks.deliveries(hook["id"]) show(deliveries) assert deliveries["count"] >= len(deliveries["results"])
if SEND_TEST_DELIVERY: sent = client.webhooks.test(hook["id"]) show(sent) assert sent["queued"] else: print("skipped: webhooks.test posts to WEBHOOK_URL (SEND_TEST_DELIVERY = False)")
show(client.webhooks.delete(hook["id"])) assert hook["id"] not in [h["id"] for h in client.webhooks.list()]

Usage

now = client.billing.credits_balance()["credit_amount"] print(f"credits used by this notebook: {start_credits - now} (balance {now})") show(client.billing.usage_by_feature())