Quick start
Export events, sessions, and users from a workspace.
The Export API client provides three methods to export data from your workspace. Each method supports pagination and optional time-based filtering.
This feature is offered as an add-on. Contact sales for more information.
Install the client
Install the client using your preferred package manager:
npm install @croct/exportExport events
Here is how to export event data from your workspace:
import {Configuration, ExportApi} from '@croct/export';
async function exportEvents(): Promise<void> { const api = new ExportApi( new Configuration({ apiKey: '<API KEY>' }) );
let cursor: string | undefined = undefined; let running = true;
while (running) { const {data: {items: events, nextCursor}} = await api.exportEvents({ pageSize: 100, cursor: cursor, });
console.log(events);
cursor = nextCursor; running = events.length > 0; }}You can filter events by type using the events parameter:
import {Configuration, EventType, ExportApi} from '@croct/export';
const {data: {items: events}} = await api.exportEvents({ pageSize: 100, events: [ EventType.PRODUCT_VIEWED, EventType.CHECKOUT_STARTED, EventType.ORDER_PLACED, ],});See the API reference for a complete list of event types.
Export sessions
Here is how to export session data from your workspace:
import {Configuration, ExportApi} from '@croct/export';
async function exportSessions(): Promise<void> { const api = new ExportApi( new Configuration({ apiKey: '<API KEY>' }) );
let cursor: string | undefined = undefined; let running = true;
while (running) { const {data: {items: sessions, nextCursor}} = await api.exportSessions({ pageSize: 100, cursor: cursor, });
console.log(sessions);
cursor = nextCursor; running = sessions.length > 0; }}Export users
Here is how to export user data from your workspace:
import {Configuration, ExportApi} from '@croct/export';
async function exportUsers(): Promise<void> { const api = new ExportApi( new Configuration({ apiKey: '<API KEY>' }) );
let cursor: string | undefined = undefined; let running = true;
while (running) { const {data: {items: users, nextCursor}} = await api.exportUsers({ pageSize: 100, cursor: cursor, });
console.log(users);
cursor = nextCursor; running = users.length > 0; }}You can specify the start and end parameters to define the time range for the data you want to export. For example, to export events from the last 24 hours:
const today = new Date();today.setHours(0, 0, 0, 0);
const yesterday = new Date(today.getTime());yesterday.setDate(today.getDate() - 1);
const {data: {items: events}} = await api.exportEvents({ pageSize: 100, start: yesterday.getTime(), end: today.getTime(),});