← Back to API Docs

LoginWA Android SDK (Kotlin)

Lightweight REST client to start and verify OTP over WhatsApp.

Repo: GitHub · Module: sdk/android · Sample: sdk/android/sample

Install (planned Maven Central)

Add the dependency:

dependencies {
    implementation("com.loginwa:loginwa-otp:0.1.0")
}

Until published, import the sdk/android project as a module or publish to Maven Local.

Initialize

val client = LoginWAClient(
    apiKey = BuildConfig.LOGINWA_API_KEY,
    baseUrl = "https://api.loginwa.com/api/v1", // optional override
    enableLogging = true
)

Start OTP

val start = client.startOtp(
    StartOtpRequest(
        phone = "6281234567890",
        countryCode = "62",
        otpLength = 6,
        messageTemplate = "OTP code {code} valid for {ttl} minutes",
        meta = mapOf("user_id" to "123")
    )
)
val sessionId = start.sessionId

Verify OTP

val verify = client.verifyOtp(
    VerifyOtpRequest(
        sessionId = sessionId.orEmpty(),
        otpCode = "123456"
    )
)
if (verify.status == "verified") {
    // success
}

Errors

  • HttpError(status, code, rawBody) for non-2xx responses.
  • NetworkError for connectivity/timeouts.
  • SerializationError for invalid/unexpected JSON.

Notes

  • Keep the API key out of source control (use BuildConfig/gradle properties or secure storage).
  • Default base URL: https://api.loginwa.com/api/v1.
  • Logging is BASIC (no body) when enableLogging=true.

Sample app

  • Location: sdk/android/sample (Activity with phone/session/OTP form.)
  • Set LOGINWA_API_KEY in ~/.gradle/gradle.properties, open the project in Android Studio, run module :sample.