-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebhook_setup.py
More file actions
63 lines (49 loc) · 1.7 KB
/
Copy pathwebhook_setup.py
File metadata and controls
63 lines (49 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""Example: Register, list, and manage webhooks.
Usage:
export LIVEPASSES_API_KEY="your-api-key"
python examples/webhook_setup.py
"""
from __future__ import annotations
import os
import sys
from livepasses import (
CreateWebhookParams,
Livepasses,
LivepassesError,
)
def main() -> None:
api_key = os.environ.get("LIVEPASSES_API_KEY", "")
if not api_key:
print("Set LIVEPASSES_API_KEY environment variable first.")
sys.exit(1)
client = Livepasses(api_key)
try:
# 1. Create a webhook for pass events
print("Registering webhook...")
webhook = client.webhooks.create(
CreateWebhookParams(
url="https://your-app.com/webhooks/livepasses",
events=["pass.generated", "pass.redeemed", "pass.checked_in", "batch.completed"],
)
)
print(f" Webhook ID: {webhook.id}")
print(f" URL: {webhook.url}")
print(f" Events: {', '.join(webhook.events)}")
print(f" Secret: {webhook.secret}")
print(" (Store this secret to verify incoming webhook signatures)\n")
# 2. List all registered webhooks
print("Listing all webhooks...")
webhooks = client.webhooks.list()
for wh in webhooks:
print(f" - {wh.id}: {wh.url} (active: {wh.is_active})")
print(f" Events: {', '.join(wh.events)}")
print()
# 3. Clean up — delete the webhook
print("Deleting webhook...")
client.webhooks.delete(webhook.id)
print(" Webhook deleted\n")
print("Done!")
except LivepassesError as e:
print(f"ERROR: API error [{e.code}]: {e}")
if __name__ == "__main__":
main()