I work with our public DNS records quite a bit. The most painful part of the process is navigating through the GoDaddy web portal just to update the same records on a handful of domains. I created a PowerShell module that calls the GoDaddy API to make these simple changes much less frustrating.

I started off doing some research, GoDaddy has wonderful documentation. You’ll need a key/secret pair to make calls to the API, which you can generate here. (Use a production key.)

To make an API call with PowerShell I used Invoke-WebRequest with the following parameters:

  • URI: Specifies the Uniform Resource Identifier (URI) of the Internet resource to which the web request is sent.
  • Method: Specifies the method used for the web request. (Get, Post, Put, etc)
  • Headers: Specifies the headers of the web request. Enter a hash table or dictionary.

To authenticate against the API I inserted the key/secret into the headers using a hashtable:

$apiKey = '2s7Yn1f2dW_W5KJhWbGwuLhyW4Xdvgb2c'
$apiSecret = 'oMmm2m5TwZxrYyXwXZnoN'

$Headers = @{}
$Headers["Authorization"] = 'sso-key ' + $apiKey + ':' + $apiSecret

Once I was confident that I’d be able to authenticate, I tried using the Get method to retrieve all records for my domain:

Invoke-WebRequest https://api.godaddy.com/v1/domains/clintcolding.com/records/ -Method Get -Headers $Headers

The API successfully returned the data but in JSON, which wasn’t exactly easy to read:

StatusCode        : 200
StatusDescription : OK
Content           : [{"type":"A","name":"@","data":"","ttl":600},{"type":"A","name":"@","data":"19
RawContent        : HTTP/1.1 200 OK
                    Access-Control-Allow-Credentials: true
                    Vary: Origin,Accept-Encoding
                    x-newrelic-app-data: PxQPUVdRCwcTVlRXDgkOVVATGhE1AwE2QgNWEVlbQFtcCxYkSRFBBxdFXRJJJH1nH0sXUxh
Forms             : {}
Headers           : {[Access-Control-Allow-Credentials, true], [Vary, Origin,Accept-Encoding],
                    [x-newrelic-app-data, PxQPUVdRCwcTVlRXDgkOVVATGhE1AwE2QgNWEVlbQFtcCxYkSRFBBxdFXRJJJH1nH0sXUx
                    5UVQRbDAIAXQRVBgMPREhXV18RAz4=], [Access-Control-Allow-Origin, *]...}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        : mshtml.HTMLDocumentClass
RawContentLength  : 696

I reran the command, this time, piping the output to ConvertFrom-Json:

Invoke-WebRequest https://api.godaddy.com/v1/domains/clintcolding.com/records/ -Method Get -Headers $Headers | ConvertFrom-Json
type  name           data                                 ttl
----  ----           ----                                 ---
A     @                           600
A     @                           600
CNAME email          email.secureserver.net              3600
CNAME ftp            @                                   3600
CNAME www            @                                   3600
CNAME _domainconnect _domainconnect.gd.domaincontrol.com 3600
MX    @              mailstore1.secureserver.net         3600
MX    @              smtp.secureserver.net               3600
NS    @              ns53.domaincontrol.com              3600
NS    @              ns54.domaincontrol.com              3600

Which makes it much easier to read. This was my first time calling API’s using PowerShell. If you would have done it differently or have any tips, I’d love some constructive criticism.

This is just a glimpse of what you can do with GoDaddy API’s. You can view all available API’s in the documentation.