Get all shared content in list from page using API and Next.js

My company is trying to migrate from WordPress, and so I'm building a prototype with agility cms and Next.js. I've been wondering how I could essentially get an archive page of all items in a list. The example I have is `authors`..

On a page, I've created a module that's supposed to get all Authors, but when query the page by id: `https://123-api.agilitycms.cloud/fetch/en-us/page/10`, I get back the page data, but for the posts, I do not see all authors, this is what i get:

```

"fields": {
"title": "We Love Writing",
"preHeader": "Authors",
"subtitle": "Some amazing blog posts that are written by even more amazing people.",
"readMoreLabel": "Read More",
"posts": {
"referencename": "authors"
}
}

```

 

Is the idea that I'm then supposed to use `"referencename": "authors"` to perform another API query to get all authors?so use `/{apitype}/{lang}/list/{referenceName}` to make a GET call then for all the authors? I was expecting to get all the authors data alongside all the other modules in the page....

Is this the correct way to make an archive page?

0

Comments

2 comments
  • Official comment

    Hi there - amazing work so far!  Next.js and Agility CMS go great together.

    You have a couple of options here.  You can certainly make the second call using the referencename from module.  That will return you the list.  You can also use the expandAllContentLinks=true parameter on that call to pull in the list together with the first call.  That's a brand new parameter just released last week.

    There's also another route you may want to consider, and that's using the Sync API.  You can check out the example of that in the NextJS starter code here: https://github.com/agility/agilitycms-nextjs-starter-2020 

    This is a pretty fully featured starter using NextJS, Agility CMS, and Tailwind CSS, with a lot of components that you can use to get going quickly.  

    The biggest benefit to using the sync api is that when you need to build the site it only pulls down the content that has changed since the last build, making each build really, really fast.

    Happy coding!

     

    Comment actions Permalink
  • Joel Varty Wow! this is a fantastic starter! There's a lot of good stuff in here. It's awesome that you've combined Tailwinds and styled-components; to me that's the perfect CSS setup!

    Thanks for pointing out the `expandAllContentLinks`. I also saw you can use this parameter with the JS SDK also. What I also love is the use of `getCustomInitialProps` which also runs serverside and performs the second request for all items in a list is `expandAllContentLinks` isn't used in the initial query. I will remember this technique...

    Thanks for recommending how to get all shared content items from a module!

    0
    Comment actions Permalink

Please sign in to leave a comment.

Didn't find what you were looking for?

New post