fetchRecommendations

fun fetchRecommendations(context: Context, recommendationId: String, itemId: String = "", includedFields: Set<String> = emptySet(), workspaceId: String? = null): MoETask<RecommendedItems>

Fetches the recommended items associated with recommendationId.

Items are served from the local cache while a non-expired entry exists; otherwise the SDK fetches them from the server and caches the response. An empty result is a success.

Sample Usage:

MoERecommendationsHelper.fetchRecommendations(
context = context,
recommendationId = "YOUR_RECOMMENDATION_ID",
// optional
itemId = "YOUR_ITEM_ID",
// optional
includedFields = setOf("title", "price")
)
.onSuccess { recommendedItems ->
val items = recommendedItems.items
if (items.isEmpty()) {
// No recommendations are available for this user. Show your empty state.
} else {
// Render the items.
}
}
.onFailure { failure ->
when (failure.reason) {
RecommendationsFailureReason.RATE_LIMIT_EXCEEDED -> {
// Retry later.
}
MoERequestFailureReason.NetworkError -> {
// The device is offline. Retry when connectivity returns.
}
else -> {
// Show a fallback.
}
}
}

Return

A MoETask delivering RecommendedItems on success, on the main thread. A failure carries a RecommendationsFailureReason, or a MoERequestFailureReason when the SDK itself blocked the call.

Since

1.0.0

Parameters

context

An instance of Context.

recommendationId

Recommendation ID defined on the dashboard. Must not be blank.

itemId

Item ID defined on the MoEngage dashboard. Optional field, ignored when no value is passed

includedFields

Fields to return for each item, over and above the core fields. Optional field, ignored when no value is passed or empty.

workspaceId

The optional workspace ID; if null, the default instance will be used.

Throws

if the SDK is not initialized for the given instance. The task rejects with MoERequestFailureReason.SdkState instead when the integration validator is disabled.