os/pkgs/fetch-hostingde-invoices.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

39 lines
923 B
Nix
Raw Normal View History

self:
with self; ''
set -e
PATH="$PATH:${jq}/bin:${curl}/bin"
SECRET_FILE=$1
OUT_DIR=$2
AUTH_TOKEN=$(cat $SECRET_FILE)
CURL_BODY=$(cat <<EOF
{
"limit": 10,
"sort": {
"field": "documentDate",
"order": "DESC"
},
"authToken": "$AUTH_TOKEN"
}
EOF)
CURL_URL="https://secure.hosting.de/api/billing/v1/json/documentsFind"
echo "fetching $CURL_URL";
documents=$(curl -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d "$CURL_BODY" "$CURL_URL" | jq '.response.data.[].documentId' -rc)
for doc in $documents; do
CURL_BODY=$(cat <<EOF
{
"id": "$doc",
"authToken": "$AUTH_TOKEN"
}
EOF)
CURL_URL="https://secure.hosting.de/api/billing/v1/json/accountingDocumentPdfGet"
echo "fetching $doc";
url=$(curl -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d "$CURL_BODY" "$CURL_URL" | jq '.response' -rc)
curl $url >> "$OUT_DIR/$doc.pdf"
done
''