Skip to content

Instantly share code, notes, and snippets.

@kyeotic
Created March 31, 2026 20:35
Show Gist options
  • Select an option

  • Save kyeotic/a9a3ed42bb7be6b66d58cf70053da977 to your computer and use it in GitHub Desktop.

Select an option

Save kyeotic/a9a3ed42bb7be6b66d58cf70053da977 to your computer and use it in GitHub Desktop.
Get the Cloudflare Pages Subdomain
#!/bin/bash
# Reads account_id and project_name from stdin JSON, returns subdomain as JSON
set -euo pipefail
INPUT=$(cat)
ACCOUNT_ID=$(echo "$INPUT" | jq -r '.account_id')
PROJECT_NAME=$(echo "$INPUT" | jq -r '.project_name')
SUBDOMAIN=$(curl -sf \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
"https://api.cloudflare.com/client/v4/accounts/${ACCOUNT_ID}/pages/projects/${PROJECT_NAME}" \
| jq -r '.result.subdomain')
jq -n --arg subdomain "$SUBDOMAIN" '{"subdomain": $subdomain}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment