Last active
June 16, 2021 04:03
-
-
Save simonmichael/62cc9661569cdea990dc2020ac36582a to your computer and use it in GitHub Desktop.
paypalcsv - download transactions CSV from Paypal's API
This file contains 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 | |
# Download last 30 days of transaction history from Paypal as CSV. | |
# brew install jsonpp jq | |
# npm install -g json2csv | |
# credentials from an API app created in https://developer.paypal.com | |
CLIENT_ID= | |
SECRET= | |
TOKEN=`curl -s https://api-m.paypal.com/v1/oauth2/token -d "grant_type=client_credentials" -u "$CLIENT_ID:$SECRET" | jq .access_token -r` | |
# max date range is 31d | |
START=`date -v-30d +%Y-%m-%dT00:00:00%z` | |
END=`date -v+1d +%Y-%m-%dT00:00:00%z` | |
# max page size is 500, so this will fetch at most 500 transactions. | |
# sed strips the field name prefixes, while keeping them unique | |
curl -s -H "Authorization: Bearer $TOKEN" "https://api.paypal.com/v1/reporting/transactions?start_date=$START&end_date=$END&fields=all&page_size=500&page=1" \ | |
| json2csv --unwind --flatten-objects \ | |
| sed -E -e '1s/([^\.]+)\.(value|currency_code)/\1_\2/g' -e '1s/"[^"]*\.([^"]*)"/"\1"/g' | |
# or this ? | |
#curl -s -H "Authorization: Bearer $TOKEN" "https://api.paypal.com/v1/reporting/transactions?start_date=$START&end_date=$END&fields=all&page_size=500&page=1" \ | |
#| jq '.transaction_details' \ | |
#| json2csv --unwind --flatten-objects \ | |
#| sed -E -e '1s/([^\.]+)\.(value|currency_code)/\1_\2/g' -e '1s/"[^"]*\.([^"]*)"/"\1"/g' | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If anybody gets a "PERMISSION_DENIED, No Permission for the requested operation" error when running this, the solution is simply to add
-H "Accept: application/json" -H "Accept-Language: en_US"
to thecurl
TOKEN request on line 11: