You are trying to search on a reference to an unsupported type. You can only search on references to single entries

Hi, I’m facing a problem.

I have two content types: page and header. The page, except some common fields has the components field which is an array displayed as Entry links list. That components array is the reference “container” for header and some other content types.

What I’m trying to do is call Contentful for only those page type components which has header linked in components field. Considering that not all of already defined page components on my space has linked header I need to somehow determine those which has it linked. Here is an example structure:

{
  sys: {
    id: 'page-entry-id',
    type: 'Entry',
    contentType: {
      sys: { type: 'Link', linkType: 'ContentType', id: 'page' }
    }
  },
  fields: {
    name: 'hello world page',
    ... (some other fields)
    components: [
      {
        sys: {
          id: 'header-entry-id',
          type: 'Entry',
          contentType: {
            sys: { type: 'Link', linkType: 'ContentType', id: 'header' }
          }
        },
        fields: {
          name: 'hellow world header'
          ... (some other fields)
        }
      }
    ]
  }
}

What I already made is this query:

const { data } = await client.getEntries({
  content_type: 'page',
  'fields.components.sys.contentType.sys.id': 'header',
  order: '-sys.updatedAt',
  limit: 4,
  skip: 0
})

But at the end I’m receiving this error: You are trying to search on a reference to an unsupported type. You can only search on references to single entries.

This is how components field looks like in Contentful:

Right now I’m requesting for all page components, no matter if they contain header or not, and then I filter them by getting only those with header linked. But it’s done on node backend and it’s too late for me because I’m working on pagination feature and I need exactly 4 pages with headers linked. When some of the page components doesn’t have header, I still got them in the response (without this in query ofc ‘fields.components.sys.contentType.sys.id’: ‘header’,) and after filtering only those with header linked, so at the end, instead of 4 results per page I have for instance 3 or 2 and all pagination is broken.

Any advice how to make a working query is welcomed.