How do I fetch the content of a field in exactly the order I added them in Contentful, without using the order
param?
I have a field in my Content Model called “Content Blocks”. Each time I use this model, I add multiple blocks within it that link to other content (an article) also hosted in my space.
So, ContentBlocks is essentially an object that contains other objects: contentBlock1, contentBlock2, contentBlock3, etc.
When I make the API call to fetch this fields, however, the contentBlocks come in out of order from the way I added them on Contentful. So, on Contentful it looks like this:
CONTENTBLOCKS:
- contentBlock1
- contentBlock2
- contentBlock3
- contentBlock4
- …
but when I get the fetch results, it comes in randomly as
{
contentBlock2,
contentBlock3,
contentBlock1,
contentBlock4,
...
}
My fetch code is:
fetchNewsletter (publishDate) {
try {
return this.instance
.get(`${this.contentfulURL}/${MAGAZINE_SPACE_ID}/entries?content_type=newsletter&fields.publishDate=${publishDate}&include=2`)
.set({ Authorization: `Bearer ${MAGAZINE_ACCESS_TOKEN}`, Accept: 'application.json' })
.then(response => response.body)
.catch(error => console.error(error))
} catch (error) {
console.error('fetch newsletter error', error)
}
}
The sub-blocks are not based on any property ( id
, createdAt
) other than the order in which they are added in, so using the order
param will not help.
This issue is similar to what I am experiencing.
How do I fetch the array of contentBlocks in exactly the order I added them in Contentful, without using the order
param?