XCP-ng
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    filter for custom field

    Scheduled Pinned Locked Moved REST API
    3 Posts 2 Posters 34 Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R Offline
      randyrue
      last edited by

      I'm trying to get a list of VMs that have a "true" value for a custom field. The doc at https://docs.xen-orchestra.com/restapi even describes an example as "With custom fields:" but the example following (and all the other examples) make no mention of filters.

      The custom field is called "export_vga" and I can see it if I query fields=* under "other" but can't filter on it using its short name, nor for XenCenter.CustomFields.export_vga or other.XenCenter.CustomFields.export_vga or other:XenCenter.CustomFields.export_vga (I'm pretty much trying to find a working curl command by trial and error at this point).

      This returns every VM and every field:

      curl -k -b authenticationToken=$tk "https://xoa.pc.scharp.org/rest/v0/vms?fields=*" | less
      

      including the lines:

      "other": {
            "XenCenter.CustomFields.export_vga": "true",
      

      I can filter on other fields:

      curl -k -b authenticationToken=$tk "https://xoa.pc.scharp.org/rest/v0/vms?filter=name_label:xoa&fields=name_label" 
      [
        {
          "name_label": "xoa",
          "href": "/rest/v0/vms/73018610-8d50-4685-5617-f15e0d09fa5"
        }
      ]
      

      grateful for any guidance

      1 Reply Last reply Reply Quote 0
      • DanpD Offline
        Danp Pro Support Team
        last edited by

        This filter works in XOA --

        other:XenCenter.CustomFields.export_vga:"true"

        You can try this with curl --

        curl -k -b authenticationToken=$tk "https://xoa.pc.scharp.org/rest/v0/vms?fields=name_label%2Cpower_state%2Cuuid&filter=other%3AXenCenter.CustomFields.export_vga%3A%22true%22"

        R 1 Reply Last reply Reply Quote 1
        • R Offline
          randyrue @Danp
          last edited by

          @Danp said in filter for custom field:

          other:XenCenter.CustomFields.export_vga:"true"

          I think I had something either very close to that or even exactly that except I didn't quote "true." Which makes sense as "true" is just a string, not a bool.

          This works:

          curl -k -b authenticationToken=$tk "https://xoa.pc.scharp.org/rest/v0/vms?filter=other:XenCenter.CustomFields.export_vga:"true"&fields=name_label"
          

          Thank you!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post