Query
The query API
Section titled “The query API”uHeadless has a flexible query API that allows to access any content that matches a specific query.
Options
Section titled “Options”This resource has these properties
| Property | Default | Type | Description |
|---|---|---|---|
| breadcrumb | false | boolean | Include the breadcrumb property in the document result. |
| depth | 2 | number | The depth of relations to include in the response. |
| domain | string | Scope the results to a specified hostname define under “Culture and hostnames” in Umbraco. | |
| exclude | Array<string> | Define the fields that you want to exclude in the response. You can’t use both exclude and include. If so, include will take precedence over exclude. | |
| include | Array<string> | Define the fields that you want to include in the response. | |
| limit | 10 | number | The amount of document to return form the query. |
| locale | current or default language | string | Set the locale of the content you wan’t to query for. By default it uses the currentPage if middleware is enabled. Otherwise the language defined as default in Umbraco. |
| query | uHeadlessQuery | Query the results. See queries sections to learn more. | |
| skip | number | The amount to skip before starting the paginated result. | |
| sort | asc or desc | The direction you want to sort in. | |
| sortBy | string | The property that you want to sort by, e.g. createdAt or propterties.publishDate. |
How to use
Section titled “How to use”The query API is used as query parameters in the url under the query scope.
const url = new URL('https://api.uheadless.com')
url.searchParams.set('token', UHEADLESS_API_KEY)
// Has to belong to the culture and hostname "example.com"url.searchParams.set('query[domain]', 'example.com')// Has contentTypeAlis "article"url.searchParams.set('query[contentTypeAlias]', 'article')// Has parent "1023"url.searchParams.set('query[parent]', '1023')// Has a property "tag" with value "tagA"url.searchParams.set('query[properties.tag]', 'tagA')
// Only return "nodeName" and "properties.description"url.searchParams.set('include', ['nodeName', 'properties.description'].join('|'))
// Limit to 10 itemsurl.searchParams.set('limit', '10')
const request = new Request(url)
const docs = await fetch(request).then(res => res.json())