# Stopping profiles

If you use locking mechanism, then it is recommended to stop profiles after you have used them, but it is not required. If the browser window has been closed for 5 or more minutes - the profile lock will expire and other users will be able to use the profile again.

# Request

The request is POST https://api.wade.com/profiles/{profile_id}/stop and you should check it out in API reference. You only need to provide profile_lock in URL parameters (API Key is not needed).

# Response codes

Code Meaning
200 OK. Profile successfully stopped
400 Bad Request. You did not provide profile_lock in request params
404 Not Found. The profile ID and profile lock combination not found. This means your session has expired or somebody has overridden it. You should not retry the request and may treat this as success

# Code example

val profileId = "my_profile_id"
val profileLock = "profile_lock_from_start_response"

val url = "$apiUrl/profiles/$profileId/stop?profile_lock=$profileLock"

val client = HttpClient(CIO) { expectSuccess = true }
runCatching {
    client.post(url)
}.getOrElse { it: Throwable ->
    when (it) {
        is ClientRequestException -> {
            when (it.response.status) {
                HttpStatusCode.BadRequest -> println("You forgot to set profile_lock") // 400
                HttpStatusCode.NotFound -> {
                    // Session with this profileId and profileLock not found,
                    // usually should be treated as success
                    println("Profile not found")
                    return@getOrElse
                } // 404
                else -> println("Server responded with: ${it.response.status}")
            }
        }
        is TimeoutException -> println("Request timed out")
        is ConnectException -> println("Server does not respond or you have no internet")
        else -> {
            // Unknown error
            it.printStackTrace()
        }
    }
    return
}

println("Successfully stopped profile")