fixed API

This commit is contained in:
boxi committed 2026-05-15 20:45:58 +02:00
1 parent af0d8b77a5
commit 6dba8aaa2e
6 files changed
+45 -20

No files matched your search

+17 -10
View File
@@ -1,21 +1,22 @@
### Get Spaces ### Get Spaces
GET http://localhost:31009/v1/spaces GET http://localhost:31009/v1/spaces
Authorization: Bearer {{apiKey}} Authorization: Bearer {{apiKey}}
Anytype-Version: {{apiVersion}}
### Get Types ### Get Types
GET http://localhost:31009/v1/spaces/{{spaceId}}/types GET http://localhost:31009/v1/spaces/{{spaceId}}/types
Authorization: Bearer {{apiKey}} Authorization: Bearer {{apiKey}}
Anytype-Version: 0.1 Anytype-Version: {{apiVersion}}
### Get Type ### Get Type
GET http://localhost:31009/v1/spaces/{{spaceId}}/types/{{taskTypeId}} GET http://localhost:31009/v1/spaces/{{spaceId}}/types/{{taskTypeId}}
Authorization: Bearer {{apiKey}} Authorization: Bearer {{apiKey}}
Anytype-Version: 0.1 Anytype-Version: {{apiVersion}}
### Get objects of type ### Get objects of type
POST http://localhost:31009/v1/spaces/{{spaceId}}/search?type=project POST http://localhost:31009/v1/spaces/{{spaceId}}/search?type=project
Authorization: Bearer {{apiKey}} Authorization: Bearer {{apiKey}}
Anytype-Version: 0.1 Anytype-Version: {{apiVersion}}
Content-Type: application/json Content-Type: application/json
{ {
@@ -23,23 +24,29 @@ Content-Type: application/json
} }
### Get Property ### 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 GET http://localhost:31009/v1/spaces/{{spaceId}}/properties/{{priorityPropertyId}}/tags
Authorization: Bearer {{apiKey}} 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 Templates
GET http://localhost:31009/v1/spaces/{{spaceId}}/types/{{taskTypeId}}/templates GET http://localhost:31009/v1/spaces/{{spaceId}}/types/{{taskTypeId}}/templates
Authorization: Bearer {{apiKey}} Authorization: Bearer {{apiKey}}
Anytype-Version: 0.1 Anytype-Version: {{apiVersion}}
### Create Task ### Create Task
POST http://localhost:31009/v1/spaces/{{spaceId}}/objects POST http://localhost:31009/v1/spaces/{{spaceId}}/objects
Authorization: Bearer {{apiKey}} Authorization: Bearer {{apiKey}}
Anytype-Version: {{apiVersion}}
Content-Type: application/json Content-Type: application/json
{ {
@@ -1,6 +1,7 @@
{ {
"local": { "local": {
"apiKey": "<API-Key>", "apiKey": "<API-Key>",
"apiVersion": "2025-11-08",
"spaceId": "<Space-Id>", "spaceId": "<Space-Id>",
"taskTypeId": "<taskTypeId>", "taskTypeId": "<taskTypeId>",
"priorityPropertyId": "<priorityPropertyId>" "priorityPropertyId": "<priorityPropertyId>"
@@ -6,6 +6,7 @@ import io.ktor.client.call.*
import io.ktor.client.engine.cio.* import io.ktor.client.engine.cio.*
import io.ktor.client.plugins.* import io.ktor.client.plugins.*
import io.ktor.client.plugins.contentnegotiation.* import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.plugins.defaultRequest
import io.ktor.client.request.* import io.ktor.client.request.*
import io.ktor.client.statement.* import io.ktor.client.statement.*
import io.ktor.http.* import io.ktor.http.*
@@ -32,7 +33,10 @@ class AnyTypeApi(
private val http = HttpClient(CIO) { private val http = HttpClient(CIO) {
install(ContentNegotiation) { install(ContentNegotiation) {
json(Json { ignoreUnknownKeys = true }) json(Json { ignoreUnknownKeys = true; explicitNulls = false })
}
defaultRequest {
header("Anytype-Version", "2025-11-08")
} }
}.also { client -> }.also { client ->
client.plugin(HttpSend).intercept { request -> client.plugin(HttpSend).intercept { request ->
@@ -62,7 +66,6 @@ class AnyTypeApi(
suspend fun getSpaces(): Result<List<Space>> = suspend fun getSpaces(): Result<List<Space>> =
runCatching { runCatching {
val response = http.get("$baseUrl/v1/spaces") { val response = http.get("$baseUrl/v1/spaces") {
header("Anytype-Version", "0.1")
bearerAuth(apiKey) bearerAuth(apiKey)
} }
response.body<SpacesResponse>().data response.body<SpacesResponse>().data
@@ -71,7 +74,6 @@ class AnyTypeApi(
suspend fun getTypes(): Result<List<ObjectType>> = suspend fun getTypes(): Result<List<ObjectType>> =
runCatching { runCatching {
val response = http.get("$baseUrl/v1/spaces/$spaceId/types") { val response = http.get("$baseUrl/v1/spaces/$spaceId/types") {
header("Anytype-Version", "0.1")
bearerAuth(apiKey) bearerAuth(apiKey)
} }
response.body<TypesResponse>().data response.body<TypesResponse>().data
@@ -81,7 +83,6 @@ class AnyTypeApi(
runCatching { runCatching {
val response = http.post("$baseUrl/v1/spaces/$spaceId/search") { val response = http.post("$baseUrl/v1/spaces/$spaceId/search") {
contentType(ContentType.Application.Json) contentType(ContentType.Application.Json)
header("Anytype-Version", "0.1")
bearerAuth(apiKey) bearerAuth(apiKey)
setBody(mapOf("types" to listOf(typeKey))) setBody(mapOf("types" to listOf(typeKey)))
} }
@@ -91,7 +92,6 @@ class AnyTypeApi(
suspend fun getTags(propertyId: String): Result<List<Tag>> = suspend fun getTags(propertyId: String): Result<List<Tag>> =
runCatching { runCatching {
val response = http.get("$baseUrl/v1/spaces/$spaceId/properties/$propertyId/tags") { val response = http.get("$baseUrl/v1/spaces/$spaceId/properties/$propertyId/tags") {
header("Anytype-Version", "2025-11-08")
bearerAuth(apiKey) bearerAuth(apiKey)
} }
response.body<TagsResponse>().data response.body<TagsResponse>().data
@@ -100,7 +100,6 @@ class AnyTypeApi(
suspend fun getTemplates(typeId: String): Result<List<Template>> = suspend fun getTemplates(typeId: String): Result<List<Template>> =
runCatching { runCatching {
val response = http.get("$baseUrl/v1/spaces/$spaceId/types/$typeId/templates") { val response = http.get("$baseUrl/v1/spaces/$spaceId/types/$typeId/templates") {
header("Anytype-Version", "0.1")
bearerAuth(apiKey) bearerAuth(apiKey)
} }
response.body<TemplatesResponse>().data response.body<TemplatesResponse>().data
@@ -108,7 +107,7 @@ class AnyTypeApi(
suspend fun createObject( suspend fun createObject(
title: String, title: String,
details: String = "", details: String? = null,
typeKey: String, typeKey: String,
templateId: String? = null, templateId: String? = null,
properties: List<JsonElement> = emptyList(), properties: List<JsonElement> = emptyList(),
@@ -116,12 +115,11 @@ class AnyTypeApi(
runCatching { runCatching {
val response = http.post("$baseUrl/v1/spaces/$spaceId/objects") { val response = http.post("$baseUrl/v1/spaces/$spaceId/objects") {
contentType(ContentType.Application.Json) contentType(ContentType.Application.Json)
header("Anytype-Version", "0.1")
bearerAuth(apiKey) bearerAuth(apiKey)
setBody( setBody(
CreateObjectRequest( CreateObjectRequest(
name = title, name = title,
body = details, body = details?.takeIf { it.isNotBlank() },
typeKey = typeKey, typeKey = typeKey,
templateId = templateId, templateId = templateId,
properties = properties, properties = properties,
@@ -7,7 +7,7 @@ import kotlinx.serialization.json.JsonElement
@Serializable @Serializable
data class CreateObjectRequest( data class CreateObjectRequest(
val name: String, val name: String,
val body: String, val body: String? = null,
@SerialName("type_key") val typeKey: String, @SerialName("type_key") val typeKey: String,
@SerialName("template_id") val templateId: String? = null, @SerialName("template_id") val templateId: String? = null,
val properties: List<JsonElement> = emptyList(), 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>,
)
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.