← back to Dw Signup Fulfillment
apply-verified-tag.sh
33 lines
#!/usr/bin/env bash
# TK-10830 — apply the verified-sample entitlement tag to Kelly's EXISTING customer
# (id 8388564123699). This is the end-state the verify-click produces (completeVerification
# -> addTags), applied directly since Shopify's search index is blind to this record so the
# /claim + verify flow can't resolve it. Idempotent (merges, never drops existing tags).
set -euo pipefail
CID=8388564123699
FT="$(grep -E '^SHOPIFY_FULFILLMENT_TOKEN=' "$HOME/Projects/secrets-manager/.env" | cut -d= -f2-)"
SHOP="designer-laboratory-sandbox.myshopify.com"
BASE="https://$SHOP/admin/api/2024-10"
cur="$(curl -s "$BASE/customers/$CID.json" -H "X-Shopify-Access-Token: $FT")"
oldtags="$(echo "$cur" | python3 -c "import sys,json;print(json.load(sys.stdin).get('customer',{}).get('tags',''))")"
echo "current tags: [$oldtags]"
# merge desired tags into existing
newtags="$(python3 - "$oldtags" <<'PY'
import sys
have=[t.strip() for t in sys.argv[1].split(',') if t.strip()]
want=['verified-sample','zopim-referral','tk-10830']
for w in want:
if w.lower() not in [h.lower() for h in have]: have.append(w)
print(', '.join(have))
PY
)"
echo "new tags: [$newtags]"
printf '{"customer":{"id":%s,"tags":"%s"}}' "$CID" "$newtags" > /tmp/kelly-tag-update.json
resp="$(curl -s -X PUT "$BASE/customers/$CID.json" -H "X-Shopify-Access-Token: $FT" -H "Content-Type: application/json" --data @/tmp/kelly-tag-update.json)"
echo "$resp" | python3 -c "import sys,json
c=json.load(sys.stdin).get('customer')
print('UPDATED customer',c['id'],'tags now:',repr(c.get('tags'))) if c else print('FAIL:',sys.stdin.read()[:300])"