# Export events

Export events from an application.

```
GET https://api.croct.io/export/events
```

## Example

Here is an example of how to export events:

**JavaScript**

```js
const url = new URL('https://api.croct.io/export/events');
url.searchParams.append('start', '1440990000000');
url.searchParams.append('end', '1441076400000');
url.searchParams.append('pageSize', '100');
url.searchParams.append('events', 'productViewed');
url.searchParams.append('events', 'checkoutStarted');
url.searchParams.append('events', 'orderPlaced');

const response = await fetch(url, {
  headers: {
    'X-Api-Key': '<API KEY>',
  },
});

const {metadata, items, nextCursor} = await response.json();
```

**cURL**

```bash
curl -X GET 'https://api.croct.io/export/events' \
  -H 'X-Api-Key: <API KEY>' \
  -G \
  --data-urlencode 'start=1440990000000' \
  --data-urlencode 'end=1441076400000' \
  --data-urlencode 'pageSize=100' \
  --data-urlencode 'events=productViewed' \
  --data-urlencode 'events=checkoutStarted' \
  --data-urlencode 'events=orderPlaced'
```

## Headers

This endpoint requires the following HTTP headers:

- `X-Api-Key`: `string`

  The [API key](/explanation/application/api-keys) of the application from which to export events.

## Parameters

This endpoint accepts the following query parameters:

- `start`: `integer` (optional)

  The earliest event time to include, in milliseconds since epoch.

  Only events that occurred at or after this time are included.

- `end`: `integer` (optional)

  The latest event time to include, in milliseconds since epoch.

  Only events that occurred before this time are included. If not provided, there is no upper time limit.

- `pageSize`: `integer` (optional) (default: 100)

  The maximum number of events returned per request.

  Must be between 1 and 1000.

- `cursor`: `string` (optional)

  A cursor for retrieving the next page of results.

  If omitted, export starts from the beginning of the specified time window.

- `events`: `Array<string>` (optional)

  The list of event types to include. By default, all event types are included.

  Here are the supported event types:

  | Event                                                                                | Constant                           |
  | ------------------------------------------------------------------------------------ | ---------------------------------- |
  | [`userSignedUp`](/reference/event/types/user-account/user-signed-up)                 | `EventType.USER_SIGNED_UP`         |
  | [`userSignedIn`](/reference/event/types/user-account/user-signed-in)                 | `EventType.USER_SIGNED_IN`         |
  | [`userSignedOut`](/reference/event/types/user-account/user-signed-out)               | `EventType.USER_SIGNED_OUT`        |
  | [`tabOpened`](/reference/event/types/web-browsing/tab-opened)                        | `EventType.TAB_OPENED`             |
  | [`tabUrlChanged`](/reference/event/types/web-browsing/tab-url-changed)               | `EventType.TAB_URL_CHANGED`        |
  | [`tabVisibilityChanged`](/reference/event/types/web-browsing/tab-visibility-changed) | `EventType.TAB_VISIBILITY_CHANGED` |
  | [`locationDetected`](/reference/event/types/session/location-detected)               | `EventType.LOCATION_DETECTED`      |
  | [`clientDetected`](/reference/event/types/session/client-detected)                   | `EventType.CLIENT_DETECTED`        |
  | [`pageOpened`](/reference/event/types/web-browsing/page-opened)                      | `EventType.PAGE_OPENED`            |
  | [`pageLoaded`](/reference/event/types/web-browsing/page-loaded)                      | `EventType.PAGE_LOADED`            |
  | [`productAbandoned`](/reference/event/types/ecommerce/product-abandoned)             | `EventType.PRODUCT_ABANDONED`      |
  | [`productViewed`](/reference/event/types/ecommerce/product-viewed)                   | `EventType.PRODUCT_VIEWED`         |
  | [`cartAbandoned`](/reference/event/types/ecommerce/cart-abandoned)                   | `EventType.CART_ABANDONED`         |
  | [`cartViewed`](/reference/event/types/ecommerce/cart-viewed)                         | `EventType.CART_VIEWED`            |
  | [`cartModified`](/reference/event/types/ecommerce/cart-modified)                     | `EventType.CART_MODIFIED`          |
  | [`checkoutStarted`](/reference/event/types/ecommerce/checkout-started)               | `EventType.CHECKOUT_STARTED`       |
  | [`orderPlaced`](/reference/event/types/ecommerce/order-placed)                       | `EventType.ORDER_PLACED`           |
  | [`nothingChanged`](/reference/event/types/engagement/nothing-changed)                | `EventType.NOTHING_CHANGED`        |
  | [`goalCompleted`](/reference/event/types/engagement/goal-completed)                  | `EventType.GOAL_COMPLETED`         |
  | [`eventOccurred`](/reference/event/types/engagement/event-occurred)                  | `EventType.EVENT_OCCURRED`         |
  | [`slotPersonalized`](/reference/event/types/engagement/slot-personalized)            | `EventType.SLOT_PERSONALIZED`      |
  | [`leadGenerated`](/reference/event/types/engagement/lead-generated)                  | `EventType.LEAD_GENERATED`         |
  | [`audienceMatched`](/reference/event/types/session/audience-matched)                 | `EventType.AUDIENCE_MATCHED`       |
  | [`userClicked`](/reference/event/types/engagement/user-clicked)                      | `EventType.USER_CLICKED`           |
  | [`userScrolled`](/reference/event/types/engagement/user-scrolled)                    | `EventType.USER_SCROLLED`          |

## Response

This endpoint returns a JSON response with the following properties:

- `data`: `object`

  The response containing exported events and pagination information.

  - `items`: [`Array<object>`](/reference/event/overview#event-types)

    The list of exported events.

    See the [Event types](/reference/event/overview#event-types) reference for the complete event structure.

  - `nextCursor`: `string`

    An opaque cursor for retrieving the next page of results.

    The value is an empty string when there are no more results. Treat it as opaque and pass it back unchanged on the next request.

  - `metadata`: `object`

    Metadata about the workspace and application.

    - `organizationName`: `string`

      The name of the organization.

    - `organizationSlug`: `string`

      The URL-friendly identifier of the organization.

    - `workspaceName`: `string`

      The name of the workspace.

    - `workspaceSlug`: `string`

      The URL-friendly identifier of the workspace.

    - `applicationName`: `string`

      The name of the application.

    - `applicationSlug`: `string`

      The URL-friendly identifier of the application.

### Example response

Here is an example of a JSON response from this endpoint:

```json
{
  "metadata": {
    "organizationName": "Acme Corp",
    "organizationSlug": "acme-corp",
    "workspaceName": "Production",
    "workspaceSlug": "production-app",
    "applicationName": "E-commerce Store",
    "applicationSlug": "ecommerce-store"
  },
  "items": [
    {
      "id": "924f6c8f-3b5b-47ea-b483-25a0506dc436",
      "sessionId": "343dd18a-1ab1-4298-8b19-f14880ba4e9c",
      "userId": "91d286ab-654a-47a3-ae3f-a0c0d661e44d",
      "timestamp": 1440990000000,
      "context": {
        "type": "web",
        "tabId": "0b032685-0a7e-4cdd-9ff1-9d3af33507a4",
        "url": "https://www.example.com"
      },
      "payload": {
        "type": "userSignedIn",
        "externalUserId": "user-123"
      }
    }
  ],
  "nextCursor": "eyJzZXNzaW9uSWQiOiIxMjM0NSIsInRpbWVzdGFtcCI6MTYwOTQ1OTMwMDAwMH0"
}
```
