fixed API
This commit is contained in:
1 parent
af0d8b77a5
commit
6dba8aaa2e
6 files changed
+45
-20
No files matched your search
+17
-10
@@ -1,21 +1,22 @@
|
||||
### Get Spaces
|
||||
GET http://localhost:31009/v1/spaces
|
||||
Authorization: Bearer {{apiKey}}
|
||||
Anytype-Version: {{apiVersion}}
|
||||
|
||||
### Get Types
|
||||
GET http://localhost:31009/v1/spaces/{{spaceId}}/types
|
||||
Authorization: Bearer {{apiKey}}
|
||||
Anytype-Version: 0.1
|
||||
Anytype-Version: {{apiVersion}}
|
||||
|
||||
### Get Type
|
||||
GET http://localhost:31009/v1/spaces/{{spaceId}}/types/{{taskTypeId}}
|
||||
Authorization: Bearer {{apiKey}}
|
||||
Anytype-Version: 0.1
|
||||
Anytype-Version: {{apiVersion}}
|
||||
|
||||
### Get objects of type
|
||||
POST http://localhost:31009/v1/spaces/{{spaceId}}/search?type=project
|
||||
Authorization: Bearer {{apiKey}}
|
||||
Anytype-Version: 0.1
|
||||
Anytype-Version: {{apiVersion}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
@@ -23,23 +24,29 @@ Content-Type: application/json
|
||||
}
|
||||
|
||||
### Get Property
|
||||
GET http://localhost:31009/v1/spaces/{{spaceId}}/properties/{{priorityPropertyId}}
|
||||
Authorization: Bearer {{apiKey}}
|
||||
Anytype-Version: 0.1
|
||||
|
||||
### Get Property Tags
|
||||
GET http://localhost:31009/v1/spaces/{{spaceId}}/properties/{{priorityPropertyId}}/tags
|
||||
Authorization: Bearer {{apiKey}}
|
||||
Anytype-Version: 0.1
|
||||
Anytype-Version: {{apiVersion}}
|
||||
|
||||
### Get Property Values Priority
|
||||
GET http://localhost:31009/v1/spaces/{{spaceId}}/properties/{{priorityPropertyId}}/tags
|
||||
Authorization: Bearer {{apiKey}}
|
||||
Anytype-Version: {{apiVersion}}
|
||||
|
||||
### Get Property Values Project
|
||||
GET http://localhost:31009/v1/spaces/{{spaceId}}/properties/{{projectPropertyId}}/tags
|
||||
Authorization: Bearer {{apiKey}}
|
||||
Anytype-Version: {{apiVersion}}
|
||||
|
||||
### Get Templates
|
||||
GET http://localhost:31009/v1/spaces/{{spaceId}}/types/{{taskTypeId}}/templates
|
||||
Authorization: Bearer {{apiKey}}
|
||||
Anytype-Version: 0.1
|
||||
Anytype-Version: {{apiVersion}}
|
||||
|
||||
### Create Task
|
||||
POST http://localhost:31009/v1/spaces/{{spaceId}}/objects
|
||||
Authorization: Bearer {{apiKey}}
|
||||
Anytype-Version: {{apiVersion}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"local": {
|
||||
"apiKey": "<API-Key>",
|
||||
"apiVersion": "2025-11-08",
|
||||
"spaceId": "<Space-Id>",
|
||||
"taskTypeId": "<taskTypeId>",
|
||||
"priorityPropertyId": "<priorityPropertyId>"
|
||||
|
||||
@@ -6,6 +6,7 @@ import io.ktor.client.call.*
|
||||
import io.ktor.client.engine.cio.*
|
||||
import io.ktor.client.plugins.*
|
||||
import io.ktor.client.plugins.contentnegotiation.*
|
||||
import io.ktor.client.plugins.defaultRequest
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.statement.*
|
||||
import io.ktor.http.*
|
||||
@@ -32,7 +33,10 @@ class AnyTypeApi(
|
||||
|
||||
private val http = HttpClient(CIO) {
|
||||
install(ContentNegotiation) {
|
||||
json(Json { ignoreUnknownKeys = true })
|
||||
json(Json { ignoreUnknownKeys = true; explicitNulls = false })
|
||||
}
|
||||
defaultRequest {
|
||||
header("Anytype-Version", "2025-11-08")
|
||||
}
|
||||
}.also { client ->
|
||||
client.plugin(HttpSend).intercept { request ->
|
||||
@@ -62,7 +66,6 @@ class AnyTypeApi(
|
||||
suspend fun getSpaces(): Result<List<Space>> =
|
||||
runCatching {
|
||||
val response = http.get("$baseUrl/v1/spaces") {
|
||||
header("Anytype-Version", "0.1")
|
||||
bearerAuth(apiKey)
|
||||
}
|
||||
response.body<SpacesResponse>().data
|
||||
@@ -71,7 +74,6 @@ class AnyTypeApi(
|
||||
suspend fun getTypes(): Result<List<ObjectType>> =
|
||||
runCatching {
|
||||
val response = http.get("$baseUrl/v1/spaces/$spaceId/types") {
|
||||
header("Anytype-Version", "0.1")
|
||||
bearerAuth(apiKey)
|
||||
}
|
||||
response.body<TypesResponse>().data
|
||||
@@ -81,7 +83,6 @@ class AnyTypeApi(
|
||||
runCatching {
|
||||
val response = http.post("$baseUrl/v1/spaces/$spaceId/search") {
|
||||
contentType(ContentType.Application.Json)
|
||||
header("Anytype-Version", "0.1")
|
||||
bearerAuth(apiKey)
|
||||
setBody(mapOf("types" to listOf(typeKey)))
|
||||
}
|
||||
@@ -91,7 +92,6 @@ class AnyTypeApi(
|
||||
suspend fun getTags(propertyId: String): Result<List<Tag>> =
|
||||
runCatching {
|
||||
val response = http.get("$baseUrl/v1/spaces/$spaceId/properties/$propertyId/tags") {
|
||||
header("Anytype-Version", "2025-11-08")
|
||||
bearerAuth(apiKey)
|
||||
}
|
||||
response.body<TagsResponse>().data
|
||||
@@ -100,7 +100,6 @@ class AnyTypeApi(
|
||||
suspend fun getTemplates(typeId: String): Result<List<Template>> =
|
||||
runCatching {
|
||||
val response = http.get("$baseUrl/v1/spaces/$spaceId/types/$typeId/templates") {
|
||||
header("Anytype-Version", "0.1")
|
||||
bearerAuth(apiKey)
|
||||
}
|
||||
response.body<TemplatesResponse>().data
|
||||
@@ -108,7 +107,7 @@ class AnyTypeApi(
|
||||
|
||||
suspend fun createObject(
|
||||
title: String,
|
||||
details: String = "",
|
||||
details: String? = null,
|
||||
typeKey: String,
|
||||
templateId: String? = null,
|
||||
properties: List<JsonElement> = emptyList(),
|
||||
@@ -116,12 +115,11 @@ class AnyTypeApi(
|
||||
runCatching {
|
||||
val response = http.post("$baseUrl/v1/spaces/$spaceId/objects") {
|
||||
contentType(ContentType.Application.Json)
|
||||
header("Anytype-Version", "0.1")
|
||||
bearerAuth(apiKey)
|
||||
setBody(
|
||||
CreateObjectRequest(
|
||||
name = title,
|
||||
body = details,
|
||||
body = details?.takeIf { it.isNotBlank() },
|
||||
typeKey = typeKey,
|
||||
templateId = templateId,
|
||||
properties = properties,
|
||||
|
||||
@@ -7,7 +7,7 @@ import kotlinx.serialization.json.JsonElement
|
||||
@Serializable
|
||||
data class CreateObjectRequest(
|
||||
val name: String,
|
||||
val body: String,
|
||||
val body: String? = null,
|
||||
@SerialName("type_key") val typeKey: String,
|
||||
@SerialName("template_id") val templateId: String? = null,
|
||||
val properties: List<JsonElement> = emptyList(),
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package ch.ergon.anytask.api.dto
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class Tag(
|
||||
val id: String,
|
||||
val key: String = "",
|
||||
val name: String,
|
||||
val color: String = "",
|
||||
)
|
||||
@@ -0,0 +1,8 @@
|
||||
package ch.ergon.anytask.api.dto
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class TagsResponse(
|
||||
val data: List<Tag>,
|
||||
)
|
||||