> ## Documentation Index
> Fetch the complete documentation index at: https://buttercms.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Kotlin SDK

> The ButterCMS Kotlin SDK provides a native Kotlin interface for Android apps, with support for pages, collections, blog posts, and the rest of the Read API.

> [!NOTE]
>
> This SDK is an Android library (published as an AAR with Android Gradle plugin and AndroidX dependencies, minSdkVersion 24). It isn't usable in a plain, non-Android JVM application.

## Installation

### Gradle

Add the dependency to your `build.gradle.kts`:

```kotlin theme={null}
dependencies {
    implementation("com.buttercms.android:buttercmsclient-kotlin:1.0.0")
}
```

Or in `build.gradle`:

```groovy theme={null}
dependencies {
    implementation 'com.buttercms.android:buttercmsclient-kotlin:1.0.0'
}
```

### Maven

```xml theme={null}
<dependency>
    <groupId>com.buttercms.android</groupId>
    <artifactId>buttercmsclient-kotlin</artifactId>
    <version>1.0.0</version>
</dependency>
```

## Initialization

Initialize the SDK with your Read API token from the [ButterCMS Settings](https://buttercms.com/settings/).

```kotlin theme={null}
import com.buttercms.ButterCMS

val client = ButterCMS("your_api_token")
```

## API methods

All API calls are made through `client.data`, are asynchronous, and take a `Callback` parameter that receives the result when the call finishes.

### Pages

```kotlin theme={null}
import com.buttercms.error.Callback
import com.buttercms.error.RestCallError
import com.buttercms.getPage
import com.buttercms.getPages
import com.buttercms.model.Page
import com.buttercms.model.Pages

// Retrieve a single page
client.data.getPage(
    "landing_page",
    "home-page",
    mapOf("locale" to "en", "levels" to "2"),
    Map::class.java,
    callback = object : Callback<Page, RestCallError> {
        override fun success(response: Page) {
            println(response)
        }
        override fun failure(error: RestCallError) {
            println(error.errorMessage)
        }
    }
)

// List all pages of a type
client.data.getPages(
    "landing_page",
    mapOf("page" to "1", "page_size" to "10"),
    Map::class.java,
    callback = object : Callback<Pages, RestCallError> {
        override fun success(response: Pages) {
            println(response)
        }
        override fun failure(error: RestCallError) {
            println(error.errorMessage)
        }
    }
)
```

### Collections

```kotlin theme={null}
import com.buttercms.getCollection
import com.buttercms.model.Collections

// Retrieve collection content (one collection slug per call)
client.data.getCollection(
    "faq",
    mapOf("locale" to "en"),
    Map::class.java,
    callback = object : Callback<Collections, RestCallError> {
        override fun success(response: Collections) {
            println(response)
        }
        override fun failure(error: RestCallError) {
            println(error.errorMessage)
        }
    }
)
```

### Blog Posts

```kotlin theme={null}
import com.buttercms.getPost
import com.buttercms.getPosts
import com.buttercms.model.Post
import com.buttercms.model.Posts
import com.buttercms.searchPosts

// List blog posts
client.data.getPosts(
    mapOf("page" to "1", "page_size" to "10", "exclude_body" to "true"),
    callback = object : Callback<Posts, RestCallError> {
        override fun success(response: Posts) { println(response) }
        override fun failure(error: RestCallError) { println(error.errorMessage) }
    }
)

// Retrieve a single post
client.data.getPost(
    "my-post-slug",
    callback = object : Callback<Post, RestCallError> {
        override fun success(response: Post) { println(response) }
        override fun failure(error: RestCallError) { println(error.errorMessage) }
    }
)

// Search posts
client.data.searchPosts(
    "search term",
    mapOf("page" to "1", "page_size" to "10"),
    callback = object : Callback<Posts, RestCallError> {
        override fun success(response: Posts) { println(response) }
        override fun failure(error: RestCallError) { println(error.errorMessage) }
    }
)
```

### Authors

```kotlin theme={null}
import com.buttercms.getAuthor
import com.buttercms.getAuthors
import com.buttercms.model.Author
import com.buttercms.model.Authors

// List all authors
client.data.getAuthors(
    mapOf("include" to "recent_posts"),
    callback = object : Callback<Authors, RestCallError> {
        override fun success(response: Authors) { println(response) }
        override fun failure(error: RestCallError) { println(error.errorMessage) }
    }
)

// Retrieve a single author
client.data.getAuthor(
    "jennifer-smith",
    mapOf("include" to "recent_posts"),
    callback = object : Callback<Author, RestCallError> {
        override fun success(response: Author) { println(response) }
        override fun failure(error: RestCallError) { println(error.errorMessage) }
    }
)
```

### Categories

```kotlin theme={null}
import com.buttercms.getCategories
import com.buttercms.getCategory
import com.buttercms.model.Categories
import com.buttercms.model.Category

// List all categories
client.data.getCategories(
    mapOf("include" to "recent_posts"),
    callback = object : Callback<Categories, RestCallError> {
        override fun success(response: Categories) { println(response) }
        override fun failure(error: RestCallError) { println(error.errorMessage) }
    }
)

// Retrieve a single category
client.data.getCategory(
    "news",
    mapOf("include" to "recent_posts"),
    callback = object : Callback<Category, RestCallError> {
        override fun success(response: Category) { println(response) }
        override fun failure(error: RestCallError) { println(error.errorMessage) }
    }
)
```

### Tags

```kotlin theme={null}
import com.buttercms.getTags
import com.buttercms.model.Tags

// List all tags
client.data.getTags(
    mapOf("include" to "recent_posts"),
    callback = object : Callback<Tags, RestCallError> {
        override fun success(response: Tags) { println(response) }
        override fun failure(error: RestCallError) { println(error.errorMessage) }
    }
)
```

## Resources

> [card] [GitHub Repository](https://github.com/ButterCMS/buttercms-kotlin)
>
> View source code, report issues, and contribute

> [card] [Maven Central](https://central.sonatype.com/artifact/com.buttercms.android/buttercmsclient-kotlin)
>
> Package details and version history


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.