Language

Create spreadsheets & documents with Kotlin

Create a shareable spreadsheet from Kotlin using OkHttp — the standard HTTP client on Android and the JVM. Send your rows as JSON and read back a URL. Works in Android apps (via a backend proxy), Ktor servers, and plain Kotlin scripts.

Kotlin (OkHttp)
val json = """
{
  "title": "Q3 Revenue",
  "sheets": [{ "rows": [
    ["Month", "Revenue", "Growth"],
    ["July", 48200, "+12%"]
  ] }]
}
""".trimIndent()

val req = Request.Builder()
    .url("https://openofficeai.com/api/v1/sheets")
    .addHeader("Authorization", "Bearer YOUR_API_KEY")
    .post(json.toRequestBody("application/json".toMediaType()))
    .build()

OkHttpClient().newCall(req).execute().use { res ->
    println(res.body!!.string()) // contains the "url"
}

How to create a spreadsheet with Kotlin

  1. 1Add the OkHttp dependency.
  2. 2Build a Request with the Bearer header and a JSON request body.
  3. 3Execute the call and read the response string.
  4. 4Parse it (kotlinx.serialization / Moshi) to get the url.

Why use OpenOfficeAI with Kotlin

Frequently asked questions

Should I call this from Android directly?

Proxy it through your backend so the API key never ships in the APK. The app calls your server, which calls OpenOfficeAI with the key from a secure store.

Can I use Ktor client instead of OkHttp?

Yes. Ktor's HttpClient with the ContentNegotiation plugin works the same way: client.post(url) { bearerAuth(key); setBody(...) }, then read the url from the response.

How do I parse the JSON response cleanly?

Define a @Serializable data class with a url field and decode with kotlinx.serialization, or use Moshi. Both map the response in one line.

Start creating documents with Kotlin

Free tier includes 500 API calls per month — no card required.

Related integrations