I can use curl to call a REST api
curl -H 'Authorization: Bearer <token>' \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-X POST \
-d '<json>' \
https://api.dnsimple.com/v2/1010/zones/example.com/records
and the json needs to be in the format of:
{
"name": "",
"type": "MX",
"content": "mxa.example.com",
}
How can I call this API using Invoke-WebRequest? I'm trying the following (of course I'm using variables here) When I call this I'm getting an error 400
$uri = [string]::Format("https://api.dnsimple.com/v2/{0}/zones/{1}/records",$account,$domain)
$headers = @{}
$headers["Authorization"] = [string]::Format("Bearer {0}", $token)
$headers["Accept"] = "application/json"
$headers["Content-Type"] = "application/json"
$json = @{}
$json["name"] = $subdomain
$json["type"] = "A"
$json["content"] = $ip
Invoke-WebRequest -Uri $uri -Body $json -Headers $headers -Method Post
-Body $json->-Body ($json |ConvertTo-Json)