addFavorite

abstract suspend fun addFavorite(locationId: Long, isPrimary: Boolean = false): List<FavoriteLocation>

Adds a location to the member's favorites. The server treats this as a declarative upsert: an excluded location becomes a favorite and a muted one is unmuted - it never answers 409 for a location already favorited.

Use it when the member favorites a place from a map, a search result or a detail screen - it replaces facilities().update(id, verified = true). A running visit-detection session starts watching the new favorite without a restart. To exclude a location there is no replacement yet: keep calling facilities().update(id, verified = false).

Favorites mix fitness and retail locations, but a member has one primary location across all of them, and the primary is the gym visits fall back to: only mark a fitness location (FavoriteLocation.isFitness) primary. Marking a location primary demotes the previous one. Re-adding the current primary with isPrimary = false keeps it primary - the SDK never demotes it as a side effect of an upsert.

Android (Kotlin)

lifecycleScope.launch {
try {
val favorites = AFCore.locations().addFavorite(locationId = marker.id, isPrimary = false)
showFavorites(favorites)
} catch (t: Throwable) {
showError(t)
}
}

iOS (Swift)

Task {
do {
let favorites = try await AFCore.shared.locations().addFavorite(locationId: marker.id, isPrimary: false)
showFavorites(favorites)
} catch {
showError(error)
}
}

Return

The complete, post-mutation favorites list.

Parameters

locationId

Canonical location id to favorite (a legacy club id is resolved server-side; 409 when ambiguous).

isPrimary

Whether to make it the member's primary location.

Throws

if the request fails - 400 for a non-positive id, 404 for an unknown location.