cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Go to solution
Highlighted

Updating DNS Records via GoDaddy API

Trying to update my Dynamic IP address via GoDaddy's API and found a good script written by @sanctus and @mfox. It was giving me errors when trying to update the record, not sure if the API changed since they posted the script, back in early 2017, but it was throwing errors on the call.  So some research and found that it was an API change, I made some changes and now works like a champ.  Hope it saves someone some time.

 

#!/bin/bash

# This script is used to check and update your GoDaddy DNS server to the IP address of your current internet connection.
# Special thanks to mfox for his ps script
# https://github.com/markafox/GoDaddy_Powershell_DDNS
#
# First go to GoDaddy developer site to create a developer account and get your key and secret
#
# https://developer.godaddy.com/getstarted
# Be aware that there are 2 types of key and secret - one for the test server and one for the production server
# Get a key and secret for the production server
#
#Enter vaules for all variables, Latest API call requries them.

domain="mydomain.com"                       # your domain
type="A"                                    # Record type A, CNAME, MX, etc.
name="sip"                                  # name of record to update
ttl="3600"                                  # Time to Live min value 600
port="1"                                    # Required port, Min value 1
weight="1"                                  # Required weight, Min value 1
key="asdfcasdfasdcSDasd23423sdf"            # key for godaddy developer API
secret="ASDsadsdfoasdke32309sdasdf"         # secret for godaddy developer API

headers="Authorization: sso-key $key:$secret"

 echo $headers

result=$(curl -s -X GET -H "$headers" \
 "https://api.godaddy.com/v1/domains/$domain/records/$type/$name")

dnsIp=$(echo $result | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")
 echo "dnsIp:" $dnsIp

# Get public ip address there are several websites that can do this.
ret=$(curl -s GET "http://ipinfo.io/json")
#echo $ret
currentIp=$(echo $ret | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")
 echo "currentIp:" $currentIp

 if [ $dnsIp != $currentIp ];
 then
        echo "IP's are not equal, updating record"
        curl -X PUT "https://api.godaddy.com/v1/domains/$domain/records/$type/$name" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-H "$headers" \
-d "[ { \"data\": \"$currentIp\", \"port\": $port, \"priority\": 0, \"protocol\": \"string\", \"service\": \"string\", \"ttl\"$
fi
 if [ $dnsIp = $currentIp ];
 then
      echo "IP's are equal, no update required"
fi

Little cron job that runs every hour and mission accomplished.

By no means a expert as this stuff but any suggestion on ways I could have done this better are certainly welcome! 

 

Cheers all!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Manager
Community Manager
Solution

Re: Updating DNS Records via GoDaddy API

Hey @TheBelcherman. Thanks for being part of GoDaddy Community and for posting this solution. I'm sure someone will find it helpful! I'll mark this response as the solution so it can be prioritized in search results. 

 

JesseW - GoDaddy | Community Manager | 24/7 support available at x.co/247support | Remember to choose a solution and give kudos.

View solution in original post

11 REPLIES 11
Highlighted
Community Manager
Community Manager
Solution

Re: Updating DNS Records via GoDaddy API

Hey @TheBelcherman. Thanks for being part of GoDaddy Community and for posting this solution. I'm sure someone will find it helpful! I'll mark this response as the solution so it can be prioritized in search results. 

 

JesseW - GoDaddy | Community Manager | 24/7 support available at x.co/247support | Remember to choose a solution and give kudos.

View solution in original post

Highlighted

Re: Updating DNS Records via GoDaddy API

Thank you so much for this post!  It's very comprehensible and works very well!

 

When little problem, though.  In your code, it looks like part of a line was cut off.  The line:

 

-d "[ { \"data\": \"$currentIp\", \"port\": $port, \"priority\": 0, \"protocol\": \"string\", \"service\": \"string\", \"ttl\"$

Should actually be:

d "[ { \"data\": \"$currentIp\", \"port\": $port, \"priority\": 0, \"protocol\": \"string\", \"service\": \"string\", \"ttl\": $ttl, \"weight\": $weight } ]"  

Otherwise it will throw an error if you try to run it (specifically for unmatched quotes, but the API call might fail without those parameters).  Otherwise it works like a charm!

Highlighted

Re: Updating DNS Records via GoDaddy API

Thanks for this!

I've tuned up this code and added it on GitHub at:

 

https://github.com/UnklAdM/update-godaddy-dns

 

Adam.

Adam Wheeler
A.K.A. "UnklAdM"
Highlighted

Re: Updating DNS Records via GoDaddy API

Good man!

Highlighted

Re: Updating DNS Records via GoDaddy API

Hi ,

What about if I want to update the @ in name field? I mean the main domain? it's generated an error like this :

Unrecognized token in source text.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnrecognizedToken
but when I write any name it's work like a charm!
Any advice?

Highlighted

Re: Updating DNS Records via GoDaddy API

Thanks for the support (the subject itself of course), I found the solution my self.
I would like to share the knowledge If someone interested to update the main domain @ just adds : after the name variable. 
Regard's

Highlighted

Re: Updating DNS Records via GoDaddy API

Works for me with @ but I can't seem to update my * A record?

Highlighted

Re: Updating DNS Records via GoDaddy API

i got ./godaddy_api.sh: line 51: unexpected EOF while looking for matching `''
./godaddy_api.sh: line 53: syntax error: unexpected end of file

Highlighted

Re: Updating DNS Records via GoDaddy API

https://www.godaddy.com/community/Managing-Domains/Updating-DNS-Records-via-GoDaddy-API/m-p/125997/h...

 

The line:

 

-d "[ { \"data\": \"$currentIp\", \"port\": $port, \"priority\": 0, \"protocol\": \"string\", \"service\": \"string\", \"ttl\"$

Should actually be:

d "[ { \"data\": \"$currentIp\", \"port\": $port, \"priority\": 0, \"protocol\": \"string\", \"service\": \"string\", \"ttl\": $ttl, \"weight\": $weight } ]"  

Otherwise it will throw an error if you try to run it (specifically for unmatched quotes, but the API call might fail without those parameters).




Highlighted

Re: Updating DNS Records via GoDaddy API

I’m a hardware EE, what you guys can pull off is mind blowing!  Coding truly is king!

 

Cheers everyone!

Highlighted
New

Re: Updating DNS Records via GoDaddy API

This is incredible for DNS failover. I am going to look into someone modifying the script so that I will ping the IP and if the IP stops responding the the DNS will be changed to a failover IP

 

Free DNS failover.  Would be great to have this interface with a web interface so I could add as many records as I wanted for DNS failover.