How to skip fetching archived content

We are fetching builder page as per Integrating Pages - Builder.io
If we have 2 pages “page1” & “page2” with exact same URL and fields, according to builder logic, it will show the first page “page1” from the list.
Now, if I archive “page1”, it still shows “page1” but it should show “page2”.

How can we achieve this? Is there any query parameter we can pass which will not fetch archived entries?

1 Like

Hi Olivela!

That seems like a very strange issue, it’s not supposed to return archived content. Will you be able to help us with the page1 and page2 content links for further investigation?

1 Like

I’m experiencing this with this archived content shadowing this published content when using this JS API query:

builder
  .get('learning-hub-article', {
    fields: 'data,firstPublished,id,name',
    includeRefs: true,
    options: {
      includeUnpublished: builder.previewingModel === 'learning-hub-article',
    },
    url: '/learn/climate-action-framework',
  })
  .promise()

Public API key: 4a52b3b8ac444b998a4f90d60aa6fcc3

Interestingly, it doesn’t occur with this URL generated by the Builder editor. It’s something about the URL the JS API generates.

Hi @balleverte!

We are not able to reproduce this from our end, could you try clearing the cache as well as republishing the content again and see if that fixes the issue?

With caching disabled, compare the results of these URLs:

This one generated by the Builder visual editor (using includeUnpublished=true) returns the archived data (id=5c7e20f2a8ff4915bc348cb63ac6b278):

https://cdn.builder.io/api/v1/query/4a52b3b8ac444b998a4f90d60aa6fcc3/learning-hub-article?omit=meta.componentsUsed&apiKey=4a52b3b8ac444b998a4f90d60aa6fcc3&includeUnpublished=true&fields=data%2CfirstPublished%2Cid%2Cname&userAttributes.urlPath=%2Flearn%2Fclimate-action-framework&userAttributes.host=null&userAttributes.device=desktop&options.learning-hub-article.model=%22learning-hub-article%22

This one generated by the application running standalone (not in preview mode, using includeUnpublished=false) returns the published content (id=dcce36ec6a2d421c8b650966a9470bdc):

https://cdn.builder.io/api/v1/query/4a52b3b8ac444b998a4f90d60aa6fcc3/learning-hub-article?omit=meta.componentsUsed&apiKey=4a52b3b8ac444b998a4f90d60aa6fcc3&includeUnpublished=false&fields=data%2CfirstPublished%2Cid%2Cname&userAttributes.urlPath=%2Flearn%2Fclimate-action-framework&userAttributes.host=null&userAttributes.device=desktop&options.learning-hub-article.model=%22learning-hub-article%22

Hi @balleverte,

If you use includeUnpublished=true that is going to include archived content as well by default. In case you don’t want archived content then I recommend you delete them.

In that case, the answer seems to be to add includeUnpublished=true as well as either &query.published.$ne=archived or &query.published.$in=%5B%27draft%27%2C%20%27published%27%5D.

1 Like