Skip to content

Instantly share code, notes, and snippets.

@TaylorJadin
Last active Aug 30, 2022
Embed
What would you like to do?
Submit multiple URLS to gtmetrix using their API
#!/bin/bash
# Config
GTMETRIX_API_KEY=
SLEEP_TIME=5
# Functions
function submit_test {
curl -s -u $GTMETRIX_API_KEY: \
-X POST -H Content-Type:application/vnd.api+json \
"https://gtmetrix.com/api/2.0/tests" \
-d '{"data":{"type":"test","attributes":{"url":"'$URL'"}}}'
}
# Loop through URLs and submit tests
for URL in "$@"; do
test=`submit_test`
while [[ $test == *'status":"429"'* ]]; do
sleep $SLEEP_TIME
test=`submit_test`
done
echo "Submitted test for: $URL"
done
echo "Tests submitted, check results by logging in at https://gtmetrix.com"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment