0

I am trying to POST a data to receive an input using powershell but it's throwing error. Url: https://www.example.com/api/login

JSON data = {"username": "emailid", "password": "password"}

Once the post is successful, i will receive an output in JSON format something like:

{"account": "some-guid", "Token": "xxx", "selflink": "https://www.example.com/api/me", "username": "emailid"}

When I am posting the JSON data, I'm getting syntax error.

I'm using the below code to invoke

$url = "https://somedomain.com/api/login"

$params = @{"username"="abcd@pqr.com";
        "password"="123456";
}

$response = Invoke-WebRequest -Uri $url -Method POST -Body $params -ContentType "application/json"
Developer
  • 759
  • 2
  • 9
  • 24

1 Answers1

0

I changed the $param to | ConvertTo-Json

$JSON = @{
"username" = "abcd@xyz.com"
"password" = "123456"
} | ConvertTo-Json

and it worked fine.

Developer
  • 759
  • 2
  • 9
  • 24
  • http://stackoverflow.com/questions/35722865/how-to-make-a-post-request-using-powershell-if-body-have-a-parameter-type – Developer Mar 24 '17 at 13:42