Notes on cloudflare api and Jq

2016-07-16

Notes on cloudflare api and Jq

Jq is a great tool Link . It makes working with json from rest api’s much easier and easier to read. See the examples page for more info but here is a short one.

Prerequisites for examples

  • setup a cloudflare api token
  • install jq brew install jq if your on osx.
1
2
3
4
curl https://www.cloudflare.com/api_json.html \
-d 'a=zone_load_multi' \
-d 'tkn=xxxxxxxxxxxxxxx' \
-d [email protected]' |jq '.response.zones.count'

This example queries the cloudflare api and returns just the count of zones in your account. Its possible the api has been updated with more features but these queries still work as of when I published this. YMMV

The following example returns the list of domains currently in your account.

1
2
3
4
curl https://www.cloudflare.com/api_json.html \
-d 'a=zone_load_multi' \
-d 'tkn=xxxxxxxxxxxxxxx' \
-d [email protected]' | jq '.response.zones.objs[].zone_name'

Normally the output is to much to deal with visually but jq makes it very easy to traverse the json heirarchy.


Comments: