api - Powershell Invoke-RestMethod -
i'm trying create powershell script access dyn's api , perform checks/updates on dns zones use/test.
i'm following api details , here's first link, https://help.dyn.com/session-log-in/
here's beginning of rest script i've put together:
$url = "https://api2.dynect.net/rest/session/" $body = @{customer_name='mahcompany';user_name='mahname';password='mahpass'} invoke-restmethod -method post -uri $url -body $body
this produces following results:
invoke-restmethod : remote server returned error: (406) not acceptable. @ line:12 char:9 + $test = invoke-restmethod -method post -uri $url -body $body + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : invalidoperation: (system.net.httpwebrequest:httpwebrequest) [invoke-> restmethod], webexception + fullyqualifiederrorid : webcmdletwebresponseexception,microsoft.powershell.commands.invokerestmethodcommand
this supposed json query according dyn information, , i've tried sevveral other examples of dyn's using curl basis:
$json = @"{"customer_name":"yourcustomer","user_name":"youruser","password":"yourpass"}'
however doesn't work either.
can point me in right direction here? can't crazy, i'm trying pass parameters rest-method query string. appreciated @ point.
-sean
content type
invoke-restmethod -method post -uri $url -body $body -contenttype 'application/json'
this might problem if dyn.com expecting proper content type.
according documentation on invoke-restmethod
:
if parameter omitted , request method post, invoke-restmethod sets content type "application/x-www-form-urlencoded". otherwise, content type not specified in call.
convertto-json
you don't have create json string manually. can create hashtable , convert it:
$data = @{ customer = 'something' name = 'whatever' } $data | convertto-json
i'm not saying making malformed json, can prevent that.
Comments
Post a Comment