Getting Started with API’s in PowerShell

Clint Colding
Nov 29, 2017 · 3 min read
Image for post
Image for post

PowerShell is an impressively powerful tool and one of its most powerful features is its ability to call API’s. For those of us that have a primarily infrastructure focused background, we understand what an API is and does, but we’re a little foggy on how to use them.

The first API project I completed used the GoDaddy API. I was frustrated with the tedious process of using the GoDaddy web portal to update DNS records across our various domains. So I decided to create more efficient PowerShell commands.

I started off doing some research, thankfully GoDaddy has wonderful documentation of their API’s. I decided a logical place to start was to return all the records associated with a specific domain. Under the /v1/domains API, I found a Get request that retrieves DNS records for the specified domain:

Image for post
Image for post

The first step of making any API call is finding the API URL and what type of authentication is needed, if any. By expanding the documentation pane above, I found both.

The URL was and the authentication was in the request header:

Image for post
Image for post

Now that I knew what I needed, I could start building my PowerShell script. To make the API call 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.

First I needed to create a “Authorization” table with my key/secret pair that I could pass into the request header. You can get your API keys here. (Use a production key.)

Remember, we need to recreate the request header that we found in the documentation.

Once I was confident that I’d be able to authenticate, I ran Invoke-WebRequest using the Get method to retrieve all records for my domain. The API successfully returned the data in JSON:

To get a more legible output, I reran the command. This time, piping the output to ConvertFrom-Json.

After successfully retrieving the DNS records for my domain, I repeated the process, this time using the Put method.

In the end, this made updating DNS entries across our domains much more efficient. I also built custom DNS failover scripts for disaster recovery.

I have a GitHub project that includes the basic Get, Add, and Set commands for working with your GoDaddy DNS.

This is just a glimpse of what you can do with GoDaddy’s API. Make sure to check out the documentation, I’d love to see what you automate!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store