@prismicio/client - v7
Overview
@prismicio/client is Prismic’s SDK for fetching and working with content.
Fetch content with a client and many query methods.
Retrieve metadata about a Prismic repository using repository methods.
Migrate content to Prismic using a write-capable client.
Convert content to other formats using content helpers.
Code confidently knowing all APIs are type-safe with TypeScript.
This page documents all APIs provided by @prismicio/client.
Install
@prismicio/client can be installed in any JavaScript project.
npm install --save @prismicio/clientAPI
createClient()
Creates a Prismic client that can fetch content from a Prismic repository.
const client = createClient(repositoryName, config);Parameters
repositoryNamestringThe repository name from which content is fetched.
config options
Options that configure content requests. See the config parameter in createClient().
const client = createClient("example-prismic-repo", {
accessToken: "example-access-token",
});accessTokenstringThe secure token for accessing the API. Only needed if your repository is private.
routesRoute[]A list of route resolver objects that define how a
page’s url property is resolved.
typestringpathstringThe resolved path of the page with optional keywords.
resolversRecord<string, string>A map of custom keywords to API IDs of the content relationships in the route’s document.
uidstringA specific UID to which this route is scoped. The route is only defined for the page whose UID matches the given UID.
langstringA specific language to which this route is scoped. The route is only defined for pages whose locale matches the given locale.
brokenRoutestringThe url value used for broken link fields. A link is broken when its
linked page has been unpublished or deleted.
defaultParamsobjectDefault parameters that will be sent with each query. These parameters can be overridden on each query if needed. See query parameters.
fetchOptionsRequestInitOptions provided to the client’s fetch() on all network requests. These
options will be merged with internally required options. They can also be
overriden on a per-query basis using the query’s fetchOptions parameter.
documentAPIEndpointstringThe full Content API V2 endpoint for the repository. Useful if you are using a proxy.
fetchtypeof fetchThe function used to make network requests to the Prismic Content API.
In environments where a global fetch function does not exist, this
function must be provided.
refstring | (() => string | Promise<string>)The ref used to query pages. It can optionally be a function that returns a ref.
Return type
A Prismic Client that can fetch content from the configured Prismic repository.
See the available query methods below.
createWriteClient()
Creates a Prismic client that can write content to a Prismic repository. It includes all methods supported in createClient().
const client = createWriteClient(repositoryName, config);Parameters
repositoryNamestringThe repository name to which content is written.
configobjectwriteTokenstringA Prismic write token that allows for writing content to the repository.
assetAPIEndpointstringThe Prismic Asset API endpoint.
"https://asset-api.prismic.io/"migrationAPIEndpointstringThe Prismic Migration API endpoint.
"https://migration.prismic.io/"Return type
A Prismic WriteClient that can write content to the configured Prismic repository.
The client should be used with the createMigration() function and the migrate() client method.
createMigration()
Creates a Migration instance that holds a set of migration procedures to execute, like “create a page” or “create an asset.” The migration can be executed with a write client’s migrate() method.
const migration = createMigration();Return value
A Migration instance that can hold migration procedures.
Query methods
Fetch content from a Prismic repository using the client’s query methods.
The following example fetches all blog posts from the fr-fr locale using the getAllByType() method.
const client = createClient("example-prismic-repo");
const blogPosts = await client.getAllByType("blog_post", {
lang: "fr-fr",
});Query parameters
All query methods accept optional parameters.
filtersstring[]One or more filters to filter pages for the query.
graphQuerystringSpecify which fields to retrieve and what content to retrieve from linked pages. See GraphQuery.
orderingsOrdering[]Orders the results by the specified field(s). You can specify as many fields as you want.
fieldstringThe field used to order results.
direction"asc" | "desc"The order of the sorting for this field.
"asc"
langstringThe locale from which to return results. Use "*" to fetch content from
all locales.
pagenumberThe results page number when a query returns multiple pages of results.
pageSizenumberThe maximum number of pages that the API will return for your query.
afterstringA page ID. Only pages listed after the page ID are returned.
Can be used along with the orderings parameter.
accessTokenstringThe secure token for accessing the API. Only needed if your repository is private.
brokenRoutestringThe route populated in the url property for broken links. A link is
broken when its linked page has been unpublished or deleted.
fetchLinksstring[]A list of fields to retrieve from linked pages. Prefer the
graphQuery option over fetchLinks.
integrationFieldsRefstringThe ref used to populate integration fields.
refstringThe ref used to query pages.
routesRoute[]Orders the results by the specified field(s). You can specify as many
fields as you want. See Route.
fetchstring[]Make queries faster by only retrieving the specified fields. Use the
graphQuery option instead.
predicatesstring[]filters.get()
Fetches pages based on the params argument. Results are paginated.
await client.get(params);Parameters
Return value
A paginated list of pages.
resultsPrismicDocument[]A paginated list of pages matching the query.
pagenumberThe page number for the page of results.
total_pagesnumberThe total number of pages.
results_sizenumberThe number of results in the page of results.
results_per_pagenumberThe maximum number of results per page.
total_results_sizenumberThe total number of results within all pages.
next_pagestring | nullThe API URL to the next page, if one exists.
prev_pagestring | nullThe API URL to the previous page, if one exists.
getFirst()
Fetches the first page returned based on the params argument.
await client.getFirst(params);Parameters
Return value
A PrismicDocument if one is found, null otherwise.
Possible errors
- Throws
NotFoundErrorif a matching page cannot be found.
getByID()
Fetches a page with a specific ID.
await client.getByID(id, params);Parameters
idstringReturn value
A PrismicDocument if one is found, null otherwise.
Possible errors
- Throws
NotFoundErrorif a matching page cannot be found.
getByIDs()
Fetches pages with specific IDs. Results are paginated.
await client.getByIDs(ids, params);Parameters
idsstring[]Return value
A paginated list of pages.
resultsPrismicDocument[]A paginated list of pages matching the query.
pagenumberThe page number for the page of results.
total_pagesnumberThe total number of pages.
results_sizenumberThe number of results in the page of results.
results_per_pagenumberThe maximum number of results per page.
total_results_sizenumberThe total number of results within all pages.
next_pagestring | nullThe API URL to the next page, if one exists.
prev_pagestring | nullThe API URL to the previous page, if one exists.
getAllByIDs()
Fetches pages with specific IDs. This method may make multiple network requests to fetch all matching pages.
await client.getAllByIDs(ids, params);Parameters
idsstring[]Return value
An array of matching PrismicDocument pages.
getByUID()
Fetches a page with a specific UID and type.
await client.getByUID(type, uid, params);Parameters
typestringuidstringReturn value
A PrismicDocument if one is found.
Possible errors
- Throws
NotFoundErrorif a matching page cannot be found.
getByUIDs()
Fetches pages with specific UIDs and a specific type. Results are paginated.
await client.getByUIDs(type, uids, params);Parameters
typestringuidsstring[]Return value
A paginated list of pages.
resultsPrismicDocument[]A paginated list of pages matching the query.
pagenumberThe page number for the page of results.
total_pagesnumberThe total number of pages.
results_sizenumberThe number of results in the page of results.
results_per_pagenumberThe maximum number of results per page.
total_results_sizenumberThe total number of results within all pages.
next_pagestring | nullThe API URL to the next page, if one exists.
prev_pagestring | nullThe API URL to the previous page, if one exists.
getAllByUIDs()
Fetches pages with specific UIDs and a specific type. This method may make multiple network requests to fetch all matching pages.
await client.getAllByUIDs(type, uids, params);Parameters
typestringuidsstring[]Return value
An array of matching PrismicDocument pages.
getSingle()
Fetches a specific single type page.
await client.getSingle(type, params);Parameters
typestringReturn value
A PrismicDocument if one is found, null otherwise.
Possible errors
- Throws
NotFoundErrorif a matching page cannot be found.
getByType()
Fetches pages with a specific type. Results are paginated.
await client.getByType(type, params);Parameters
typestringReturn value
A paginated list of pages.
resultsPrismicDocument[]A paginated list of pages matching the query.
pagenumberThe page number for the page of results.
total_pagesnumberThe total number of pages.
results_sizenumberThe number of results in the page of results.
results_per_pagenumberThe maximum number of results per page.
total_results_sizenumberThe total number of results within all pages.
next_pagestring | nullThe API URL to the next page, if one exists.
prev_pagestring | nullThe API URL to the previous page, if one exists.
getAllByType()
Fetches pages with a specific type. This method may make multiple network requests to fetch all matching documents.
await client.getAllByType(type, params);Parameters
typestringReturn value
An array of matching PrismicDocument pages.
getByTag()
Fetches pages with a specific tag. Results are paginated.
await client.getByTag(tag, params);Parameters
tagstringReturn value
A paginated list of pages.
resultsPrismicDocument[]A paginated list of pages matching the query.
pagenumberThe page number for the page of results.
total_pagesnumberThe total number of pages.
results_sizenumberThe number of results in the page of results.
results_per_pagenumberThe maximum number of results per page.
total_results_sizenumberThe total number of results within all pages.
next_pagestring | nullThe API URL to the next page, if one exists.
prev_pagestring | nullThe API URL to the previous page, if one exists.
getAllByTag()
Fetches pages with a specific tag. This method may make multiple network requests to fetch all matching documents.
await client.getAllByTag(tag, params);Parameters
tagstringReturn value
An array of matching PrismicDocument pages.
getByEveryTag()
Fetches pages with every tag from a list of tags. Results are paginated.
await client.getByEveryTag(tags, params);Parameters
tagsstring[]Return value
A paginated list of pages.
resultsPrismicDocument[]A paginated list of pages matching the query.
pagenumberThe page number for the page of results.
total_pagesnumberThe total number of pages.
results_sizenumberThe number of results in the page of results.
results_per_pagenumberThe maximum number of results per page.
total_results_sizenumberThe total number of results within all pages.
next_pagestring | nullThe API URL to the next page, if one exists.
prev_pagestring | nullThe API URL to the previous page, if one exists.
getAllByEveryTag()
Fetches pages with every tag from a list of tags. This method may make multiple network requests to fetch all matching pages.
await client.getAllByEveryTag(tags, params);Parameters
tagsstring[]Return value
An array of matching PrismicDocument Pages.
getBySomeTags()
Fetches pages with at least one tag from a list of tags. Results are paginated.
await client.getBySomeTags(tags, params);Parameters
tagsstring[]Return value
A paginated list of pages.
resultsPrismicDocument[]A paginated list of pages matching the query.
pagenumberThe page number for the page of results.
total_pagesnumberThe total number of pages.
results_sizenumberThe number of results in the page of results.
results_per_pagenumberThe maximum number of results per page.
total_results_sizenumberThe total number of results within all pages.
next_pagestring | nullThe API URL to the next page, if one exists.
prev_pagestring | nullThe API URL to the previous page, if one exists.
getAllBySomeTags()
Fetches pages with at least one tag from a list of tags. This method may make multiple network requests to fetch all matching documents.
await client.getAllBySomeTags(tags, params);Parameters
tagsstring[]Return value
An array of matching PrismicDocument pages.
queryLatestContent()
Configures the client to query the latest published content. This is the client’s default mode.
client.queryLatestContent();queryContentFromReleaseByID()
Configures the client to query content from a release with a specific ID.
client.queryContentFromReleaseByID(releaseID);Parameters
releaseIDstringqueryContentFromReleaseByLabel()
Configures the client to query content from a release with a specific label. A release’s label is its name shown in the Page Builder.
client.queryContentFromReleaseByLabel(releaseLabel);Parameters
releaseLabelstringqueryContentFromRef()
Configures the client to query content from a specific ref.
client.queryContentFromRef(ref);Parameters
refstring | (() => string | Promise<string>)The ref used to query pages. It can optionally be a function that returns a ref.
Repository methods
Fetch repository metadata using the client’s repository methods.
getRepository()
Fetches metadata about the client’s Prismic repository.
await client.getRepository();Return value
refsRef[]idstringrefstringThe value used to select a content version.
labelstringThe ref’s name. The master ref is always named “Master.”
isMasterRefbooleanDetermines if the ref is the master ref. The master ref contains the latest published content.
scheduledAtstringIf the ref is associated with a release, this value is the timestamp at which the release will be automatically published, if set.
languagesLanguage[]The repository’s enabled languages.
idstringnamestringis_masterbooleanDetermines if the language is the default language of the repository.
typesRecord<string, string>The repository’s content model API IDs mapped to their labels.
integrationFieldsRefstring | nullThe value used to select a content version for integration field data.
licensestringLicensing information for the repository’s content.
oauth_initiatestringThe URL used to begin the OAuth process for the repository.
oauth_tokenstringThe token used for the OAuth process for the repository.
versionstringThe version of the API. You probably don’t need this.
bookmarksunknownexperimentsunknownformsunknowngetRefs()
Fetches the repository’s active refs.
await client.getRefs();Return value
An array of ref objects:
idstringrefstringThe value used to select a content version.
labelstringThe ref’s name. The master ref is always named “Master.”
isMasterRefbooleanDetermines if the ref is the master ref. The master ref contains the latest published content.
scheduledAtstringIf the ref is associated with a release, this value is the timestamp at which the release will be automatically published, if set.
getRefByLabel()
Fetches a ref by its label. A release ref’s label is its name shown in the Page Builder.
client.getRefByLabel(releaseLabel);Parameters
releaseLabelstringPossible errors
- Throws
PrismicErrorif a matching release cannot be found.
getMasterRef()
Fetches the repository’s master ref.
client.getMasterRef();getReleases()
Fetches the repository’s active releases.
await client.getReleases();Return value
An array of ref objects:
idstringrefstringThe value used to select a content version.
labelstringThe ref’s name. The master ref is always named “Master.”
isMasterRefbooleanDetermines if the ref is the master ref. The master ref contains the latest published content.
scheduledAtstringIf the ref is associated with a release, this value is the timestamp at which the release will be automatically published, if set.
getReleaseByID()
Fetches a release with a specific ID.
await client.getReleaseByID(releaseID);Parameters
releaseIDstringReturn value
idstringrefstringThe value used to select a content version.
labelstringThe ref’s name. The master ref is always named “Master.”
isMasterRefbooleanDetermines if the ref is the master ref. The master ref contains the latest published content.
scheduledAtstringIf the ref is associated with a release, this value is the timestamp at which the release will be automatically published, if set.
Possible errors
- Throws
PrismicErrorif a matching release cannot be found.
getReleaseByLabel()
Fetches a release by its label. A release ref’s label is its name shown in the Page Builder.
await client.getReleaseByLabel(releaseLabel);Parameters
releaseLabelstringReturn value
idstringrefstringThe value used to select a content version.
labelstringThe ref’s name. The master ref is always named “Master.”
isMasterRefbooleanDetermines if the ref is the master ref. The master ref contains the latest published content.
scheduledAtstringIf the ref is associated with a release, this value is the timestamp at which the release will be automatically published, if set.
Possible errors
- Throws
PrismicErrorif a matching release cannot be found.
getTags()
Fetches the repository’s page tags.
client.getTags();Returns
An array of string tags.
buildQueryURL()
Builds a Content API query URL with a set of parameters.
client.buildQueryURL(params);resolvePreviewURL()
Fetches a previewed page’s URL using a preview token and page ID. The token and page ID are provided in the URL opened after clicking the Page Builder’s Preview the page button.
await client.resolvePreviewURL(params);Parameters
paramsParameters that determine how the preview URL is resolved.
previewTokenstringThe preview token provided by the preview session.
documentIDstringThe previewed page’s ID used to determine the destination URL.
defaultURLstringThe URL used if a page URL cannot be resolved.
"/" linkResolver(field: ContentRelationshipField) => string | null | undefinedA link resolver used to convert a content relationship field. If the link resolver returns a value, it takes priority over a route resolver.
Return value
The previewed page’s URL as a string, or defaultURL if a matching page cannot be found.
graphQLFetch()
A preconfigured fetch() function for Prismic’s GraphQL API that can be provided to GraphQL clients. It adds the required prismic-ref and Authorization headers to all requests.
client.graphQLFetch;migrate()
Executes a set of migration procedures added to a Migration instance created by createMigration().
client.migrate(migration, params);Parameters
paramsobjectParameters that affect how the migration is executed.
reporter(event: Event) => voidA function called when events occur during the migration.
typestringThe event type.
dataobjectMetadata about the event.
React to migration events
You can react to events during the migration process using the reporter option. Each event provides metadata about the event.
The following example logs the event type when an event occurs.
client.migrate(migration, {
reporter(event) {
console.log(event.type);
},
});The following events are supported:
start- The start of the migration process.end- The end of the migration process.assets:creating- An asset is being created.assets:created- All assets were created.documents:masterLocale- Fetching the master locale for a page.documents:creating- A page is being created.documents:created- All pages were created.documents:updating- A page is being updated.documents:updated- All pages were updated.
Migration methods
You can migrate content to Prismic using a special write-capable version of the client.
These methods are available on the Migration instance returned by createMigration().
createAsset()
Creates a new asset in a Migration instance. The asset will not be created in your repository until the migration is executed with migrate().
migration.createAsset(asset);
migration.createAsset(field);
migration.createAsset(file, filename, params);Parameters
One of the three signatures must be used:
fileBlob | File | URLBinary data for the asset. It can also be a URL pointing to a hosted asset that will be downloaded.
filenamestringThe filename shown in the repository’s media library.
paramsobjectMetadata about the image.
notesstringNotes shown in the repository’s media library.
creditsstringCredits shown in the repository’s media library.
tagsstring[]Return value
A reference to the asset that can be referenced in migration pages. The asset won’t be created until the migration is executed with migrate().
createDocument()
Creates a new page in a Migration instance. The page will not be created in your repository until the migration is executed with migrate().
migration.createDocument(document, title, params);Parameters
documentPrismicDocumentA Prismic page in API v2 format.
paramsobjectmasterLanguageDocumentPrismicMigrationDocument | PrismicDocument | ContentRelationshipField | (() => PrismicMigrationDocument | PrismicDocument | ContentRelationshipField)The page used as the new page’s master language.
Return value
A reference to the page that can be referenced in other migration pages. The page won’t be created until the migration is executed with migrate().
updateDocument()
Updates an existing page in a Migration instance. The page will not be updated in your repository until the migration is executed with migrate().
migration.updateDocument(document, title);Parameters
documentPrismicDocumentThe Prismic page in API v2 format with updated content.
Return value
A reference to the page that can be referenced in other migration pages. The page won’t be created until the migration is executed with migrate().
createDocumentFromPrismic()
Creates a new page in a Migration instance based on an existing Prismic page. Assets and content relationships will be created and resolved automatically. The page and its assets will not be created in your repository until the migration is executed with migrate().
migration.createDocumentFromPrismic(document, title);Parameters
documentPrismicDocumentA Prismic page in API v2 format.
Return value
A reference to the page that can be referenced in other migration pages. The page won’t be created until the migration is executed with migrate().
getByUID()
Gets a page with a specific UID and type from within a Migration instance. Use this method to retrieve a page that has not yet been migrated using migrate().
migration.getByUID(type, uid);Parameters
typestringuidstringReturn value
A PrismicMigrationDocument if one is found, undefined otherwise.
getSingle()
Gets a specific single type page from within a Migration instance. Use this method to retrieve a page that has not yet been migrated using migrate().
migration.getSingle(type);Parameters
typestringReturn value
A PrismicMigrationDocument if one is found, undefined otherwise.
Content helpers
@prismicio/client provides helpers that manipulate Prismic content. The helpers can be used throughout your website or in scripts.
Content helpers can be imported directly from @prismicio/client:
import { asDate } from "@prismicio/client";asDate()
Converts a date or timestamp field to a JavaScript Date.
asDate(field);Parameters
fieldDateField | TimestampFieldReturn value
field as a Date, or null if the field is empty.
asLink()
Converts a link field, link to media field, content relationship field, or Prismic page to a URL.
asLink(fieldOrDocument, params);Parameters
fieldOrDocumentLinkField | LinkToMediaField | ContentRelationshipField | PrismicDocumentconfigobjectConfiguration that affects how a link is converted.
linkResolver(field: ContentRelationshipField) => string | null | undefinedA link resolver used to convert a content relationship field. If the link resolver returns a value, it takes priority over a route resolver.
Return value
The field’s or page’s URL as a string, or null if the field is empty.
asLinkAttrs()
Converts a link field, link to media field, content relationship field, or Prismic page to a set of link attributes. The attributes are intended to be passed to <a> HTML elements.
asLinkAttrs(fieldOrDocument, params);Parameters
fieldOrDocumentLinkField | LinkToMediaField | ContentRelationshipField | PrismicDocumentconfigobjectConfiguration that affects how a link is converted.
linkResolver(field: ContentRelationshipField) => string | null | undefinedA link resolver used to convert a content relationship field. If the link resolver returns a value, it takes priority over a route resolver.
rel(metadata) => string | undefinedA function that determines the rel attribute value. The function is
provided metadata about the link.
Return value
An object of <a> HTML attributes.
target"_blank" | undefinedThe link’s
target
value.
"_blank" if the field’s “Open in new tab” option is checked.
asHTML()
Converts a rich text field to HTML. The output can be customized using a set of serialization functions.
asHTML(field, config);Parameters
fieldRichTextFieldconfigobjectConfiguration that affects how the rich text is converted.
linkResolver(field: ContentRelationshipField) => string | null | undefinedA link resolver used to convert a content relationship field. If the link resolver returns a value, it takes priority over a route resolver.
serializerobject | functionA map of rich text block types to functions that return HTML. A single function can also be provided, but an object is recommended.
Standard HTML elements (e.g. heading1 becomes a <h1>).
Return value
The rich text field as an HTML string.
asText()
Converts a rich text field to plain text.
asText(field, config);Parameters
fieldRichTextFieldconfigobjectConfiguration that affects how the rich text is converted.
separatorstringThe string inserted between rich text blocks.
" "
Return value
The rich text field as a plain string.
asImageSrc()
Converts an image field to an image URL. The image can be transformed using imgix’s Rendering API.
asImageSrc(field, transformations);Parameters
fieldImageFieldtransformationsobjectimgix transformations to apply. See imgix’s Rendering API for a list of supported transformations.
Return value
The image field’s URL as a string.
asImageWidthSrcSet()
Converts an image field to a srcset designed for <img> HTML elements. The srcset uses width descriptors, like 400w and 600w.
The image can be transformed using imgix’s Rendering API.
asImageWidthSrcSet(field, config);Parameters
fieldImageFieldconfigobjectConfiguration that affects how the image is converted.
widths"thumbnails" | number[]The width descriptors to be used in the srcset. If "thumbnails" is
provided, the widths of the image’s responsive
views are used.
[640, 750, 828, 1080, 1200, 1920, 2048, 3840]
...transformationsobjectimgix transformations to apply. See imgix’s Rendering API for a list of supported transformations.
Return value
An object of <img> HTML attributes.
asImagePixelDensitySrcSet()
Converts an image field to a srcset designed for <img> HTML elements. The srcset uses pixel density descriptors, like 1x and 2x.
The image can be transformed using imgix’s Rendering API.
asImagePixelDensitySrcSet(field, config);Parameters
fieldImageFieldconfigobjectConfiguration that affects how the image is converted.
pixelDensitiesnumber[]The pixel density descriptors to be used in the srcset.
[1, 2, 3]...transformationsobjectimgix transformations to apply. See imgix’s Rendering API for a list of supported transformations.
Return value
An object of <img> HTML attributes.
mapSliceZone()
Converts slices in a slice zone to objects of your choosing. It is designed to add data, remove unused content, or preprocess content on a server.
await mapSliceZone(slices, mappers, context);Parameters
slicesSliceZonemappersRecord<string, (args: Metadata) => Promise<any> | any>A map of slice type IDs to mapper functions. The return value of each function becomes the slice’s new value.
sliceSliceindexnumberThe index of slice in the slice zone.
slicesSliceZoneThe slices argument passed to mapSliceZone().
contextanyThe context argument passed to mapSliceZone().
contextanyArbitrary data provided to each function in mappers.
Return value
A promise containing the provided slice zone with each slice converted according to the functions in the mappers argument.
Mapping to UI component props
When using the <SliceZone> component from @prismicio/react, @prismicio/vue, or @prismicio/svelte, properties returned by the mapper function become the slice component’s props.
The following example shows how mapSliceZone() can populate a React component’s slice and lang props.
const slices = await mapSliceZone(document.data.slices, {
current_language: ({ slice }) => {
// The slice's component will be rendered like:
// <CurrentLanguage slice={slice} lang={document.lang} />
return { slice, lang: document.lang };
},
});
function CurrentLanguage({ slice, lang }) {
return <p>The current language is: {lang}</p>;
}isFilled
A set of functions that determine if a field has content or not. Each field type has its own function within isFilled.
isFilled.richText(field);The following functions are available:
isFilled.color(field)isFilled.contentRelationship(field)isFilled.date(field)isFilled.embed(field)isFilled.geoPoint(field)isFilled.group(field)isFilled.image(field)isFilled.imageThumbnail(field)isFilled.integrationField(field)isFilled.keyText(field)isFilled.link(field)isFilled.linkToMedia(field)isFilled.number(field)isFilled.richText(field)isFilled.select(field)isFilled.table(field)isFilled.timestamp(field)isFilled.title(field)
Fields that are marked as repeatable, such as a repeatable list of links, can be checked with isFilled.repeatable().
isFilled.repeatable(field);Slice zones can also be checked for at least one slice.
isFilled.sliceZone(slices);Parameters
fieldRichTextField | ImageField | ...A field to check. The field type must match the isFilled checker.
Return value
true if the field has content, false otherwise.
Query filters
You can adjust which pages are returned by query methods using filters. @prismicio/client provides helpers to write filters.
import { filter } from "@prismicio/client";Each filter type has its own function within filter.
The following example uses the not() filter to fetch all Page pages except the pages with the home UID.
await client.getAllByType("page", {
filters: [filter.not("my.page.uid", "home")],
});at()
Checks that a field or page metadata property matches a value exactly.
filter.at(path, value);Parameters
pathstringA path to a field or page metadata property. See the supported paths below.
valuestring | number | boolean | Date | string[]The value to compare against. A string[] is only allowed when path is
"document.tags".
Return value
The filter as a string. It can be used in a query method’s filters parameter.
Supported paths
The following paths are supported by this filter:
"document.type""document.tags""document.id""my.[document-type].uid""my.[document-type].[key-text-field]""my.[document-type].[select-field]""my.[document-type].[number-field]""my.[document-type].[date-field]""my.[document-type].[boolean-field]""my.[document-type].[content-relationship-field]"
not()
Checks that a field or page metadata property doesn’t match a value exactly.
filter.not(path, value);Parameters
pathstringA path to a field or page metadata property. See the supported paths below.
valuestring | number | boolean | Date | string[]The value to compare against. A string[] is only allowed when path is
"document.tags".
Return value
The filter as a string. It can be used in a query method’s filters parameter.
Supported paths
The following paths are supported by this filter:
"document.type""document.tags""document.id""my.[document-type].uid""my.[document-type].[key-text-field]""my.[document-type].[select-field]""my.[document-type].[number-field]""my.[document-type].[date-field]""my.[document-type].[boolean-field]""my.[document-type].[content-relationship-field]"
any()
Includes pages with a field or metadata property matching a value from a given list.
filter.any(path, values);Parameters
pathstringA path to a field or page metadata property. See the supported paths below.
values(string | number | boolean | Date)[]Return value
The filter as a string. It can be used in a query method’s filters parameter.
Supported paths
The following paths are supported by this filter:
"document.type""document.tags""document.id""my.[document-type].uid""my.[document-type].[key-text-field]""my.[document-type].[select-field]""my.[document-type].[number-field]""my.[document-type].[date-field]""my.[document-type].[boolean-field]""my.[document-type].[content-relationship-field]"
in()
Includes pages with an ID or UID matching a value from a given list. This filter is much more efficient at that than the any() filter.
filter.in(path, values);Parameters
pathstringA path to an ID or UID property. See the supported paths below.
valuesstring[]Return value
The filter as a string. It can be used in a query method’s filters parameter.
Supported paths
The following paths are supported by this filter:
"document.id""my.[document-type].uid"
fulltext()
Includes pages with a matching string anywhere in the page. It can also check within a specific rich text, text, or select field.
filter.fulltext(path, searchTerm);Parameters
path"document" | stringA path to a field or "document" to search the whole page. See the supported paths below.
searchTermstringThe search term to find.
Return value
The filter as a string. It can be used in a query method’s filters parameter.
Supported paths
The following paths are supported by this filter:
"document""my.[document-type].uid""my.[document-type].[rich-text-field]""my.[document-type].[text-field]""my.[document-type].[select-field]"
has()
Includes pages that have a value for a specific field.
filter.has(path);Parameters
pathstringA path to a field. See the supported paths below.
Return value
The filter as a string. It can be used in a query method’s filters parameter.
Supported paths
The following paths are supported by this filter:
"my.[document-type].[field]"
Groups and slices are not supported.
missing()
Includes pages that do not have a value for a specific field. The inverse of has().
filter.missing(path);Parameters
pathstringA path to a field. See the supported paths below.
Return value
The filter as a string. It can be used in a query method’s filters parameter.
Supported paths
The following paths are supported by this filter:
"my.[document-type].[field]"
Groups and slices are not supported.
similar()
Includes pages that have similar content to a given page. This filter allows you to build content discovery features, like a “Related posts” section.
filter.similar(documentID, specificity);Parameters
documentIDstringThe ID of the page used to compare other pages against.
specificitynumberThe maximum number of pages that a term may appear in to be considered relevant.
Return value
The filter as a string. It can be used in a query method’s filters parameter.
geopointNear()
Includes pages with a geopoint field value near the given coordinates.
filter.geopointNear(path, latitude, longitude, radius);Parameters
latitudenumberThe latitude coordinate.
longitudenumberThe longitude coordinate.
radiusnumberThe search radius in kilometers.
Return value
The filter as a string. It can be used in a query method’s filters parameter.
Supported paths
The following paths are supported by this filter:
"my.[document-type].[geopoint-field]"
numberLessThan()
Includes pages with a number field value less than a given number.
filter.numberLessThan(path, number);Parameters
numbernumberReturn value
The filter as a string. It can be used in a query method’s filters parameter.
Supported paths
The following paths are supported by this filter:
"my.[document-type].[number-field]"
numberGreaterThan()
Includes pages with a number field value greater than a given number.
filter.numberGreaterThan(path, number);Parameters
numbernumberReturn value
The filter as a string. It can be used in a query method’s filters parameter.
Supported paths
The following paths are supported by this filter:
"my.[document-type].[number-field]"
numberInRange()
Includes pages with a number field value within a given range.
filter.numberInRange(path, lowerLimit, upperLimit);Parameters
lowerLimitnumberupperLimitnumberReturn value
The filter as a string. It can be used in a query method’s filters parameter.
Supported paths
The following paths are supported by this filter:
"my.[document-type].[number-field]"
dateAfter()
Includes pages with a date field, timestamp field, or timestamp metadata property after a given date.
filter.dateAfter(path, date);Parameters
pathstringA path to a field or page metadata property. See the supported paths below.
datestring | number | DateThe date to compare. The value can be an ISO 8601 date or timestamp (e.g.
2002-08-28 or 2002-08-28T15:30:00+0300), a 13-digit Epoch timestamp
(e.g. 1030545000000), or a
Date
object.
Return value
The filter as a string. It can be used in a query method’s filters parameter.
Supported paths
The following paths are supported by this filter:
document.first_publication_datedocument.last_publication_datemy.[custom-type].[date-field]my.[custom-type].[timestamp-field]
dateBefore()
Includes pages with a date field, timestamp field, or timestamp metadata property before a given date.
filter.dateBefore(path, date);Parameters
pathstringA path to a field or page metadata property. See the supported paths below.
datestring | number | DateThe date to compare. The value can be an ISO 8601 date or timestamp (e.g.
2002-08-28 or 2002-08-28T15:30:00+0300), a 13-digit Epoch timestamp
(e.g. 1030545000000), or a
Date
object.
Return value
The filter as a string. It can be used in a query method’s filters parameter.
Supported paths
The following paths are supported by this filter:
document.first_publication_datedocument.last_publication_datemy.[custom-type].[date-field]my.[custom-type].[timestamp-field]
dateBetween()
Includes pages with a date field, timestamp field, or timestamp metadata property between given dates.
filter.dateBetween(path, startDate, endDate);Parameters
pathstringA path to a field or page metadata property. See the supported paths below.
startDatestring | number | DateThe start date to compare. The value can be an ISO 8601 date or timestamp
(e.g. 2002-08-28 or 2002-08-28T15:30:00+0300), a 13-digit Epoch
timestamp (e.g. 1030545000000), or a
Date
object.
endDatestring | number | DateThe end date to compare. The value can be an ISO 8601 date or timestamp
(e.g. 2002-08-28 or 2002-08-28T15:30:00+0300), a 13-digit Epoch
timestamp (e.g. 1030545000000), or a
Date
object.
Return value
The filter as a string. It can be used in a query method’s filters parameter.
Supported paths
The following paths are supported by this filter:
document.first_publication_datedocument.last_publication_datemy.[custom-type].[date-field]my.[custom-type].[timestamp-field]
dateDayOfMonth()
Includes pages with a date field, timestamp field, or timestamp metadata property that is on a specific day of the month.
filter.dateDayOfMonth(path, dayOfMonth);Parameters
pathstringA path to a field or page metadata property. See the supported paths below.
dayOfMonthnumberThe day of the month to compare.
Return value
The filter as a string. It can be used in a query method’s filters parameter.
Supported paths
The following paths are supported by this filter:
document.first_publication_datedocument.last_publication_datemy.[custom-type].[date-field]my.[custom-type].[timestamp-field]
dateDayOfMonthAfter()
Includes pages with a date field, timestamp field, or timestamp metadata property that is after a specific day of the month.
filter.dateDayOfMonthAfter(path, dayOfMonth);Parameters
pathstringA path to a field or page metadata property. See the supported paths below.
dayOfMonthnumberThe day of the month to compare.
Return value
The filter as a string. It can be used in a query method’s filters parameter.
Supported paths
The following paths are supported by this filter:
document.first_publication_datedocument.last_publication_datemy.[custom-type].[date-field]my.[custom-type].[timestamp-field]
dateDayOfMonthBefore()
Includes pages with a date field, timestamp field, or timestamp metadata property that is before a specific day of the month.
filter.dateDayOfMonthBefore(path, dayOfMonth);Parameters
pathstringA path to a field or page metadata property. See the supported paths below.
dayOfMonthnumberThe day of the month to compare.
Return value
The filter as a string. It can be used in a query method’s filters parameter.
Supported paths
The following paths are supported by this filter:
document.first_publication_datedocument.last_publication_datemy.[custom-type].[date-field]my.[custom-type].[timestamp-field]
dateDayOfWeek()
Includes pages with a date field, timestamp field, or timestamp metadata property that is on a specific day of the week.
filter.dateDayOfWeek(path, dayOfWeek);Parameters
pathstringA path to a field or page metadata property. See the supported paths below.
dayOfWeekstring | numberThe day of the week to compare. See the supported days of the week below.
Return value
The filter as a string. It can be used in a query method’s filters parameter.
Supported paths
The following paths are supported by this filter:
document.first_publication_datedocument.last_publication_datemy.[custom-type].[date-field]my.[custom-type].[timestamp-field]
Supported days of the week
The following days of the week are supported by this filter:
"monday","mon",1"tuesday","tue",2"wednesday","wed",3"thursday","thu",4"friday","fri",5"saturday","sat",6"sunday","sun",7
Strings can be capitalized (e.g. "Monday") or all caps (e.g. "MONDAY").
dateDayOfWeekAfter()
Includes pages with a date field, timestamp field, or timestamp metadata property that is after a specific day of the week.
filter.dateDayOfWeekAfter(path, dayOfWeek);Parameters
pathstringA path to a field or page metadata property. See the supported paths below.
dayOfWeekstring | numberThe day of the week to compare. See the supported days of the week below.
Return value
The filter as a string. It can be used in a query method’s filters parameter.
Supported paths
The following paths are supported by this filter:
document.first_publication_datedocument.last_publication_datemy.[custom-type].[date-field]my.[custom-type].[timestamp-field]
Supported days of the week
The following days of the week are supported by this filter:
"monday","mon",1"tuesday","tue",2"wednesday","wed",3"thursday","thu",4"friday","fri",5"saturday","sat",6"sunday","sun",7
Strings can be capitalized (e.g. "Monday") or all caps (e.g. "MONDAY").
dateDayOfWeekBefore()
Includes pages with a date field, timestamp field, or timestamp metadata property that is before a specific day of the week.
filter.dateDayOfWeekBefore(path, dayOfWeek);Parameters
pathstringA path to a field or page metadata property. See the supported paths below.
dayOfWeekstring | numberThe day of the week to compare. See the supported days of the week below.
Return value
The filter as a string. It can be used in a query method’s filters parameter.
Supported paths
The following paths are supported by this filter:
document.first_publication_datedocument.last_publication_datemy.[custom-type].[date-field]my.[custom-type].[timestamp-field]
Supported days of the week
The following days of the week are supported by this filter:
"monday","mon",1"tuesday","tue",2"wednesday","wed",3"thursday","thu",4"friday","fri",5"saturday","sat",6"sunday","sun",7
Strings can be capitalized (e.g. "Monday") or all caps (e.g. "MONDAY").
dateMonth()
Includes pages with a date field, timestamp field, or timestamp metadata property that is within a specific month.
filter.dateMonth(path, month);Parameters
pathstringA path to a field or page metadata property. See the supported paths below.
monthstring | numberThe month to compare. See the supported months below.
Return value
The filter as a string. It can be used in a query method’s filters parameter.
Supported paths
The following paths are supported by this filter:
document.first_publication_datedocument.last_publication_datemy.[custom-type].[date-field]my.[custom-type].[timestamp-field]
Supported months
The following months are supported by this filter:
"january","jan",1"february","feb",2"march","mar",3"april","apr",4"may","may",5"june","jun",6"july","jul",7"august","aug",8"september","sep",9"october","oct",10"november","nov",11"december","dec",12
Strings can be capitalized (e.g. "Monday") or all caps (e.g. "MONDAY").
dateMonthAfter()
Includes pages with a date field, timestamp field, or timestamp metadata property that is after a specific month.
filter.dateMonthAfter(path, month);Parameters
pathstringA path to a field or page metadata property. See the supported paths below.
monthstring | numberThe month to compare. See the supported months below.
Return value
The filter as a string. It can be used in a query method’s filters parameter.
Supported paths
The following paths are supported by this filter:
document.first_publication_datedocument.last_publication_datemy.[custom-type].[date-field]my.[custom-type].[timestamp-field]
Supported months
The following months are supported by this filter:
"january","jan",1"february","feb",2"march","mar",3"april","apr",4"may","may",5"june","jun",6"july","jul",7"august","aug",8"september","sep",9"october","oct",10"november","nov",11"december","dec",12
Strings can be capitalized (e.g. "Monday") or all caps (e.g. "MONDAY").
dateMonthBefore()
Includes pages with a date field, timestamp field, or timestamp metadata property that is before a specific month.
filter.dateMonthBefore(path, month);Parameters
pathstringA path to a field or page metadata property. See the supported paths below.
monthstring | numberThe month to compare. See the supported months below.
Return value
The filter as a string. It can be used in a query method’s filters parameter.
Supported paths
The following paths are supported by this filter:
document.first_publication_datedocument.last_publication_datemy.[custom-type].[date-field]my.[custom-type].[timestamp-field]
Supported months
The following months are supported by this filter:
"january","jan",1"february","feb",2"march","mar",3"april","apr",4"may","may",5"june","jun",6"july","jul",7"august","aug",8"september","sep",9"october","oct",10"november","nov",11"december","dec",12
Strings can be capitalized (e.g. "Monday") or all caps (e.g. "MONDAY").
dateYear()
Includes pages with a date field, timestamp field, or timestamp metadata property that is within a specific year.
filter.dateYear(path, year);Parameters
pathstringA path to a field or page metadata property. See the supported paths below.
yearnumberReturn value
The filter as a string. It can be used in a query method’s filters parameter.
Supported paths
The following paths are supported by this filter:
document.first_publication_datedocument.last_publication_datemy.[custom-type].[date-field]my.[custom-type].[timestamp-field]
dateHour()
Includes pages with a date field, timestamp field, or timestamp metadata property that is within a specific hour.
filter.dateHour(path, hour);Parameters
pathstringA path to a field or page metadata property. See the supported paths below.
hournumberReturn value
The filter as a string. It can be used in a query method’s filters parameter.
Supported paths
The following paths are supported by this filter:
document.first_publication_datedocument.last_publication_datemy.[custom-type].[date-field]my.[custom-type].[timestamp-field]
dateHourAfter()
Includes pages with a date field, timestamp field, or timestamp metadata property that is after a specific hour.
filter.dateHourAfter(path, hour);Parameters
pathstringA path to a field or page metadata property. See the supported paths below.
hournumberReturn value
The filter as a string. It can be used in a query method’s filters parameter.
Supported paths
The following paths are supported by this filter:
document.first_publication_datedocument.last_publication_datemy.[custom-type].[date-field]my.[custom-type].[timestamp-field]
dateHourBefore()
Includes pages with a date field, timestamp field, or timestamp metadata property that is before a specific hour.
filter.dateHourBefore(path, hour);Parameters
pathstringA path to a field or page metadata property. See the supported paths below.
hournumberReturn value
The filter as a string. It can be used in a query method’s filters parameter.
Supported paths
The following paths are supported by this filter:
document.first_publication_datedocument.last_publication_datemy.[custom-type].[date-field]my.[custom-type].[timestamp-field]