Created
February 20, 2025 09:34
-
-
Save falexandrou/823ecaee45e364a97e350955e5024974 to your computer and use it in GitHub Desktop.
callVercelToken.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Export these as environment variables either in this file or elsewhere | |
VERCEL_BYPASS_TOKEN='<deployment bypass token found in Vercel settings>' | |
CRON_SECRET='<cron secret set up as environment variable>' | |
function callVercelCron() { | |
# Function documentation | |
local usage=" | |
Usage: callVercelCron <URL> | |
Makes an HTTP GET request to the specified URL with a bearer token provided in the script. | |
Arguments: | |
URL : The API endpoint URL (required) | |
Example: | |
callVercelCron 'https://api.example.com/endpoint' | |
" | |
# Check if URL is provided | |
if [ $# -eq 0 ]; then | |
echo "Error: URL parameter is missing" | |
echo "$usage" | |
return 1 | |
fi | |
local URL=$1 | |
local TOKEN=$CRON_SECRET | |
# Check if token is available | |
if [ -z "$TOKEN" ]; then | |
echo "Error: Bearer token is not set in the script" | |
echo "$usage" | |
return 1 | |
fi | |
# Make the API call using curl | |
local response | |
response=$(curl -s -X GET \ | |
-H "Authorization: Bearer ${TOKEN}" \ | |
-H "X-Vercel-Protection-Bypass: ${VERCEL_BYPASS_TOKEN}" \ | |
-H "Content-Type: application/json" \ | |
"${URL}") | |
# Check if curl command was successful | |
if [ $? -eq 0 ]; then | |
# Print the response (try to format with jq if available) | |
echo "${response}" | jq '.' 2>/dev/null || echo "${response}" | |
return 0 | |
else | |
echo "Error: Failed to make the API call" | |
return 1 | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment