Skip to content

useCollectionApi Composable ​

File Information ​

  • Path: app/composables/api/useCollectionApi.ts
  • Purpose: Collection/collage operations API
  • Category: Content API Composable

Overview ​

The useCollectionApi composable provides functionality for fetching collections (collages) and their associated assets.

Functions ​

getCollections ​

Fetches all collections for a workspace.

Signature:

typescript
getCollections(workspace: string): Promise<any>

Parameters:

  • workspace: string - Workspace ID/URL

Returns:

  • Promise<any> - Collections response

API Endpoint: GET /digital/collection/get-all?url_workspace_id={workspace}

Usage:

typescript
const { getCollections } = useCollectionApi()

const collections = await getCollections(workspaceId)
// collections contains array of collections

getCollageDetails ​

Fetches detailed information about a specific collection/collage including its assets.

Signature:

typescript
getCollageDetails(
  collectionId: string,
  body: any
): Promise<any>

Parameters:

  • collectionId: string - Collection ID
  • body: any - Query parameters (page, per_page, filters, etc.)

Returns:

  • Promise<any> - Collection details with assets

API Endpoint: GET /digital/collection/{collectionId}/assets?{queryString}

Usage:

typescript
const { getCollageDetails } = useCollectionApi()
const { toQueryString } = useHelpers()

const details = await getCollageDetails(collectionId, {
  page: 1,
  per_page: 20,
  filter_by: 'file_type:image'
})
// details contains collection info and assets

Error Handling ​

All functions include error logging:

typescript
catch (error: any) {
  console.error("[CollectionAPI] {functionName} - Error:", error)
  throw error
}

Integration with API Client ​

The composable uses the global $api client:

typescript
const { $api } = useNuxtApp()
const { toQueryString } = useHelpers()

Use Cases ​

List Collections ​

typescript
const { getCollections } = useCollectionApi()

const loadCollections = async () => {
  try {
    const collections = await getCollections(workspaceId)
    // Display collections...
  } catch (error) {
    console.error('Failed to load collections:', error)
  }
}

View Collection Details ​

typescript
const { getCollageDetails } = useCollectionApi()

const loadCollectionAssets = async (collectionId: string, page: number = 1) => {
  try {
    const details = await getCollageDetails(collectionId, {
      page,
      per_page: 20
    })
    // Display collection assets...
  } catch (error) {
    console.error('Failed to load collection:', error)
  }
}