Manage DNS Records in DNSMadeEasy with REST API

Steps to manage dns records in DNSMadeEasy with REST API

Authentication Header

The following Request Headers are required by refering to the API Document

  • x-dnsme-apiKey – The API Key for your account
  • x-dnsme-requestDate – Standard HTTP-formatted date. This date is used to protect against falsified requests played back at a future time.
  • x-dnsme-hmac – HMAC hash of value of the x-dnsme-requestDate field

Login to to get the API Key

Prepare a PowerShell Function to generate the Authentication Header

function Get-DnsMadeEasyHeader {
    #Replace the APIKey & SecretKey with the Value from your account
	$Date = ([DateTime](Get-Date).ToUniversalTime()).ToString("ddd, dd MMM yyyy HH:mm:ss 'GMT'")

	$HMACSHA1 = New-Object System.Security.Cryptography.HMACSHA1
	$HMACSHA1.Key = [System.Text.Encoding]::ASCII.GetBytes($secretKey)
	$HMACHash = ([System.BitConverter]::ToString($HMACSHA1.ComputeHash([Text.Encoding]::ASCII.GetBytes($Date))) -Replace "-", "").ToLower()

	$Headers = @{ 'x-dnsme-apiKey' = $APIKey
	              'x-dnsme-requestDate' = $Date
	              'x-dnsme-hmac' = $HMACHash
                  'ContentType' = "application/json"}

	Return $Headers

List All Domains Registered

List all domains registered in our DnsMadeEasy Account

#Get All Domain Registered
$URI = ""

$Response = Invoke-RestMethod -Uri $URI -Headers (Get-DnsMadeEasyHeader)-Method Get 
$ | Select Name, ID


name                   id
----                   --    xxxxxxx   xxxxxxx   xxxxxxx xxxxxxx        xxxxxxx

List All Records for Particular Domain

List all records, like A, MX, TXT and others for a particular domain, like

#List Records for 1 Domain
$DomainName = ""
$DomainID = ($ | ? Name -like $DomainNAme).id 

$DNS_Records = Invoke-RestMethod -Uri$DomainID/records -Headers (Get-DnsMadeEasyHeader) -Method Get
#Output of All Records 
$ | Select ID,Name, Type, Value


       id name  type value         
       -- ----  ---- -----         
111555619       MX   mail          
107390283       A
111643122       TXT  "1234"        
111555587 mail  A 
107870636 my    A 
108219864 uat   A 
108854884 unifi A 

Create a New Record

Create a new TXT record with value = "1234567890" in

#Create a New Record
$DomainName = ""
$DomainID = ($ | ? Name -like $DomainNAme).id 

#Data Declare here need to be converted to json format later
$Body = @{
    name = ""
    type = "TXT"
    value = "1234567890"
    id = $ID
    gtdLocation = 'DEFAULT'
    ttl = 86400

Invoke-RestMethod -Uri$DomainID/records -Headers (Get-DnsMadeEasyHeader) -Body ($Body | ConvertTo-Json) -Method Post 

#Verify the DNS record is created successfully
$DNS_Records = (Invoke-RestMethod -Uri$DomainID/records -Headers (Get-DnsMadeEasyHeader) -Method Get).Data
$DNS_Records | ? Type -Like "TXT" | Select Name, Type, Value


name type value 
---- ---- ----- 
     TXT  "1234"

Update DNS Record

Update TXT record with new value

$DNS_Records = (Invoke-RestMethod -Uri$DomainID/records -Headers (Get-DnsMadeEasyHeader) -Method Get).Data
#Search for the DNS record need to be updated
$ID = ($DNS_Records | Where-Object {($_.type -eq "TXT")}).ID

$New_Value = "12345"

$Body = @{

    name = ""
    type = "TXT"
    value = $New_Value
    id = $ID
    gtdLocation = 'DEFAULT'
    ttl = 86400

#Update DNS Record
Invoke-RestMethod -Uri$DomainID/records/$ID -Headers (Get-DnsMadeEasyHeader) -Body ($Body | ConvertTo-Json) -Method Put

#Verify TXT record is updated
$DNS_Records = (Invoke-RestMethod -Uri$DomainID/records -Headers (Get-DnsMadeEasyHeader) -Method Get).Data
$DNS_Records | Where-Object {($_.type -eq "TXT")}


name type value  
---- ---- -----  
     TXT  "12345"

Delete DNS Record

Delete the TXT record

$DNS_Records = (Invoke-RestMethod -Uri$DomainID/records -Headers (Get-DnsMadeEasyHeader) -Method Get).Data
#Search for the DNS record need to be deleted 
$ID = ($DNS_Records | Where-Object {($_.type -eq "TXT") -and ($_.value -cmatch "1234")}).ID

#Delete the DNS record
Invoke-RestMethod -Uri$DomainID/records/$ID -Headers (Get-DnsMadeEasyHeader) -Method Delete

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top