#!/usr/bin/env bash # # SendPier Send API — read how much of your allowance is left. # # Requirements: bash and curl. # # Usage: # export SENDPIER_API_KEY='sp_live_...' # export SENDPIER_DOMAIN='example.com' # ./get-quota.sh # # The answer holds domain, monthly_limit, used_this_month and remaining. The # figures are those of the running period of this one domain -- a key never # sees another domain. # # Check this before a large batch rather than after a 429: once the allowance # is spent, every further message is refused with quota_exceeded until the # period rolls over or you add credits. set -euo pipefail API_BASE='https://api.sendpier.com' : "${SENDPIER_API_KEY:?set SENDPIER_API_KEY to your Send API key}" : "${SENDPIER_DOMAIN:?set SENDPIER_DOMAIN to the domain the key belongs to}" response=$(curl -sS "${API_BASE}/v1/quota" \ -H "Authorization: Bearer ${SENDPIER_API_KEY}" \ -H "X-Domain-Name: ${SENDPIER_DOMAIN}" \ -H 'Accept: application/json' \ -w '\n%{http_code}') status=$(printf '%s' "$response" | tail -n1) payload=$(printf '%s' "$response" | sed '$d') echo "$payload" if [ "$status" != '200' ]; then echo "request failed with HTTP ${status}" >&2 exit 1 fi