cancel
Showing results for 
Search instead for 
Did you mean: 
Go to solution

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!

 

7 REPLIES 7
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.

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!

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"

Re: Updating DNS Records via GoDaddy API

Good man!

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: (Smiley Happy [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnrecognizedToken
but when I write any name it's work like a charm!
Any advice?

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

Re: Updating DNS Records via GoDaddy API

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