Skip to content

Instantly share code, notes, and snippets.

@khayama-zz
Forked from greyhoundforty/billing-pull.md
Last active August 18, 2020 13:52
Show Gist options
  • Save khayama-zz/7e00d7248c65dc196f6fb1775e4baac8 to your computer and use it in GitHub Desktop.
Save khayama-zz/7e00d7248c65dc196f6fb1775e4baac8 to your computer and use it in GitHub Desktop.
Pull Billing information via API and export in CSV format

Generate IAM Token

export IAM_TOKEN=`ibmcloud iam oauth-tokens | head -n 1 | awk '{print $4}'`
echo $IAM_TOKEN

Get Account ID

export ACCOUNT_ID=`ibmcloud account show | head -n 5 | tail -n 1 | awk '{print $3}'`
echo $ACCOUNT_ID

Pull usage for month in CSV format

YEAR_MONTH=2020-08

curl -s -X GET "https://billing.cloud.ibm.com/v4/accounts/${ACCOUNT_ID}/resource_instances/usage/${YEAR_MONTH}?format=csv" -H "Authorization: Bearer ${IAM_TOKEN}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment