API > GetPage
The GetPages function is used to fetch the content/properties on multiple pages.
This function will return an array of type Page.
import { getPages } from "@suncel/nextjs/api";
type GetPagesRes = {
pages: Page[];
count: number;
total_count: number;
success: boolean;
};
const getPages = async (
options?:GetPagesOptions
): Promise<RequestResult<GetPagesRes>>
options: Optional fetching options (see below)
type GetPagesOptions = {
author?: boolean;
root?: boolean;
folder?: string;
q?: string;
includes_folder?: boolean;
only_folder?: boolean;
folder_depth?: number;
tags?: string[];
status?: PageStatus;
language?: string;
content_type?: string;
page_variant_id?: string;
limit?: number;
offset?: number;
sort_by?: keyof Page;
order?: 'asc' | 'desc';
fields?: (keyof Page)[];
excluded_fields?: (keyof Page)[];
};
author: If you want to populate the author information in the result.
root: To fetch only the root pages (do not work if folder option has a value) ****(default value⇒ false)
folder: Folder Id - fetch all the pages under this folder. It fetches only the pages at the root of the folder. If you want to fetch the pages from the sub-folders of the folder, use folder_depth options (do not work if root is true) ****
folder_depth: Gives you control over how many levels down pages should be fetched (do not work if folder is empty)
q: search query on the name, slug, and path(accept regex)
path: search query on the path
includes_folder: To include folders in the result (default value⇒ false)
status: To filter by status
language: To filter per language
content_type: To filter per content type
limit: Limit of pages per request. 0 is no limit (use for pagination)
offset: Number of pages to skip (use for pagination)
sort_by: Apply a sort on an attribute (need to be used with order)
order: order of the sort (need to be used with sort_by)
fields: specify which fields to return (used to optimize the size of the request)
excluded_fields: specify which fields to exclude (used to optimize the size of the request) (example: excluded_fields:['content', 'saved-content', 'history']
, it will remove the content, the draft content, and the page history from the request. it will optimize the result of the query as those two fields can be quite large )