# Rewards

The SDK allows for the host application to retrieve a token, which in turn can be used by the host application to fetch data from the Rewards system (see documentation for the Rewards). In order to fetch that token, the application must have a valid user (represented by the Identity). That user must be active.

### **Fetch Token**

To fetch the token, the following API can be used.

### **Concrete example**

{% tabs %}
{% tab title="Swift" %}

```swift
let rewards = RewardsService()
rewards.fetchToken(then: { result in
    let token = result.value.token
    guard !token.isEmpty else {
        // failure
        return
    }
    completionHandler(.success(token))
})
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val rewards = RewardsService()
rewards.fetchToken(ResultCallback { result: Result<RewardToken?>? ->
    if (result?.value == null || result.throwable != null) {
        // failure
    } else {
        // Success
        val token = result.value.token
    }
})
```

{% endtab %}
{% endtabs %}
