> For the complete documentation index, see [llms.txt](https://docs.sentiance.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sentiance.com/getting-started/accessing-insights/sdk-apis.md).

# SDK APIs

Sentiance Insights is available through the APIs exposed by the Sentiance SDK for:

* iOS
* Android
* React Native
* Flutter

### Fetching Insights

Depending on your use-case and the technical design of your application, you have two options to retrieve insights:

1. Querying the SDK on Demand
2. Listening to Callbacks for Real-time Updates

#### Querying the SDK on Demand

You can query the SDK for insights at any point in your application logic. The following example demonstrates how to fetch the recent timeline events:

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

```swift
let currentDate = Date()
let calendar = Calendar.current
let fiveDaysAgo = calendar.date(byAdding: .day, value: -5, to: currentDate)

let events = Sentiance.shared.getTimelineEvents(from: fiveDaysAgo!, to: currentDate)
events.forEach { event in
    print(event.eventId)
}
```

{% endtab %}

{% tab title="Android" %}

```kotlin
val from = Date(0)
val to = Date(Long.MAX_VALUE)

EventTimelineApi.getInstance(context).getTimelineEvents(from, to).forEach { event ->
    print("Event ID: ${event.id}")
}
```

{% endtab %}

{% tab title="React Native" %}

```javascript
import EventTimelineApi from '@sentiance-react-native/event-timeline';

const from = new Date(0); // 01/01/1970
const to = new Date(2 ** 31 * 1000);

const events = await EventTimelineApi.getTimelineEvents(from.getTime(), to.getTime());
for (const event of events) {
    console.log(`Event ID: ${event.id}`);
}
```

{% endtab %}

{% tab title="Flutter" %}

```dart
import 'package:sentiance_event_timeline/sentiance_event_timeline.dart';

final sentianceEventTimeline = SentianceEventTimeline();
const int maxLongValue = 9223372036854775807;
final events = await sentianceEventTimeline.getTimelineEvents(0, maxLongValue);
for (var event in events) {
    print("Event ID: ${event.id}");
}
```

{% endtab %}
{% endtabs %}

Similarly, you can request various insights. Read through the [full example](/implementing-features/insights.md) and explore [SDK API Reference](/sdk/api-reference.md) for a comprehensive list of available APIs

#### Listening to Callbacks for Real-time Updates

When setting up callbacks for real-time updates, it's crucial to ensure that you attach the listener at the appropriate location in your code.

The listeners should be included in the app boot-up scripts, right after executing the SDK initialization commands.

Checkout [Real-Time Listeners](/sdk/appendix/real-time-listeners.md) for more details

#### Synchronising Insights with Your Backend

A common practice involves ensuring the insights are effectively synchronised with your backend storage systems. This step is essential for integrating real-time data insights directly into your data management workflows.

Checkout [Data Synchronization](/sdk/appendix/data-sychronization.md) for more details
