New on LowEndTalk? Please Register and read our Community Rules.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
Cloudflare api - Identify and remove a record
For a project I need to remove a a record from a CF account. When I started I didn't think this would be hard. But now I reached that part and I'm stuck. I'm writing a bash script and I only have that ip and/or a record name. However according to the CF I need to know the record id.
http://snapr.pw/i/95be42bf75701e07e980dd6899ed56.png
And to get the record id I need to call rec_load_all. This will return all the records for that given domain. Now the problem is, how am I going to identify the right record id from the response from Cloudflare in bash?
Cloudflare api documentation: https://www.cloudflare.com/docs/client-api.html


Comments
Traverse, match the same fqdn or IP, then grab the record_id. I'd recommend PHP and execute via the command line. It will provide more functionality and you would exec just like bash anyway
Here's a snippet of code I have, though it might have an issue with www.something.com vs something.com. I can't remember if I fixed it or not. It's something to start off, I guess.
$tkn is your cloudflare API token
$email is your cloudflare email address
function rec_load_all() { curl https://www.cloudflare.com/api_json.html \ -d 'a=rec_load_all' \ -d "tkn=$tkn" \ -d "email=$email" \ -d "z=$1" -s | python -mjson.tool > results.txt } #$1 = searching for that zone's dns ID function getDNSID() { dnsLineNum=`grep -E "$1" -n results.txt | head -n 1 | cut -d ":" -f1`; echo "dns line #:$dnsLineNum"; dnsIDLineNum=`echo "$dnsLineNum + 13" | bc -q`; echo "dns id line #: $dnsIDLineNum"; DNSID=`sed -n "$dnsIDLineNum p" results.txt | cut -d ":" -f2 | sed "s/\"//g;s/ //;s/\,//";` }