Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't add record #4

Open
bighippo999 opened this issue Jul 9, 2017 · 1 comment
Open

Doesn't add record #4

bighippo999 opened this issue Jul 9, 2017 · 1 comment

Comments

@bighippo999
Copy link

Hi, great script thanks for writing it.
I need to automatically add dns records for new servers, but I was getting update failed error when running. Looking through the code and Cloudflares API guide it looks like the script can only update an existing record (it uses PUT), I added an if check to see if it's adding/updating then use either POST or PUT depending on the action.

I genuinely dont understand GIT to submit my changes back :) so I'll just put it below:

# Perform record update
api_dns_update=`${curl_command} -s -X PUT "${cf_api_url}/zones/${zone_id}/dns_records/${record_id}" -H "X-Auth-Email: ${cf_email}" -H "X-Auth-Key: ${cf_api_key}" -H "Content-Type: application/json" --data "{\"id\":\"${zone_id}\",\"type\":\"A\",\"name\":\"${record_name}\",\"content\":\"${WAN_addr}\"}"`

Changed to:

# Perform record update
 if [ -z $record_id ]; then
     api_dns_update=`${curl_command} -s -X POST "${cf_api_url}/zones/${zone_id}/dns_records" -H "X-Auth-Email: ${cf_email}" -H "X-Auth-Key: ${cf_api_key}" -H "Content-Type: application/json" --data "{\"id\":\"${zone_id}\",\"type\":\"A\",\"name\":\"${record_name}\",\"content\":\"${WAN_addr}\"}"`
 else
     api_dns_update=`${curl_command} -s -X PUT "${cf_api_url}/zones/${zone_id}/dns_records/${record_id}" -H "X-Auth-Email: ${cf_email}" -H "X-Auth-Key: ${cf_api_key}" -H "Content-Type: application/json" --data "{\"id\":\"${zone_id}\",\"type\":\"A\",\"name\":\"${record_name}\",\"content\":\"${WAN_addr}\"}"`
 fi

Thanks again for writing it, I hope this helps someone.

@shimco
Copy link

shimco commented Aug 4, 2018

This script is great, but on Mac OSX updating a record was failing with the error below, even after I manually created the record on the cloudflare site:
Record update failed. {"success":false,"errors":[{"code":7001,"message":"Method PUT not available for that URI."}],"messages":[],"result":null}

Updating this line has fixed the error and it's now working! Thanks @bighippo999 I've submitted a pull request to add this.

shimco added a commit to shimco/cf-ddns.sh that referenced this issue Aug 4, 2018
As discussed in issue gstuartj#4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants