ROOL API docs

Android integration

How an Android build reaches the API: the base URL per build, the staging key policy, the release guard, and how to talk to the API (sign-in, tokens, lists, errors, idempotency). The iOS lines are kept where both apps share a rule.

Rendered from docs/mobile-api-connection.md at commit 8565409 (main). The schema of record is the API reference; production, staging and main differ where Versions says so.

Base URL per build type

// app/build.gradle.kts
android {
    buildFeatures { buildConfig = true }
    buildTypes {
        debug {
            buildConfigField("String", "ROOL_API_BASE_URL", "\"https://api.staging.rool.am\"")
        }
        release {
            buildConfigField("String", "ROOL_API_BASE_URL", "\"https://api.rool.am\"")
        }
    }
}

Use flavors instead if you need several debug targets (local backend on the emulator, staging). A signed build for testers is a staging variant (the staging URL and, if needed, the key), not the release build type that ships to production; release points at production and has no key (§4a).

4a. The staging key (staging builds)

api.staging.rool.am answers 404 to any request without the team key header X-Rool-Staging-Key. This section is the accepted policy for where that key may live (decided by Rudolf, recorded under ROOL-217; not up for renegotiation here).

Policy.

// Android, staging variant only: an OkHttp interceptor (the key from local or CI configuration)
class StagingKeyInterceptor(private val key: String) : Interceptor {
    override fun intercept(chain: Interceptor.Chain) = chain.proceed(
        chain.request().newBuilder().header("X-Rool-Staging-Key", key).build()
    )
}
// iOS, staging configuration only (never the production configuration)
request.setValue(stagingKey, forHTTPHeaderField: "X-Rool-Staging-Key")

The header sits alongside Authorization: Bearer <access token>; the two do not interfere.

Behaviour, verified 2026-10-06: without the header, or with a wrong one, every path answers 404 with an empty body and no content type (not problem+json), including /health/live. With the right header the API answers exactly as production does. An empty 404 means "key missing or wrong", never "resource not found". The key is not in this repository; the server admins keep it in their password manager, and a rotation makes every copy stale. Never put it in a production build, a log or a crash report.

5. Guard in both apps

At startup, in release builds only:

#if !DEBUG
precondition(baseURL.scheme == "https", "Release builds must use HTTPS")
#endif
if (!BuildConfig.DEBUG) {
    check(BuildConfig.ROOL_API_BASE_URL.startsWith("https://")) { "Release builds must use HTTPS" }
}

6. Talking to the API

Smoke test. GET {base}/health/live answers {"status":"ok"}. GET {base}/api/v1/makes answers {"data":[],"page":{...}} on the VPS today: an empty catalog is expected, not a bug. /health/ready and /internal/* are not reachable from outside.

Models. Generate them from openapi.json at a known commit of rool-backend and follow the client rules in public-api-contract.md §5: ignore unknown fields, map unknown enum values to a safe fallback, treat ids as opaque strings, branch on code and never on text. Operations marked x-implemented: false (Google sign-in, intelligence) are not served yet: build against the fixtures.

UI strings come from GET /api/v1/localization/{en|hy|ru}, public, with a strong ETag: cache each language with its ETag, revalidate with If-None-Match, keep the cache on 304 or any error, fall back to the bundled catalog. The full client contract is localization.md §3.

Lists use { "data": [...], "page": { "nextCursor": ..., "hasMore": ... } }. Fetch the next page with ?cursor=<nextCursor>, optionally &limit= (1–100).

Errors are application/problem+json. Show title or your own text, branch on code, log requestId. 5xx responses carry no detail.

Creates that declare Idempotency-Key (vehicles, odometer readings, service events) get a fresh UUID per user action; reuse it only to retry that same action.

Sign-in

StepCallNotes
Register / log inPOST /api/v1/auth/register, POST /api/v1/auth/loginReturns an access token (JWT, 15 min) and a refresh token (opaque, 60 days)
Authenticated callAuthorization: Bearer <access token>
Access token expired401 unauthenticated → refresh once, retry the call once
RefreshPOST /api/v1/auth/refreshRotates: store the new refresh token. Reusing an old one revokes the whole session family
Refresh refused401 refresh_token_invalid or session_revokedSign in again
Log outPOST /api/v1/auth/logoutBearer token and { refreshToken }. 204, effective at once. A second logout with the same (revoked) token is 401: treat 401 as "already signed out"
Too many attempts429 rate_limited with Retry-After (seconds)

7. Before a release build ships