使用 Powershell 更新 GoDaddy API 上的 DNS 记录时出现错误 422 [英] Error 422 When Using Powershell to Update DNS Records on GoDaddy API

查看:86
本文介绍了使用 Powershell 更新 GoDaddy API 上的 DNS 记录时出现错误 422的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 GoDaddy 的 API 更新我的 DNS(我的家庭网络使用动态 IP).

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

使用位于 http://teanazar 的脚本时,我能够成功更新.com/2016/05/godaddy-ddns-updater/ 当通过 cygwin 运行时.

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

但是我正在尝试简化事情,而是在 powershell 中执行此操作.

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

到目前为止,我已经设法解决了每个问题,并且我知道它正在验证.但是当我执行时,我收到远程服务器返回错误:(422) 不可处理实体

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

推荐答案

我一直在使用基于 drizin 提供的解决方案的实现......直到最近它运行良好.

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

GoDaddy 似乎加强了 JSON 验证,但现在失败并显示以下错误:

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`"
}

根据 https://developer 上的 API 规范.Godaddy.com/doc/endpoint/domains#/v1/recordReplaceTypeName 发送的 JSON 应该是一个数组...即 [ { ... } ] 代码在其中创建 { ... }.

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 { ... }.

要解决此问题,需要对构建 JSON 的代码行进行简单更改...

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

来自:

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

致:

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

这篇关于使用 Powershell 更新 GoDaddy API 上的 DNS 记录时出现错误 422的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆