Listing all OAuth clients and their scopes via the Genesys Cloud API in Kotlin

I’m building an admin utility in Kotlin to audit our OAuth client configurations. I need to programmatically list every OAuth client in our Genesys Cloud org and check which scopes are assigned to each one. The goal is to flag any clients that have broader access than necessary.

I started by hitting GET /api/v2/oauth/clients. The response returns a list of OAuthClient objects, but the scope details aren’t immediately obvious in the top-level response. I noticed there’s a scopes field in the JSON payload, but it seems to be a list of strings. Is there a way to get more detailed information about each scope, like its description or category, directly from this endpoint?

Here’s a snippet of how I’m fetching the clients:

val response = apiClient.getOauthApi().listOauthClients()
response.body?.forEach { client ->
 println("Client: ${client.name}, Scopes: ${client.scopes}")
}

The client.scopes list just contains strings like "analytics:aggregate:read". I’d prefer not to make a separate GET /api/v2/oauth/scope call for every single scope string to get the details. Is there a batch endpoint or a way to expand the scope details in the initial client list request?

Also, I’m seeing some clients with no scopes listed. Does that mean they have default scopes, or is it a configuration error?

The scopes are nested in clientScopes on the OAuthClient object. You need to expand it with ?expand=clientScopes in your GET request.

val response = api.getOAuthClients(expand = listOf("clientScopes"))
response.entities.forEach { println("${it.name}: ${it.clientScopes?.map { s -> s.name }}") }