Skip to content

Instantly share code, notes, and snippets.

@marlluslustosa
Created May 30, 2021 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marlluslustosa/d2df55799c05cb838fbd3a79bc4a2401 to your computer and use it in GitHub Desktop.
Save marlluslustosa/d2df55799c05cb838fbd3a79bc4a2401 to your computer and use it in GitHub Desktop.
Export report goatcounter
#!/bin/bash
# https://www.goatcounter.com/code/api#export-64
token=$1
api=$2
curl() {
\command curl \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer $token" \
"$@"
}
# Start a new export, get ID from response object.
id=$(curl -X POST "$api/export" | jq .id)
# The export is started in the background, so we'll need to wait until it's finished.
while :; do
sleep 1
finished=$(curl "$api/export/$id" | jq .finished_at)
if [ "$finished" != "null" ]; then
# Download the export.
curl "$api/export/$id/download" | gzip -d
break
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment