useCwaResourceEndpoint
useCwaResourceEndpoint gives you the API URL for a resource, with the ?published= query the current admin view needs.
import { useCwaResourceEndpoint } from '#imports'
const { endpoint, query } = useCwaResourceEndpoint(iri)
// endpoint.value → '/component/titles/018e-…?published=true'
// query.value → '?published=true' (or '')
It returns an object, not a bare ref. Use it when you need to make manual API requests that respect the current publish state — for example fetching additional data for a resource that isn't automatically loaded by the resource store.
Signature
useCwaResourceEndpoint(iri: Ref<string | undefined>, postfix?: string)
Parameters
| Parameter | Type | Description |
|---|---|---|
iri | Ref<string | undefined> | The resource IRI |
postfix | string? | Optional path postfix appended before the query string (e.g. '/upload') |
Return Values
| Return | Type | Purpose |
|---|---|---|
endpoint | ComputedRef<string> | IRI + optional postfix + publish query |
query | ComputedRef<string> | Just the query string — append it to a URL you already have (this is how withFile() and useCwaFileField suffix media URLs) |
The Publish Query
A published flag is only added when the resource is publishable and the loaded version is the published one:
?published=truewhen the admin is not editing, or when the admin has forced the live version via the Publish tab's preview toggle (forcePublishedVersion)?published=falsewhen editing with that toggle explicitly set to the draft
Everything else — a non-publishable resource, or a draft while editing — gets the bare IRI.
Example
const props = defineProps<IriProp>()
const { endpoint } = useCwaResourceEndpoint(toRef(props, 'iri'))
const { data } = await useFetch(endpoint)
Used internally by withFile() and useCwaFileField (to suffix media URLs), useCwaResourceModel (the PATCH target) and useCwaResourceUpload (the upload and delete targets). Reach for it directly only when you are making your own API calls for a resource and need them to respect the current publish state.