Page model with many content pages return empty array when I try to get contents

I created a model page and five content pages of this model and I’m trying to get these content pages in nextjs but it’s returning an empty array.

I already tried builder.get(), builder.getAll and builder.getContent and none of this is working, but when I tried with especific urlPath, it’s working for example:

builder.get(‘pible-page-article’, {
userAttributes: {
urlPath: ‘/tax-pible/develop-page-test’,
},
}).toPromise()
.then(response => {
setSearchResults(response);
console.log('foi ', response)
}).catch(error => console.log('error ', error));

}, [searchTerm]);

Do we have a way to try urlPath dinamically to return all content pages?

Hello @Luiz,

You can use builder.getAll to fetch all the pible-page-articles

Here is an example:

  const articles = await builder.getAll('pible-page-article', {
    options: { includeRefs: true },
  });

Like I said, I already tried it and it doesnt’ work, it’s returning an empty array

Hello @Luiz,

Can you share the complete code?

import React, { useState, useEffect } from ‘react’;
import { Container, Input, SearchIconSection } from ‘./styles’;
import { FontAwesomeIcon } from ‘@fortawesome/react-fontawesome’;
import { faSearch } from ‘@fortawesome/free-solid-svg-icons’;
import { builder } from ‘@builder.io/react’;
import { useRouter } from ‘next/router’;

type Props = {
placeholder: string;
};

builder.init(process.env.NEXT_PUBLIC_BUILDER_API_KEY || ‘’);

function InputSearch(props: Props) {
const router = useRouter();

const [searchTerm, setSearchTerm] = useState(‘’);
const [searchResults, setSearchResults] = useState();

useEffect(() => {
/* if (searchTerm) {
builder
.getAll(‘pible-page-article’, {
limit: 100,
query: {
data: {
$or: [
{
title: { $eq: ‘dev’ },
},
],
},
},
})
.toPromise()
.then((response) => setSearchResults(response));
} */

builder.getAll('pible-page-article', { options: { includeRefs: true } })
  .then(response => {

    console.log('foi ', response)
    setSearchResults(response);
  }).catch(error => console.log('error ', error));

}, [searchTerm]);

const handleSearch = () => {
router.push(/tax-pible/${searchTerm});
};

return (

<Input
type=“text”
placeholder={props.placeholder}
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
/>

  <SearchIconSection onClick={handleSearch}>
    <FontAwesomeIcon icon={faSearch} />
  </SearchIconSection>

  {/*  <ul>
    {searchResults.length > 0 && searchResults.map(({ data }, index) => {
      console.log('ields ', data.title)
      return (
        <li key={index}>{data.title}</li>
      )
    })}
  </ul> */}
</Container>

);
}

export default InputSearch;

Hello @Luiz,

Does removing the searchTerm dependency for useEffect helps?

Hi @manish-sharma

Actually not.

I solved the problem with “noTargeting: true” parameter in builder.getAll

builder.getAll(“my-model”, { options: { noTargeting: true }} );

2 Likes

@manish-sharma
I apologize for the emotional reaction, but I spent hours looking for this hidden noTargeting.

Why isn’t it mentioned anywhere in the docs?!
It’s extremely unobvious default behavior, especially considering that ordinary REST request with no targeting params in it returns results as expected.

Hello @Ivan.1,

I apologize for the frustration this has caused. We understand how difficult it can be to spend hours troubleshooting an issue like this, especially when the default behavior isn’t clearly documented.

You’re absolutely right—the behavior of noTargeting should be more explicit in our documentation, particularly since it’s not immediately obvious and differs from the behavior of ordinary REST requests. We will share your feedback with our team to ensure that this is addressed and properly explained in future updates to the docs.

Meanwhile, you may refer to the following forum post for help Why does builder.getAll not return all results?

We appreciate your patience and understanding, and we’re committed to improving this experience for you and others moving forward. If you have any further questions or need assistance, feel free to reach out.

Thanks,