I am creating PowerShell script for API on Firepower 1120 (NO FCM, just a standalone chassis managed with FDM).
I have tested the API itself using the FDM "API Explorer" as follows (obviously account names and passwords are not real):
{
"grant_type": "password",
"username": "myradiusaccount",
"password": "myradiuspassword"
}
When pasting this into the API explorer in FDM, I get the expected result. I get a formatted curl result, the correct 200 response and it provides me with the token I use for future requests.
I'm trying to do the exact same thing, but from Powershell. This is what my script looks like:
$param = '{"grant_type":"password","username":"myradiusaccount",password":"myradiuspassword"}'
$json = $param | ConvertTo-Json
Invoke-RestMethod 'https://x.x.x.x/api/fdm/v5/fdm/token' -Method Post -Body $json -ContentType 'application/json'
However, the result I'm getting - which I'm almost positive is from the firewall API, not from PowerShell - is this:
Invoke-RestMethod : HTTP Status 500 – Internal Server ErrorH1
{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2
{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3
{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY
{font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B
{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P
{font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color :
black;}.line {height: 1px; background-color: #525D76; border: none;}HTTP Status 500 – Internal Server Error
At line:1 char:1
+ Invoke-RestMethod 'https://x.x.x.x/api/fdm/v5/fdm/token' -Method P ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebE
xception
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
These are the stored values of the variable I've built just before it executes the Invoke-RestMethod:
json$ (the body of the post) is:
"{\"grant_type\":\"password\",\"username\":\"myradiususername\",password\":\"myradiuspassword\"}"
Is anyone able to shed any light on why I'm getting a HTTP 500 from the firewall?
Oh, and below is the "cleaned up" status message I'm receiving:
Exception details:
Message: The remote server returned an error: (500) Internal Server Error.
Status code: InternalServerError
Status description: Internal Server Error
Response: