Skip to content

Instantly share code, notes, and snippets.

@greyhoundforty
Created August 11, 2020 18:33
Show Gist options
  • Save greyhoundforty/ab22765762e95bce563ee654e85a0ccf to your computer and use it in GitHub Desktop.
Save greyhoundforty/ab22765762e95bce563ee654e85a0ccf to your computer and use it in GitHub Desktop.
Pull Billing information via API and export in CSV format

Generate IAM Token

export IBMCLOUD_API_KEY=<your IBM cloud API key>

iam_token=`curl -s -k -X POST --header "Content-Type: application/x-www-form-urlencoded" --header "Accept: application/json" --data-urlencode "grant_ty
pe=urn:ibm:params:oauth:grant-type:apikey" --data-urlencode "apikey=${IBMCLOUD_API_KEY}" "https://iam.cloud.ibm.com/identity/token"  | jq -r '(.token_type + " " + .access
_token)'`

Pull usage for month in CSV format

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