# Export Talon.One data

> You can export data from Talon.One to use it in other marketing tools, run reports or analyze it as part of your BI strategy in case your integration landscape includes an existing data warehouse.

> For the complete documentation index, see [llms.txt](https://docs.talon.one/llms.txt).

Talon.One also offers reporting on the data it receives as statistics such as
campaign performance and customer activity over a time period.
You can export this data, depending its type, via one of more of the following options:

- The Campaign Manager's user interface.
- [The Integration API][iapi].
- [The Management API][mapi].

:::note
In the exported file, all timestamp values follow `UTC+00:00`.
:::

In this tutorial, let's export the following types of data:

- [Customer sessions](/docs/dev/concepts/entities/customer-sessions.md)
- [Customer profiles](/docs/dev/concepts/entities/customer-profiles.md)
- Triggered [effects](/docs/dev/integration-api/api-effects.md)
- [Loyalty data](/docs/product/loyalty-programs/overview.md)
  - Loyalty balances
  - Loyalty transaction logs
  - Projected loyalty balances

You can automate exports of [customer sessions, customer profiles and triggered effects](#automate-data-exports).
Loyalty data can only be exported [manually](#manually-export-data).

:::note
To export loyalty data, create a [loyalty program](/docs/product/loyalty-programs/overview.md),
connect it to the Application and use it in one or more campaigns.
:::

## Automate data exports

Let's automate data exports for [customer sessions](/docs/dev/concepts/entities/customer-sessions.md),
[customer profiles](/docs/dev/concepts/entities/customer-profiles.md) and triggered [effects](/docs/dev/integration-api/api-effects.md).

:::important
Loyalty data can only be exported [manually](#manually-export-data).
:::

This is the recommended option to keep an up-to-date copy of the Talon.One data
in your data warehouse.

You can automate the data export using the
[Management API][mapi] as follows:

1. Initialize a `lastSync` variable. It represents the last time you exported data.

   If you already have received events from Talon.One: set this variable to
   the `created` timestamp of the latest event you received.

   If no events have been received, set the variable to the `created` timestamp of your
   Application.
   Get the timestamp with the [List Applications](/management-api#tag/Applications/operation/getApplications) endpoint.

1. Create the following empty sets:

   - `profilesToFetch`
   - `sessionsToFetch`

1. Request all events created after your last sync using the
   [List Applications events][getAppEvents] endpoint.
   Set the `createdAfter` query parameter to the value of `lastSync`.

   The response contains an `totalResultSize` property and a `data` array containing
   events.

1. For each event in `response.data`, do the following:

   1. Store a new `talon_one_event` record in your data warehouse.
   1. If `event.sessionId` is non-zero, add it to the `sessionsToFetch` set.
   1. If `event.profileId` is non-zero, add it to the `profilesToFetch` set.
   1. Set `lastSync` to `event.created`.

1. If `response.totalResultSize` is equal to the number of items in
   `response.data`:
   1. For each ID in `profilesToFetch`, do the following:
      1. Fetch the profile using the [List customer profiles matching the given attributes][listCustProf] endpoint.
      1. Store a timestamped `talon_one_profile_snapshot` record
         in your data warehouse.
   1. For each ID in `sessionsToFetch`, do the following:
      1. Fetch the session using the [List Application sessions][listAppSess] endpoint.
      1. Store a timestamped `talon_one_session_snapshot` record in your data
         warehouse.
   . Sleep for 1-5 minutes.
1. Repeat from step 3.

This process can be run continuously, and you can tune the sleep interval to balance between
the number of API requests performed and the latency of updates to your data warehouse.

:::note
Depending on the sophistication of your existing BI tools, you can normalize the
nested event/effect data in step 4.1.

To learn more on the structure of events and how to interpret the `event.effects`
array, see [API effects](/docs/dev/integration-api/api-effects.md).
:::

If you don't have a data warehouse or cannot automate data exports, read the next
section about [exporting data manually](#manually-export-data).

## Manually export data

If you're [automating exports](#automate-data-exports), or for one-time exports,
you can manually export [customer sessions](/docs/dev/concepts/entities/customer-sessions.md),
triggered [effects](/docs/dev/integration-api/api-effects.md), and [loyalty point
transactions](/docs/product/loyalty-programs/overview).

:::important
Customer profiles cannot be manually exported.
:::

### Export customer sessions

You can export your [customer sessions](/docs/dev/concepts/entities/customer-sessions.md) as a CSV file
and check specific information about your Application, such as what items were purchased
in a certain session, or manually import the data into your data warehouse.

You can export the CSV file in the following ways:

- Programmatically, using the [Export customer sessions](/management-api#tag/Analytics/operation/exportCustomerSessions) endpoint.
- Using the Campaign Manager, see [exporting customer sessions](/docs/product/applications/display-customer-sessions.md#export-customer-sessions).

### Export triggered effects

You can export triggered [effects](/docs/dev/integration-api/api-effects.md) as a CSV file
and check specific information, such as how many times a given coupon code was redeemed, or
manually import the data into your data warehouse.

You can export the CSV file in the following ways:

- Programmatically, using the [Export triggered effects](/management-api#tag/Analytics/operation/exportEffects) endpoint.
- Using the Campaign Manager, see [exporting triggered effects](/docs/product/rules/effects/export-triggered-effects.md).

### Export loyalty balances

You can export the point balances of all users of a loyalty program for a given date
and time as a CSV file using the Campaign Manager. See the following pages:

- [Export loyalty balances in profile-based programs](/docs/product/loyalty-programs/profile-based/manage-pb-lp-data.md#export-the-loyalty-balances)
- [Export loyalty balances in card-based programs](/docs/product/loyalty-programs/card-based/manage-loyalty-cards.md#export-the-loyalty-balances)

### Export loyalty transaction logs

You can export all [loyalty point transactions](/docs/product/loyalty-programs/overview.md)
made by a given customer using the Campaign Manager as a CSV file. See [exporting transactions](/docs/product/loyalty-programs/profile-based/manage-pb-lp-data.md#export-the-transaction-logs).

## Related pages

- [Display customer sessions](/docs/product/applications/display-customer-sessions.md)
- [Display customer profiles](/docs/product/applications/display-customer-profiles.md)
- [List Application events endpoint][getAppEvents]
- [List Application sessions endpoint][listAppSess]
- [List customer profiles matching the given attributes endpoint][listCustProf]
- [Management API overview][mapi]

[getAppEvents]: /management-api#tag/Customer-data/operation/getApplicationEventsWithoutTotalCount
[listAppSess]: /management-api#tag/Customer-data/operation/getApplicationSession
[listCustProf]: /management-api#tag/Customer-data/operation/getCustomersByAttributes
[mapi]: /docs/dev/management-api/overview.md
[iapi]: /docs/dev/integration-api/overview.md
