Using Powershell to Update DNS Records on GoDaddy API


I was recently working on using the GoDaddy API in lieu of using dynamicDNS to keep my lab IP up to date.  I stumbled across a post on Stack Overflow where someone had already started some work on this, but had not quite got it working.

I was able to take what they had provided, make a couple of changes, and get it working.  It might help you out to!

http://stackoverflow.com/questions/39123202/error-422-when-using-powershell-to-update-dns-records-on-godaddy-api

Enjoy!

 

 

Comments (4)

  1. Jay says:

    please share your changes. I found the same post but haven’t figured it out.

  2. Jay says:

    What did you do to figure it out? I still get the 422…

    1. PFE Kevin says:

      Looks like they stopped accepting the TTL value (at least for me) in the $Request. I am posting an update now.

      Thanks!

  3. Brandon Cannon says:

    I struggles with this for a minute also. I was able to get it to work with the following

    $apiKey = ‘YOUR API KEY’
    $apiSecret = ‘YOUR API SECRET’
    $domain = ‘YOUR DOMAIN NAME’
    #ENTER THE NAME OF THE RECORD YOU WISH TO UPDATE#
    $name = ‘@’
    $Headers = @{}
    $Headers[“Authorization”] = ‘sso-key ‘ + $apiKey + ‘:’ + $apiSecret
    $result = Invoke-WebRequest https://api.godaddy.com/v1/domains/$domain/records/A/$name -method get -headers $headers
    $content = ConvertFrom-Json $result.content
    $dnsIp = $content.data
    $currentIp = Invoke-RestMethod http://ipinfo.io/json | Select -exp ip
    #THIS SECTION CHECKS THE CURRENT IP ADDRESS AGAINST THE PULL AND WILL UPDATE IF NOT CORRECT#
    if ( $currentIp -ne $dnsIp) {
    #$Request = @{ttl=600;data=$currentIp }
    $JSON = ConvertTo-Json @(@{data=$currentIp;ttl=600})
    Invoke-WebRequest https://api.godaddy.com/v1/domains/$domain/records/A/$name -method put -headers $headers -Body $json -ContentType “application/json”

    }
    #SHOWS RESULTS OF THE HEADER PULL
    Invoke-WebRequest https://api.godaddy.com/v1/domains/$domain/records/ -Method Get -Headers $Headers | ConvertFrom-Json

Skip to main content