DopeLabs
CDCloudflare Developers
•Created by DopeLabs on 10/12/2023 in #general-help
Why is the cloudflare API such a dumpster fire of inconsistency?
I wanted to create a script that will walk the entire API and hit every 'GET' method endpoint as a means of creating a complete snapshot of an entire account. there are many "backup" scripts out there, but all are limited in scope, and dont support grabbing "everything". ideally i would have done this programmatically by using the schema file (obtained from webui or github), but that doesnt even validate with openapi standards.
spending some time on the API documentation site i soon realized that im going to literally have to build this script in the most manual process, by looking at each and every GET endpoint, then trying to make sense of what values ill need to populate into the url.
identifiers. terribly inconsistent.
/zones/{identifier}
/zones/{zone_identifier}
/zones/{zone_id}
/zones/{zoneId}
/zones/{zone}
all of those refer to the same value.
/accounts/{account_identifier}
/accounts/{account_id}
/accounts/{identifier}
/accounts/{account}
/accounts/{accountId}
honestly this is piss poor.
some endpoints refer to {identifier} and the actual value name is 'tag'.
heres a hint:
use the parent name in the path in its singular form, and then use the actual name if you need to reference it.
a perfect example of this is:
/zones/{zone_id}/rulesets/{ruleset_id}
if the value name in a ruleset thats used as its 'identifier' named 'tag', then ffs use:
/zones/{zone_id}/rulesets/{ruleset_tag}
referring to it as simply {identifier} when the actual value name seems to be anything, helps no one.
this way even if your schema file doesnt validate, like it doesnt at the time of me writing this, i could at least count on knowing what value i need to get from each item returned when i get the parent endpoint just by using the name after the underscore. but instead you force me to have to click around on the api doc site to try and track down every value.
oh, and there are some references to 'identifiers' that dont even exist in said item... so thanks for that :/
21 replies