Created
May 30, 2021 20:45
-
-
Save marlluslustosa/d2df55799c05cb838fbd3a79bc4a2401 to your computer and use it in GitHub Desktop.
Export report goatcounter
This file contains hidden or 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
#!/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