Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error 422 When Using Powershell to Update DNS Records on GoDaddy API

I am trying to update my DNS with GoDaddy via their API (My home network is on a Dynamic IP).

I am able to succesfully update when using the script found at http://teanazar.com/2016/05/godaddy-ddns-updater/ when run through cygwin.

However I am trying to simply things, and do this in powershell instead.

However when trying to use the following script:

$IP = Invoke-WebRequest http://api.ipify.org?format=json
$IP2 = ConvertFrom-JSON $ip
$domain = 'example.com'
$type = 'A'
$name = '@'

$key = 'key'
$secret = 'secret'


$Request = @{ttl='600';data=$ip2.ip;priority='1'}

$JSON = Convertto-Json $request

$headers = @{}
$headers["Authorization"] = 'sso-key ' + $key + ':' + $secret

Invoke-WebRequest    https://api.godaddy.com/v1/domains/$domain/records/$Type/$Name -contenttype "application/json" -method put -body $json -headers $headers

I have managed to work through each issue so far, and I know it is authenticating. But when I execute, i am getting "The Remote Server returned an error: (422) Unprocessable Entity

like image 870
Brett M Avatar asked Oct 28 '25 08:10

Brett M


1 Answers

I'd been using an implementation based on the solution provided by drizin... and it worked very well up until recently.

It seems that GoDaddy have tightened up on the JSON validation and it now fails with the following error:

{
  "code": "INVALID_BODY",
  "fields": [
    {
      "code": "UNEXPECTED_TYPE",
      "message": "is not a array",
      "path": "records"
    }
  ],
  "message": "Request body doesn't fulfill schema, see details in `fields`"
}

According to the specification for the APIs at https://developer.godaddy.com/doc/endpoint/domains#/v1/recordReplaceTypeName the JSON sent should be an array... i.e. [ { ... } ] where the code creates { ... }.

To fix this it requires a simple change to the line of code that build the JSON...

From:

$JSON = ConvertTo-Json @{data=$IP;ttl=3600}

To:

$JSON = ConvertTo-Json @(@{data=$IP;ttl=3600})
like image 100
Robert Pilcher Avatar answered Oct 31 '25 08:10

Robert Pilcher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!