-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebhooks.sh
More file actions
50 lines (44 loc) · 1.51 KB
/
webhooks.sh
File metadata and controls
50 lines (44 loc) · 1.51 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
#!/bin/bash
# Webhook management via the Postcard.bot API
# Usage: POSTCARDBOT_API_KEY=pk_live_your_key bash webhooks.sh [create|list|delete <id>]
if [ -z "$POSTCARDBOT_API_KEY" ]; then
echo "Set POSTCARDBOT_API_KEY environment variable"
exit 1
fi
BASE_URL="${POSTCARDBOT_API_URL:-https://postcard.bot}"
ACTION="${1:-list}"
case "$ACTION" in
create)
URL="${2:-https://example.com/webhooks}"
echo "Creating webhook for $URL..."
curl -s -X POST "$BASE_URL/api/v1/webhooks" \
-H "Authorization: Bearer $POSTCARDBOT_API_KEY" \
-H "Content-Type: application/json" \
-d "{
\"url\": \"$URL\",
\"events\": [\"postcard.created\", \"postcard.sent\", \"postcard.delivered\", \"postcard.failed\", \"postcard.returned\"]
}" | python3 -m json.tool 2>/dev/null || cat
echo ""
echo "IMPORTANT: Save the 'secret' above — it won't be shown again."
;;
list)
echo "Listing webhooks..."
curl -s "$BASE_URL/api/v1/webhooks" \
-H "Authorization: Bearer $POSTCARDBOT_API_KEY" \
| python3 -m json.tool 2>/dev/null || cat
;;
delete)
WEBHOOK_ID="$2"
if [ -z "$WEBHOOK_ID" ]; then
echo "Usage: bash webhooks.sh delete <webhook_id>"
exit 1
fi
echo "Deleting webhook $WEBHOOK_ID..."
curl -s -X DELETE "$BASE_URL/api/v1/webhooks/$WEBHOOK_ID" \
-H "Authorization: Bearer $POSTCARDBOT_API_KEY" \
| python3 -m json.tool 2>/dev/null || cat
;;
*)
echo "Usage: bash webhooks.sh [create <url>|list|delete <id>]"
;;
esac