Query content, include only certain fields - Error in documentation?

Builder public api key

What are you trying to accomplish

I want to fetch all content belonging to a model, but only return two fields: name and data.category

It seems like there must be no white space between different fields, otherwise the result will only return the first field.

Screenshots or video link
Screenshots of your issue, or even better a link to a video of what is happening or what you are trying to accomplish. We love using loom for that sort of thing

Code stack you are integrating Builder with

Reproducible code example
If you are having integration errors, please link to codesandbox or copy and paste your problematic code here. The more detail the better!

The first one has space between name and data.category, as I followed the docs.

const posts = await builder.getAll('pattern', {
  fields: 'name, data.category',

Delete the space between name and data.category:

const posts = await builder.getAll('pattern', {
  fields: 'name,data.category',

Hi @bytrangle, Thank you for bringing this up. I’ll pass it along to the team!

I just spent way too long trying to figure out why my queries weren’t working until I stumbled on this post. Having spaces in the fields string was the culprit.

Definitely would be useful to add this very important gotcha to the docs.

Would also probably be more intuitive and typesafe if fields accepted an array of keys.

1 Like