Frontend API
Retrieve pages, blog posts, and records from your store's own content models to display in a storefront. With the Frontend API you can query content records, but not create or edit them.
Both methods take a content type as their first argument, which is the collection name of the content model — for example pages, blogs, or blog-categories — along with any custom content models defined in your store.
Returns a list of content records of the given type, with offset pagination using limit and page (the default limit is 15). The query object is passed through to the API, so where, expand, and search are also supported. The response is an object containing count, page, limit, and results.
await swell.content.list('pages', {
limit: 25,
page: 1
})Returns a single content record by slug or ID. An optional third argument accepts the same query parameters as list. Which fields come back depends on the content model. Records include id and date_created, and page and blog models typically include title, slug, content, published, and meta_description. Some content models also return a sections array, where each section has an id and a type along with whatever additional fields that section type defines. Field names are snake_case by default; if you initialize the client with useCamelCase: true, they are returned as camelCase instead.
await swell.content.get('pages', 'about-us')Content requests are not cached between calls. Every call to swell.content.get() sends a request to the API, so cache the result in your storefront if you need to avoid repeat requests for the same record.
Every swell.content.get() request sends a $preview query parameter, set to the previewContent option passed to swell.init(), which defaults to false. Because the option is applied before the query argument, you can pass $preview in the query to override it for a single request. swell.content.list() does not send this parameter.
// Send $preview=true on every content.get() request
swell.init('<store-id>', '<public_key>', {
previewContent: true
})
// Or override it for a single request
await swell.content.get('pages', 'about-us', { $preview: true })