1

I am working on a powershell script that displays all of the dns servers I manage via GoDaddy, and see which ones are about to expire. I am using the GoDaddy API and this following code:

. .\configs\example.com_update_gd_dns_cfg.ps1
Write-Output "example.com"
$headers = @{}
$headers["Authorization"] = 'sso-key ' + $key + ':' + $secret
$result = Invoke-WebRequest -Uri https://api.godaddy.com/v1/domains/example.com/records/A/@ -method get -headers $headers -Body $json
$content = ConvertFrom-Json $result.content

Write-Output $result
Write-Output "------"
Write-Output "";

with . .\configs\example.com_update_gd_dns_cfg.ps1 being;

$domain="example.com"                      # domain
$type="A"                                  # Record type A, CNAME, MX, etc.
$name="@"                                  # name of record to update. Store number.
$ttl=600                                   # Time to Live min value 600
$port=443                                  # Required port, Min value 1
$weight=1                                  # Required weight, Min value 1
$key="key"                                 # key for godaddy developer API - prod
$secret="secret"                           # secret for godaddy developer API - prod

I only want to see this response: the only values I care about are "domain", "nameServers" and "expires"

for some reason, I get this response instead of the get response for the server:


StatusCode        : 200
StatusDescription : OK
Content           : [{"data":"192.116.71.196","name":"@","ttl":600,"type":"A"}]

RawContent        : HTTP/1.1 200 OK
                    Vary: origin
                    X-Request-Id: aVPs8XeAu7YVnnVi2Asyds
                    X-DataCenter: US_EAST_1
                    Pragma: no-cache
                    Connection: keep-alive
                    Content-Length: 60
                    Cache-Control: max-age=0, no-cache, no-store...
Forms             : {}
Headers           : {[Vary, origin], [X-Request-Id, aVPs8XeAu7YVnnVi2Asyds], [X-DataCenter, US_EAST_1], [Pragma, no-cache]...}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        : System.__ComObject
RawContentLength  : 60

I can't seem to get the response I seek, what is wrong with my code?

I tried this code;

. .\configs\example_update_gd_dns_cfg.ps1
$headers = @{}
$headers["Authorization"] = 'sso-key ' + $key + ':' + $secret
$result = Invoke-WebRequest -Uri 'https://api.godaddy.com/v1/domains/example.com/records/' -Method Get -Headers $headers 

$content = $result.Content | ConvertFrom-Json
$domain = $content[0].data
Write-Output "Name: $name"
Write-Output "Domain: $domain"
Write-Output "Status: $status"
Write-Output "Expires at: $expires"
PowerShell -NoExit

and I get the following response;

Name: @
Domain: (example domain)
Status:
Expires at:

Why won't it print the rest of the request's values?

1
  • 1
    You might add $headers["Accept"]='application/json'. Also, you're missing assignments to $status and $expires (or haven't included all the relevant code).
    – harrymc
    Commented Jun 18, 2023 at 13:16

0

You must log in to answer this question.

Browse other questions tagged .