Solved

How to use filterCriteria in v2?

  • 18 April 2018
  • API
  • 1 reply
  • 234 views

Hi,

I'm pretty new to APIs as a whole so I apologize in advance if this seems like a simple question. I've been using the API Explorer to get a feel as to what I could do with Nutanix's REST API. I have been trying to make it so I could query the API for virtual disks, filtered by VM Name, to be able to know at a glance what the stats for this virtual disk are.

Now I see in API Explorer that there seems to be a filter_criteria field which would start me off the right way, but I can't get it to work, nor can I find information on V2 (most posts I see are a few years old and referencing v1?) on what the syntax in that field should be. Whatever I try always returns "Invalid filter criteria specified". I have tried every variations I could think of of "attached_vmname" as this is one of the fields that came up in the results when I queried for all virtual disks from the Explorer.

What would be the correct syntax for me to filter the output?
icon

Best answer by rhunt 20 April 2018, 21:15

The correct syntax should be:
As an encoded URL (do not include the {}:

code:
/services/rest/v2.0/virtual_disks/?filter_criteria=attached_vmname%3D%3D{VMNAME}




Which would be:
code:
/services/rest/v2.0/virtual_disks/$filter_criteria=attached_vmname==VMNAME




So in the REST Explorer you should use attached_vmname==vmname, however it still will not work. There appears to be an issue with the way that the endpoint is interpreting the filter criteria option.

Any other variation will throw the invalid syntax command.

In all honestly it looks like the filter_criteria just doesn't work at all for anyting at the Prism Element layer. It Central it appears to work without issue.

The Search Criteria does however. You may have to just pull everything down in an object and filter outside of the API call. That was ultimately what I ended up doing.

View original

1 reply

The correct syntax should be:
As an encoded URL (do not include the {}:
code:
/services/rest/v2.0/virtual_disks/?filter_criteria=attached_vmname%3D%3D{VMNAME}




Which would be:
code:
/services/rest/v2.0/virtual_disks/$filter_criteria=attached_vmname==VMNAME




So in the REST Explorer you should use attached_vmname==vmname, however it still will not work. There appears to be an issue with the way that the endpoint is interpreting the filter criteria option.

Any other variation will throw the invalid syntax command.

In all honestly it looks like the filter_criteria just doesn't work at all for anyting at the Prism Element layer. It Central it appears to work without issue.

The Search Criteria does however. You may have to just pull everything down in an object and filter outside of the API call. That was ultimately what I ended up doing.

Reply