> ## 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 and JVM apps, with support for pages, collections, blog posts, and feeds.

## Installation

### Gradle

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

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

Or in `build.gradle`:

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

### Maven

```xml theme={null}
<dependency>
    <groupId>com.buttercms</groupId>
    <artifactId>buttercmsclient</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.ButterCMSClient

val butter = ButterCMSClient("your_api_token")
```

## API methods

### Pages

```kotlin theme={null}
// Retrieve a single page
val page = butter.getPage(
    pageType = "landing_page",
    pageSlug = "home-page",
    params = mapOf("locale" to "en", "levels" to "2")
)
println(page)

// List all pages of a type
val pages = butter.listPages(
    pageType = "landing_page",
    params = mapOf("page" to "1", "page_size" to "10")
)
println(pages)
```

### Collections

```kotlin theme={null}
// Retrieve collection content
val content = butter.getContentFields(
    keys = listOf("faq", "navigation"),
    params = mapOf("locale" to "en")
)
println(content)
```

### Blog Posts

```kotlin theme={null}
// List blog posts
val posts = butter.listPosts(
    params = mapOf("page" to "1", "page_size" to "10", "exclude_body" to "true")
)

// Retrieve a single post
val post = butter.getPost(slug = "my-post-slug")
println(post)

// Search posts
val results = butter.searchPosts(
    query = "search term",
    params = mapOf("page" to "1", "page_size" to "10")
)
```

### Authors

```kotlin theme={null}
// List all authors
val authors = butter.listAuthors(
    params = mapOf("include" to "recent_posts")
)

// Retrieve a single author
val author = butter.getAuthor(
    slug = "jennifer-smith",
    params = mapOf("include" to "recent_posts")
)
```

### Categories

```kotlin theme={null}
// List all categories
val categories = butter.listCategories(
    params = mapOf("include" to "recent_posts")
)

// Retrieve a single category
val category = butter.getCategory(
    slug = "news",
    params = mapOf("include" to "recent_posts")
)
```

### Tags

```kotlin theme={null}
// List all tags
val tags = butter.listTags(
    params = mapOf("include" to "recent_posts")
)
```

### Feeds

```kotlin theme={null}
// Get RSS feed
val rss = butter.getFeed(feedType = "rss")

// Get Atom feed
val atom = butter.getFeed(feedType = "atom")

// Get Sitemap
val sitemap = butter.getFeed(feedType = "sitemap")
```

## Resources

<CardGroup cols={2}>
  <Card title="GitHub Repository" icon="github" href="https://github.com/ButterCMS/buttercms-kotlin">
    View source code, report issues, and contribute
  </Card>

  <Card title="Maven Central" icon="box" href="https://central.sonatype.com/artifact/com.buttercms/buttercmsclient">
    Package details and version history
  </Card>
</CardGroup>
