Skip to content

Kotlin SDK

Install tiktok-shop-api-kotlin, the typed TikTok Shop API client for Kotlin on the JVM, and make your first call.

tiktok-shop-api-kotlin is a typed Kotlin client for the TikTok Shop Partner API. It signs requests, handles OAuth, works with many shops at once, and verifies and types webhooks as a sealed class. It is published to Maven Central, and its source is in kotlin/.

Gradle (Kotlin DSL):

dependencies {
implementation("com.isaackogan:tiktok-shop-api-kotlin:0.1.0")
}

Maven:

<dependency>
<groupId>com.isaackogan</groupId>
<artifactId>tiktok-shop-api-kotlin</artifactId>
<version>0.1.0</version>
</dependency>

Needs JVM 11 or newer. The runtime dependencies are OkHttp and gson.

With an access token from the OAuth helper, create a client and call an operation:

import com.isaackogan.tiktok.shop.TikTokShop
import com.isaackogan.tiktok.shop.TikTokShopException
import com.isaackogan.tiktok.shop.TikTokShopOptions
class FirstCall {
fun run() {
val client = TikTokShop(
TikTokShopOptions(appKey = "YOUR_APP_KEY", appSecret = "YOUR_APP_SECRET", accessToken = "ACCESS_TOKEN"),
)
try {
val shops = client.authorization.getAuthorizedShops()
println(shops.data?.shops?.firstOrNull()?.cipher)
} catch (e: TikTokShopException) {
println("TikTok said ${e.code}: ${e.message} (request ${e.requestId})")
}
}
}

Pass shopCipher = "..." in the options and every operation that needs one gets it. Every call is signed, timestamped and sent with your access token.

  • Authorization: TikTokShopAuth, authorization URLs, token exchange and refresh.
  • Calling the API: the client, API areas, many shops and options.
  • Webhooks: Webhooks.verifyAndParse and the WebhookEvent sealed class.
  • Errors: TikTokShopException and its codes.