14-Jun-2017
15:36
- last edited on
03-Jun-2023
10:04
by
JimmyPackets
Hi Guys,
I´m playing with some REST calls, and I would like to get a specific information from a GET request. In the example:
GET , I got the following response:
{
"kind": "tm:cm:failover-status:failover-statusstats",
"selfLink": "[https://localhost/mgmt/tm/cm/failover-status?ver=12.1.2"](https://localhost/mgmt/tm/cm/failover-status?ver=12.1.2);,
"entries": {
"[https://localhost/mgmt/tm/cm/failover-status/0"](https://localhost/mgmt/tm/cm/failover-status/0);: {
"nestedStats": {
"entries": {
"color": {
"description": "green"
},
"[https://localhost/mgmt/tm/cm/failoverStatus/0/details"](https://localhost/mgmt/tm/cm/failoverStatus/0/details);: {
"nestedStats": {
"entries": {
"[https://localhost/mgmt/tm/cm/failoverStatus/0/details/0"](https://localhost/mgmt/tm/cm/failoverStatus/0/details/0);: {
"nestedStats": {
"entries": {
"details": {
"description": "active for /Common/traffic-group-1"
}
}
}
}
}
}
},
"status": {
"description": "ACTIVE"
},
"summary": {
"description": "1/1 active"
}
}
}
}
}
}
Is it possible to use query parameters to get a specific response? In the example above, I would only like to receive the appliance status (description": "ACTIVE"). I was trying to work with $filter and $select parameter but no success.
Plus, if someone could give me one example of each parameter, it would be great.
15-Jun-2017
02:39
- last edited on
03-Jun-2023
10:04
by
JimmyPackets
you can use this uri : /mgmt/tm/cm/failover-status?$select=status
but you will still have a nested response.
{
"entries": {
"https://localhost/mgmt/tm/cm/failover-status/0": {
"nestedStats": {
"entries": {
"status": {
"description": "ACTIVE"
}
}
}
}
}
}
05-Aug-2017
01:21
- last edited on
03-Jun-2023
09:52
by
JimmyPackets
To answer your follow-up question:
This is just how the rest API works. You have to do some client side manipulation to get the actual data.
Here's an example in Powershell:
$Response = (Invoke-WebRequest -Method "GET" -Headers $headers -Uri "https://mydevice.j.local/mgmt/tm/cm/failover-status?`$select=status").content | ConvertFrom-Json
$content.entries.'https://localhost/mgmt/tm/cm/failover-status/0'.nestedStats.entries.status.description
/Patrik
02-Nov-2022 08:51
Hello Patric_Jonsson
I use your example in powershell but and error appear
I tried to fix, but there are something that is missed.
Could you re-check the code?
I think that point of view to perform the task to know if the device is active/standby is pretty cool 🙂
PS C:\Windows\system32> $Response = (Invoke-WebRequest -Method "GET" -Headers $headers -Uri "https://$f5/mgmt/tm/cm/failover-status?`$select=status").content | ConvertFrom-Json $content.entries.'https://localhost/mgmt/tm/cm/failover-status/0'.nestedStats.entries.status.description
ConvertFrom-Json : Cannot bind argument to parameter 'InputObject' because it is null.
At line:1 char:154
+ ... rtFrom-Json $content.entries.'https://localhost/mgmt/tm/cm/failover-s ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [ConvertFrom-Json], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ConvertFromJsonCommand
03-Nov-2022 02:55
finally I did !!
$response = (Invoke-WebRequest -Method "GET" -Headers $headers -Uri "https://$f5/mgmt/tm/cm/failover-status?`$select=status").content
$qestate = ($response | ConvertFrom-Json).entries.'https://localhost/mgmt/tm/cm/failover-status/0'.nestedStats.entries.status.description