> ## Documentation Index
> Fetch the complete documentation index at: https://documentation.onesignal.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Export users CSV

> Request a GZip-compressed CSV with one row per user, including External ID, Tags, language, timezone, location, and session times. For apps with user-based segmentation. In beta. Filter by segment ID or name.

> [!NOTE]
>
> Exporting users requires [user-based segmentation](https://documentation.onesignal.com/docs/en/user-based-segmentation.md), which is in **beta**. Functionality may change before general availability. To request access, contact [support@onesignal.com](mailto:support@onesignal.com).

## Overview

Use this endpoint to export your [Users](https://documentation.onesignal.com/docs/en/users.md) as a GZip-compressed CSV file, with one row per user. The response returns a URL where the file is uploaded when the export finishes.

To export one row per Subscription instead, use [Export subscriptions CSV](https://documentation.onesignal.com/reference/csv-export.md).

***

## How to use this API

Authenticate with an [App API key](https://documentation.onesignal.com/docs/en/keys-and-ids.md#app-api-key). Legacy (v1) API keys are rejected with a `400` error that starts with:

```text theme={null}
Request is malformed: This endpoint does not accept legacy (v1) API keys. Please use a v2 API key.
```

See [Migrating from legacy API keys](https://documentation.onesignal.com/docs/en/keys-and-ids.md#migrating-from-legacy-api-keys) to create a replacement key.

By default, the export includes every user in the app.

### Optional filters

**segment\_id** `string`

Only export users in this segment. Send the segment's UUID, as returned by [View segments](https://documentation.onesignal.com/reference/view-segments.md). Cannot be sent with `segment_name`.

**segment\_name** `string`

Only export users in the segment with this name. Cannot be sent with `segment_id`.

**include\_unsubscribed** `boolean`

Set to `true` to include every user in the segment. Defaults to `false` when you send a segment, so the export only includes the segment's subscribed users: users with a subscribed Subscription that matches the segment's filters. Defaults to `true` when you do not send a segment, so the export includes every user in the app. Setting it to `false` without a segment exports only users with at least one subscribed Subscription. See [Subscription statuses](https://documentation.onesignal.com/docs/en/subscriptions.md#subscription-statuses).

The columns are fixed. Sending `extra_fields` returns a `400` error. Other [Export subscriptions CSV](https://documentation.onesignal.com/reference/csv-export.md) parameters, such as `last_active_since`, are ignored.

### Example request

```bash cURL theme={null}
curl --request POST \
  --url https://api.onesignal.com/apps/YOUR_APP_ID/users/csv_export \
  --header 'Authorization: Key YOUR_APP_API_KEY' \
  --header 'Content-Type: application/json; charset=utf-8' \
  --data '{"segment_id": "YOUR_SEGMENT_ID"}'
```

### Example successful response

```json 200 OK theme={null}
{
  "csv_file_url": "https://onesignal.com/csv_exports/YOUR_APP_ID/onesignal_users_0f1e2d3c4b5a69788796a5b4c3d2e1f0.csv.gz"
}
```

The file name starts with `onesignal_users_`.

### File readiness

* The export runs in the background after the API responds. The `csv_file_url` returns `404` until the file is uploaded.
* Poll the URL at intervals until the file downloads. Large apps take longer to export.
* The file remains available for 3 days after generation.
* Only one export per OneSignal account can run at a time. The limit is shared with [Export subscriptions CSV](https://documentation.onesignal.com/reference/csv-export.md). A request while another export is running returns `429`.

***

## CSV data contents

Every export has these columns, in this order.

| Column | Description |
| - | - |
| `onesignal_id` | The user's OneSignal ID. |
| `external_id` | The user's [External ID](https://documentation.onesignal.com/docs/en/users.md#external-id), if set. |
| `tags` | The user's [Tags](https://documentation.onesignal.com/docs/en/add-user-data-tags.md) as a JSON object, for example `{"plan":"pro"}`. |
| `language_code` | The user's language in ISO 639-1 format. `en` when the language is not set. |
| `timezone_id` | The user's timezone in IANA format. |
| `ip_address` | The user's last known IP address, if detected. IPv4 or IPv6. |
| `lat` | The user's latitude with 6 decimal places, if location is collected. |
| `lon` | The user's longitude with 6 decimal places, if location is collected. |
| `first_session` | When the user was first active, in UTC as `YYYY-MM-DD HH:MM:SS`. |
| `last_session` | When the user was last active, in UTC as `YYYY-MM-DD HH:MM:SS`. |

Empty cells mean the value is not set.

***

## Errors

| Status | When |
| - | - |
| `400` | The request uses a legacy (v1) API key, the app is not in the user-based segmentation beta, `segment_id` and `segment_name` are both sent, either segment field is not a string, `segment_id` is not a valid UUID, the segment does not exist, or the body contains `extra_fields`. |
| `401` | The API key is missing or invalid. |
| `403` | Exports are disabled because the app exceeded a limit. See [Disabled apps](https://documentation.onesignal.com/docs/en/disabled-apps.md). |
| `429` | Another users or subscriptions export is already running for your account. Wait for it to finish, then retry. |

Error responses list messages in `errors`:

```json 400 Bad Request theme={null}
{
  "success": false,
  "errors": ["'segment_id' The provided segment does not exist"]
}
```

***

## FAQ

### Why does `csv_file_url` return 404?

The file is not ready yet. The export runs after the API responds, and the URL returns `404` until the upload finishes. Poll the URL until the file downloads.

### Why did I get "This endpoint does not accept legacy (v1) API keys"?

The request used a legacy API key. Create an [App API key](https://documentation.onesignal.com/docs/en/keys-and-ids.md#app-api-key) and send it in the `Authorization` header as `Key YOUR_APP_API_KEY`.

### How is this different from the subscriptions export?

The users export has one row per user with user-level data. The [subscriptions export](https://documentation.onesignal.com/reference/csv-export.md) has one row per Subscription, with fields such as push token, email address, phone number, and device type.


## OpenAPI

````yaml POST /apps/{app_id}/users/csv_export
openapi: 3.1.0
info:
  title: api.onesignal.com
  version: '11.6'
servers:
  - url: https://api.onesignal.com
security:
  - {}
paths:
  /apps/{app_id}/users/csv_export:
    post:
      summary: Export users CSV
      description: >-
        Generate a GZip-compressed CSV export with one row per user. Available
        only to apps with user-based segmentation.
      operationId: export-users-csv
      parameters:
        - name: app_id
          in: path
          description: >-
            Your OneSignal App ID in UUID v4 format. See [Keys &
            IDs](/docs/en/keys-and-ids).
          schema:
            type: string
            default: YOUR_APP_ID
          required: true
        - name: Authorization
          in: header
          description: >-
            Your App API key with prefix `Key `. Legacy (v1) API keys are
            rejected with a `400` error. See [Keys &
            IDs](/docs/en/keys-and-ids).
          required: true
          schema:
            type: string
            default: Key YOUR_APP_API_KEY
        - name: Content-Type
          in: header
          required: true
          schema:
            type: string
            default: application/json; charset=utf-8
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                segment_id:
                  type: string
                  format: uuid
                  description: >-
                    The ID of a segment to filter the export. Only users in this
                    segment are included. Cannot be sent with `segment_name`.
                    Omit both fields to export all users in the app.
                segment_name:
                  type: string
                  description: >-
                    The name of a segment to filter the export. Only users in
                    this segment are included. Cannot be sent with `segment_id`.
                include_unsubscribed:
                  type: boolean
                  description: >-
                    Set to `true` to include every user in the segment. Defaults
                    to `false` when a segment is provided, so only users with a
                    subscribed Subscription that matches the segment's filters
                    are exported. Defaults to `true` when no segment is
                    provided.
      responses:
        '200':
          description: '200'
          content:
            application/json:
              schema:
                type: object
                properties:
                  csv_file_url:
                    type: string
                    description: >-
                      The URL to download the CSV file. The URL returns `404`
                      until the file is ready. The file is available for 3 days
                      after generation.
              example:
                csv_file_url: >-
                  https://onesignal.com/csv_exports/YOUR_APP_ID/onesignal_users_0f1e2d3c4b5a69788796a5b4c3d2e1f0.csv.gz
        '400':
          description: >-
            Bad request. The request uses a legacy (v1) API key, the app is not
            in the user-based segmentation beta, the segment is invalid, or the
            body contains `extra_fields`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BasicErrorResponse'
              example:
                success: false
                errors:
                  - '''segment_id'' The provided segment does not exist'
        '401':
          description: The API key is missing or invalid.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BasicErrorResponse'
              example:
                errors:
                  - >-
                    Access denied.  Please include an 'Authorization: ...'
                    header with a valid API key
                    (https://documentation.onesignal.com/docs/en/keys-and-ids#api-keys).
        '403':
          description: Exports are disabled for this app because it exceeded a limit.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BasicErrorResponse'
              example:
                success: false
                errors:
                  - >-
                    Exports have been disabled for this app due to exceeding a
                    limit. Please see
                    https://documentation.onesignal.com/docs/disabled-apps for
                    more information and instructions to re-enable your app.
        '429':
          description: >-
            Another users or subscriptions export is already running for your
            account. Wait for it to finish before you start another.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BasicErrorResponse'
              example:
                success: false
                errors:
                  - Only one export may run at a time.
      deprecated: false
      security: []
components:
  schemas:
    BasicErrorResponse:
      type: object
      properties:
        errors:
          type: array
          items:
            type: string
          description: One or more human-readable error messages.
        success:
          type: boolean
          description: >-
            Present (and `false`) on some endpoints (notifications, templates,
            segments). Not emitted by every endpoint.
        reference:
          type: array
          items:
            type: string
          description: >-
            Documentation URL fragments related to the error. Only emitted by
            the API-key auth error helpers.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.