
Type-safe library interfaces with Notion API, enabling seamless integration for applications. Features include coroutine support, JSON serialization, block and database operations, and advanced search capabilities.
A Kotlin Multiplatform library for interacting with the Notion API. Knotion provides a type-safe, idiomatic Kotlin interface to Notion's powerful API, making it easy to integrate Notion into your Kotlin applications.
repositories {
mavenCentral()
}
dependencies {
implementation("com.velkonost:knotion:1.0.0")
}repositories {
mavenCentral()
}
dependencies {
implementation 'com.velkonost:knotion:1.0.0'
}Create a Notion integration and get your API key:
Initialize the client:
val notionClient = KNotion.setupClient(
accessToken = "your_integration_token"
)// Create a new page
val page = notionClient.pages.createPage(
parentDatabase = DatabaseReference("database_id"),
properties = PropertyValueList().apply {
title("Name", "My New Page")
number("Price", 99.99)
select("Status", "In Progress")
multiSelect("Tags", "Important", "Urgent")
}
)
// Query a database
val database = notionClient.databases.query(
databaseId = "database_id",
filter = Filter.and(
Filter.property("Status", Filter.Select.equals("Done")),
Filter.property("Price", Filter.Number.greaterThan(50))
),
sorts = listOf(
Sort.property("Last edited time", Sort.Direction.descending)
)
)Knotion provides a rich type system for Notion's property types:
Example:
// Create a database with properties
val database = notionClient.databases.createDatabase(
parent = PageParent("page_id"),
title = "My Database",
properties = mapOf(
"Name" to TitlePropertySpec(),
"Status" to SelectPropertySpec(
options = listOf(
SelectOption("Not Started", Color.DEFAULT),
SelectOption("In Progress", Color.BLUE),
SelectOption("Done", Color.GREEN)
)
),
"Price" to NumberPropertySpec(
format = NumberFormat.DOLLAR
)
)
)Work with Notion's block-based content system:
Example:
// Create a page with blocks
val page = notionClient.blocks.createBlock(
parent = PageParent("page_id"),
blocks = listOf(
ParagraphBlock("Welcome to my page!"),
Heading1Block("Main Section"),
BulletedListItemBlock("First item"),
BulletedListItemBlock("Second item"),
CodeBlock("println('Hello, World!')", language = "kotlin")
)
)Full support for database operations:
Example:
// Query with complex filters
val results = notionClient.databases.query(
databaseId = "database_id",
filter = Filter.and(
Filter.property("Status", Filter.Select.equals("In Progress")),
Filter.or(
Filter.property("Priority", Filter.Select.equals("High")),
Filter.property("Due Date", Filter.Date.before("2024-12-31"))
)
),
sorts = listOf(
Sort.property("Created time", Sort.Direction.ascending)
),
pageSize = 100
)Powerful search capabilities:
Example:
// Search across workspace
val searchResults = notionClient.search(
query = "important project",
filter = SearchFilter(
property = "object",
value = "page"
),
sort = SearchSort(
direction = Sort.Direction.descending,
timestamp = "last_edited_time"
)
)Knotion provides comprehensive error handling:
try {
val page = notionClient.pages.retrieve("page_id")
} catch (e: NotionClientException) {
when (e) {
is NotionClientRequestException -> {
// Handle API request errors (400, 401, 403, etc.)
println("Request failed: ${e.message}")
}
is NotionClientResponseException -> {
// Handle API response errors
println("Response error: ${e.message}")
}
else -> {
// Handle other errors
println("Unexpected error: ${e.message}")
}
}
}API Key Security:
Rate Limiting:
Error Handling:
Resource Management:
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)A Kotlin Multiplatform library for interacting with the Notion API. Knotion provides a type-safe, idiomatic Kotlin interface to Notion's powerful API, making it easy to integrate Notion into your Kotlin applications.
repositories {
mavenCentral()
}
dependencies {
implementation("com.velkonost:knotion:1.0.0")
}repositories {
mavenCentral()
}
dependencies {
implementation 'com.velkonost:knotion:1.0.0'
}Create a Notion integration and get your API key:
Initialize the client:
val notionClient = KNotion.setupClient(
accessToken = "your_integration_token"
)// Create a new page
val page = notionClient.pages.createPage(
parentDatabase = DatabaseReference("database_id"),
properties = PropertyValueList().apply {
title("Name", "My New Page")
number("Price", 99.99)
select("Status", "In Progress")
multiSelect("Tags", "Important", "Urgent")
}
)
// Query a database
val database = notionClient.databases.query(
databaseId = "database_id",
filter = Filter.and(
Filter.property("Status", Filter.Select.equals("Done")),
Filter.property("Price", Filter.Number.greaterThan(50))
),
sorts = listOf(
Sort.property("Last edited time", Sort.Direction.descending)
)
)Knotion provides a rich type system for Notion's property types:
Example:
// Create a database with properties
val database = notionClient.databases.createDatabase(
parent = PageParent("page_id"),
title = "My Database",
properties = mapOf(
"Name" to TitlePropertySpec(),
"Status" to SelectPropertySpec(
options = listOf(
SelectOption("Not Started", Color.DEFAULT),
SelectOption("In Progress", Color.BLUE),
SelectOption("Done", Color.GREEN)
)
),
"Price" to NumberPropertySpec(
format = NumberFormat.DOLLAR
)
)
)Work with Notion's block-based content system:
Example:
// Create a page with blocks
val page = notionClient.blocks.createBlock(
parent = PageParent("page_id"),
blocks = listOf(
ParagraphBlock("Welcome to my page!"),
Heading1Block("Main Section"),
BulletedListItemBlock("First item"),
BulletedListItemBlock("Second item"),
CodeBlock("println('Hello, World!')", language = "kotlin")
)
)Full support for database operations:
Example:
// Query with complex filters
val results = notionClient.databases.query(
databaseId = "database_id",
filter = Filter.and(
Filter.property("Status", Filter.Select.equals("In Progress")),
Filter.or(
Filter.property("Priority", Filter.Select.equals("High")),
Filter.property("Due Date", Filter.Date.before("2024-12-31"))
)
),
sorts = listOf(
Sort.property("Created time", Sort.Direction.ascending)
),
pageSize = 100
)Powerful search capabilities:
Example:
// Search across workspace
val searchResults = notionClient.search(
query = "important project",
filter = SearchFilter(
property = "object",
value = "page"
),
sort = SearchSort(
direction = Sort.Direction.descending,
timestamp = "last_edited_time"
)
)Knotion provides comprehensive error handling:
try {
val page = notionClient.pages.retrieve("page_id")
} catch (e: NotionClientException) {
when (e) {
is NotionClientRequestException -> {
// Handle API request errors (400, 401, 403, etc.)
println("Request failed: ${e.message}")
}
is NotionClientResponseException -> {
// Handle API response errors
println("Response error: ${e.message}")
}
else -> {
// Handle other errors
println("Unexpected error: ${e.message}")
}
}
}API Key Security:
Rate Limiting:
Error Handling:
Resource Management:
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)