KQL plugin: How to query for a structure field

Hi there!

I was super happy to see that the KQL plugin recently came to a first release!

I followed the documentation but got stuck with writing a query for a structure field. It basically works because I get a response, however, it’s very cryptic and not really usable for templating.

// my query, params.slug = id of the wanted children of /projects (subpage)

const response = await $axios.post(process.env.APIURL + 'api/query', {
   query: "page('projects/" + params.slug + "')",
   select: {
      title: true,
      id: true,
      mediaStructure: {
        query: 'page.mediaStructure'
      },
   }
}, { auth })
// the reponse
entries:  {
  title: '0/1 Black/White On/Off Dead/Alive',
  id: 'projects/0-1-black-white-on-off-dead-alive',
  mediaStructure: '<ul>\n' +
    '<li>mediaimage:<ul>\n' +
    '<li>00001111.png<br />\n' +
    'video: [ ]<br />\n' +
    'iframe: ""<br />\n' +
    'iframecaption: ""<br />\n' +
    "fullscreen: 'false'</li>\n" +
    '</ul>\n' +
    '</li>\n' +
    '<li>\n' +
    '<p>mediaimage:</p>\n' +
    '<ul>\n' +
    '<li>01101001.png<br />\n' +
    'video: [ ]<br />\n' +
    'iframe: ""<br />\n' +
    'iframecaption: ""<br />\n' +
    "fullscreen: 'false'</li>\n" +
    '</ul>\n' +
    '</li>\n' +
    '<li>\n' +
    '<p>mediaimage:</p>\n' +
    '<ul>\n' +
    '<li>01001011.png<br />\n' +
    'video: [ ]<br />\n' +
    'iframe: ""<br />\n' +
    'iframecaption: ""<br />\n' +
    "fullscreen: 'false'</li>\n" +
    '</ul>\n' +
    '</li>\n' +
    '</ul>'
}

For your orientation, here is the structure field from the yaml blueprint

# right side 2 column layout
visRight:
  width: 1/2
  sections:
    
    structure:
      type: fields
      fields:
        mediaStructure:
          label: Media Structure
          type: structure
          sortable: true
          fields:
            mediaImage:
              label: Media Image
              type: files
              sortable: true
              uploads:
                template: mediaImage
            video:
              label: Video
              type: files
              sortable: true
              uploads:
                template: mediaVideo
            iframe:
              label: iFrame
              type: text
            iframeCaption:
              label: iFrame Caption
              type: text
            fullscreen:
              label: Fullscreen?
              type: toggle
              text: 
                - "no"
                - "yes"

Any help is really appreciated! Thank you!

Cheers,
Max

This Github Issue helped me to solve the problem. I was missing the toStructure method.

const response = await $axios.post(process.env.APIURL + 'api/query', {
   query: "page('projects/" + params.slug + "')",
   select: {
      title: true,
      id: true,
      mediaStructure: {
        query: 'page.mediaStructure.toStructure'
      },
   }
}, { auth })

I have the problem that within a structure field I have a textarea field on which I’d like to call the kirbytext() method. So far I didn’t find a way to do this. Is this possible?