Skip to main content

Installation

Gradle

Add the dependency to your build.gradle.kts:
dependencies {
    implementation("com.buttercms:buttercmsclient:1.0.0")
}
Or in build.gradle:
dependencies {
    implementation 'com.buttercms:buttercmsclient:1.0.0'
}

Maven

<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.
import com.buttercms.ButterCMSClient

val butter = ButterCMSClient("your_api_token")

API methods

Pages

// 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

// Retrieve collection content
val content = butter.getContentFields(
    keys = listOf("faq", "navigation"),
    params = mapOf("locale" to "en")
)
println(content)

Blog Posts

// 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

// 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

// 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

// List all tags
val tags = butter.listTags(
    params = mapOf("include" to "recent_posts")
)

Feeds

// 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

GitHub Repository

View source code, report issues, and contribute

Maven Central

Package details and version history