Skip to content

Instantly share code, notes, and snippets.

@jumanjiman
Created September 28, 2022 15:26
Show Gist options
  • Save jumanjiman/54cf89d72386df95cf5114d4d156f39b to your computer and use it in GitHub Desktop.
Save jumanjiman/54cf89d72386df95cf5114d4d156f39b to your computer and use it in GitHub Desktop.
GH ratelimit in both REST and GraphQL
#!/usr/bin/env bash
set -eEu
set -o pipefail
# Use env var to hide corporate namespace.
GITHUB_BASE_URL="${GITHUB_BASE_URL:-https://ghe.example.com}"
echo 'Get ratelimit with REST API v3'
curl \
-H 'Accept: application/vnd.github+json' \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
--write-out 'HTTP response code %{http_code}' \
"${GITHUB_BASE_URL}/api/v3/rate_limit"
echo
echo
echo 'Get ratelimit with GraphQL API'
curl \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-X POST \
-d '{"query": "query GetRateLimit {rateLimit { used remaining resetAt } }"' \
--write-out 'HTTP response code %{http_code}' \
"${GITHUB_BASE_URL}/api/graphql"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment