← back to Secrets Manager

find-theme-token.sh

33 lines

#!/usr/bin/env bash
# find-theme-token.sh — identify which already-stored DW Shopify token carries
# read_themes/write_themes scope, by probing the themes.json endpoint (needs read_themes).
# READ-ONLY: prints only the var NAME + last-4 + HTTP result. Never prints a full token.
# Companion to find-content-token.sh. For the collection-AEO theme-template deploy
# (DTD verdict A 2026-07-21). The "Theme Editor" app (dashboard id 312098) is the
# expected holder — if its token is stored under any of these names it shows CONTENT OK.
set -euo pipefail
cd "$(dirname "$0")"
STORE="designer-laboratory-sandbox.myshopify.com"
API="2024-10"
CANDIDATES=(SHOPIFY_THEME_TOKEN SHOPIFY_THEME_EDITOR_TOKEN SHOPIFY_ADMIN_TOKEN \
            SHOPIFY_CONTENT_TOKEN SHOPIFY_DRAFT_TOKEN SHOPIFY_ORDERS_TOKEN)
WINNER=""
for n in "${CANDIDATES[@]}"; do
  line=$(grep -m1 "^${n}=" .env 2>/dev/null || true)
  [ -z "$line" ] && { printf '%-30s — not stored\n' "$n"; continue; }
  tok="${line#*=}"; tok="${tok%\"}"; tok="${tok#\"}"; tok="${tok%\'}"; tok="${tok#\'}"
  code=$(curl -s -o /dev/null -w '%{http_code}' \
         "https://$STORE/admin/api/$API/themes.json" \
         -H "X-Shopify-Access-Token: $tok")
  if [ "$code" = "200" ]; then
    printf '%-30s …%s  →  ✅ THEMES OK (has read_themes)\n' "$n" "${tok: -4}"
    [ -z "$WINNER" ] && WINNER="$n"
  elif [ "$code" = "403" ]; then
    printf '%-30s …%s  →  403 (no themes scope)\n' "$n" "${tok: -4}"
  else
    printf '%-30s …%s  →  HTTP %s\n' "$n" "${tok: -4}" "$code"
  fi
done
echo "---"
[ -n "$WINNER" ] && echo "USABLE_THEME_TOKEN=$WINNER" || echo "USABLE_THEME_TOKEN=none — reveal the Theme Editor app (312098) token, or grant read_themes+write_themes"