FROM CACHE - en_header

New File API - get particular asset by exact name

TwoColors
Shopify Partner
73 0 20

I am playing around with new File API, and I would like to be able to get file by filename that is exactly as specified. Instead API is pulling also other assets that contains the key in their names, e.g. boardteam-1, boardteamblabla, etc.

in documentation says that about equality symbol ":"    * equality depends on how a field is indexed. For numeric fields : represents equality. For tokenized fields, equality exists if the term is found anywhere in the field. For non-tokenized fields, the search query string must match the searched field exactly.

It seems that filename is a tokenized field then. Is there a way to get exact file by name?

My dummy query below:

 

 

{
  files(first: 10, query: "filename:boardteam") {
    edges {
      node {
        ... on MediaImage {
          image {
            src
          }
        }
        ... on GenericFile {
          url
        }
      }
    }
  }

 

 

Maciej Tokarczyk
Replies 2 (2)
Michal17
Shopify Partner
835 73 158

Hi @TwoColors 

Hope you're having a great day!

Did you try with the phrase query?

{
  files(first: 10, query: "filename:'boardteam'") {
    edges {
      node {
        ... on MediaImage {
          image {
            src
          }
        }
        ... on GenericFile {
          url
        }
      }
    }
  }
TwoColors
Shopify Partner
73 0 20

Yes I did, but that's the problem with it. It then finds all assets that contains "boardteam" anywhere in the filename. So potentially can return more assets than you want. Even more, the default sorting starts from longest file name, so you need to reverse results to get exact file on first place

Maciej Tokarczyk