Skip to content

Share API

The umami-kotlin library provides a Share API for managing public share pages within your Umami instance.

New to Umami Kotlin?

Before using the Share API, ensure you have initialized the UmamiApi client. Refer to our getting started guides for Kotlin Multiplatform and Android for setup instructions.

All functions within the Share API are suspend functions, meaning they must be called from within a coroutine or another suspend function.

Obtaining a Share Instance

You can access the Share API functionalities through an extension function on your UmamiApi client instance:

// Assuming 'api' is an initialized UmamiApi client
val shareApi = api.share()

Retrieving Shares for a Website

The getWebsiteShares function returns a paginated list of share pages that belong to a website.

suspend fun getWebsiteShares(
    websiteId: String,
    search: String? = null,
    page: Int? = null,
    pageSize: Int? = null,
): SearchResponse<SharePage>
val shares = shareApi.getWebsiteShares(
    websiteId = "website-id",
    search = "dashboard",
    page = 1,
    pageSize = 10,
)
shares.data.forEach { share ->
    println("${share.name}: /share/${share.slug}")
}

Creating a Share for a Website

The createWebsiteShare function creates a share page for a website.

suspend fun createWebsiteShare(
    websiteId: String,
    name: String,
    parameters: ShareParameters = ShareParameters(),
): SharePage
val share = shareApi.createWebsiteShare(
    websiteId = "website-id",
    name = "Public dashboard",
    parameters = ShareParameters(
        allowFilter = true,
        theme = ShareTheme.DARK,
        overview = true,
        events = true,
    ),
)

Creating a Share for Any Entity

The createShare function creates a share page for a website, link, pixel or board.

suspend fun createShare(
    entityId: String,
    shareType: Int,
    name: String,
    slug: String? = null,
    parameters: ShareParameters = ShareParameters(),
): SharePage

shareType accepts 1 for websites, 2 for links, 3 for pixels and 4 for boards. When slug is omitted, Umami generates a random one.

val share = shareApi.createShare(
    entityId = "website-id",
    shareType = 1,
    name = "Public dashboard",
    slug = "public-dashboard",
)

Retrieving a Share

The getShare function returns the details of a share page by its ID.

suspend fun getShare(shareId: String): SharePage
val share = shareApi.getShare("share-id")

Updating a Share

The updateShare function updates the details of an existing share page.

suspend fun updateShare(
    shareId: String,
    name: String,
    slug: String,
    parameters: ShareParameters = ShareParameters(),
): SharePage
val share = shareApi.updateShare(
    shareId = "share-id",
    name = "Updated dashboard",
    slug = "updated-dashboard",
    parameters = ShareParameters(allowFilter = false),
)

Deleting a Share

The deleteShare function deletes a share page.

suspend fun deleteShare(shareId: String)
shareApi.deleteShare("share-id")