#!/bin/bash set -e source ./config.sh # Get the Netflix Billing Page [[ -f "BillingActivity.html" ]] || curl -v 'https://www.netflix.com/BillingActivity'\ -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'\ --compressed \ --config .env.browser_fingerprint\ --config .env.netflix_cookies > BillingActivity.html # Download the last invoice LAST_INVOICE_URL=$(cat BillingActivity.html | grep -o '/invoice/print/[^"]*' | head -1) [[ -f "LastInvoice.html" ]] || curl -v --compressed --config .env.netflix_cookies "$NETFLIX_BASE_URL$LAST_INVOICE_URL" > LastInvoice.html # Convert to pdf [[ -f "LastInvoice.pdf" ]] || wkhtmltopdf LastInvoice.html LastInvoice.pdf # Leeto login [[ -f "leeto_auth_payload.json" ]] || curl -v 'https://api.leeto.co/api/v2/users/sign_in?locale=fr'\ -H 'Accept: application/json, text/plain, */*'\ --config .env.browser_fingerprint\ --compressed -H 'Content-Type: application/json'\ --data-raw '{"user":{"email":"'"$LEETO_EMAIL"'","password":"'"$LEETO_PASSWORD"'"}}' > leeto_auth_payload.json LEETO_BEARER_TOKEN=$(cat leeto_auth_payload.json | jq --raw-output '.token') LEETO_USER_ID=$(cat leeto_auth_payload.json | jq --raw-output '.id') curl -v "https://api.leeto.co/api/v2/organisations/$LEETO_ORGANISATION_ID/reimbursement_requests?locale=fr"\ -H 'Accept: application/json, text/plain, */*'\ --compressed \ --header "Authorization: Bearer $LEETO_BEARER_TOKEN"\ --config .env.browser_fingerprint\ --form "reimbursement_request[user_id]=$LEETO_USER_ID"\ --form "reimbursement_request[grantable_id]=$LEETO_USER_ID"\ --form "reimbursement_request[grantable_type]=User"\ --form "reimbursement_request[amount]=$LEETO_AMOUNT"\ --form "reimbursement_request[quotum_id]=$LEETO_QUOTUM_ID"\ --form "reimbursement_request[receipts_attributes][][image]=@LastInvoice.pdf"