← back to Dw Signup Fulfillment
arm-webhook.sh.DISABLED-duplicate-webhook-2026-09-02
25 lines
#!/usr/bin/env bash
# TK-11114 Part C — register the customers/create webhook so every DW signup triggers
# the verify letter. Idempotent: skips if one is already registered. Run as Steve:
# ! bash ~/Projects/dw-signup-fulfillment/arm-webhook.sh
# PREREQ (Part B): the LIVE service must already have WEBHOOK_URL_TOKEN (matching secrets)
# + VERIFY_SECRET + VERIFIED_TAG=verified-sample + PUBLIC_URL, or the webhook fires but the
# verify letter 503s. And Part A (the Regios verified-sample rule) must exist first.
set -euo pipefail
SHOP="designer-laboratory-sandbox.myshopify.com"
BASE="https://$SHOP/admin/api/2024-10"
PUBLIC_URL="https://signup.designerwallcoverings.com"
FT="$(grep -E '^SHOPIFY_FULFILLMENT_TOKEN=' "$HOME/Projects/secrets-manager/.env" | cut -d= -f2-)"
WT="$(grep -E '^WEBHOOK_URL_TOKEN=' "$HOME/Projects/secrets-manager/.env" | cut -d= -f2-)"
[ -z "$WT" ] && { echo "ABORT: WEBHOOK_URL_TOKEN not in secrets-manager/.env"; exit 1; }
existing="$(curl -s "$BASE/webhooks.json?topic=customers/create" -H "X-Shopify-Access-Token: $FT" \
| python3 -c "import sys,json;print(len(json.load(sys.stdin).get('webhooks',[])))")"
if [ "$existing" != "0" ]; then echo "Already registered ($existing customers/create webhook). Nothing to do."; exit 0; fi
printf '{"webhook":{"topic":"customers/create","address":"%s/webhooks/customers/create/%s","format":"json"}}' "$PUBLIC_URL" "$WT" > /tmp/dw-webhook.json
resp="$(curl -s -X POST "$BASE/webhooks.json" -H "X-Shopify-Access-Token: $FT" -H "Content-Type: application/json" --data @/tmp/dw-webhook.json)"
echo "$resp" | python3 -c "import sys,json
w=json.load(sys.stdin).get('webhook')
print('REGISTERED webhook id =',w['id'],'-> rollback: DELETE /webhooks/'+str(w['id'])+'.json') if w else print('FAIL:',sys.stdin.read()[:400])"