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

# Export a record set as a file

> Builds a CSV or JSON file of the records matching the same filter and sort strings a records query takes. Download stores it for the caller alone and returns its bucket and key; email attaches it, or stores and links it when it is too large to attach. An export that cannot read every record fails rather than returning a short file. Validation answers at once. By default the export runs inline and answers 200 with the result. With async: true it runs in the background and the reply is 202 with a job_id; a token with no user id still runs inline. Post {job_id} alone to read the caller's job: status running, done (result holds the fields an inline export returns) or error. A running job not updated for 10 minutes reads as error. Jobs are kept for 24 hours.



## OpenAPI

````yaml /api-reference/endpoint/records/openapi.json post /records/export-records
openapi: 3.1.0
info:
  title: Records API
  version: 1.1.0
  description: >-
    Record configurations (schemas, views, versions) and the records that
    conform to them. Record IDs are server-generated, config IDs are
    client-supplied (`^[a-zA-Z0-9_-]+$`). Configs and records are updated with
    PUT: a config update applies only the fields sent, a record update merges
    `data`. Editing a config schema does not retroactively re-validate existing
    records. Publish a config version to snapshot the stored config; list and
    read versions to see its history.
servers:
  - url: https://api.quiva.ai
    description: Production API server
security:
  - bearerAuth: []
  - apiKeyAuth: []
tags:
  - name: Record Configs
    description: >-
      Manage record configuration schemas. Each configuration defines the
      structure (fields, types, validation rules) that records must conform to.
  - name: Records
    description: >-
      Manage individual data records. Each record belongs to exactly one
      configuration and its data is validated against that configuration's
      schema.
  - name: Record Config Collections
    description: Groups of record configs.
  - name: Record Config Versions
    description: Published snapshots of a record config.
  - name: Record History
    description: The change history of a record.
  - name: Record Assessment
  - name: Strategy and Simulation
  - name: Record Metrics
paths:
  /records/export-records:
    post:
      tags:
        - Records
      summary: Export a record set as a file
      description: >-
        Builds a CSV or JSON file of the records matching the same filter and
        sort strings a records query takes. Download stores it for the caller
        alone and returns its bucket and key; email attaches it, or stores and
        links it when it is too large to attach. An export that cannot read
        every record fails rather than returning a short file. Validation
        answers at once. By default the export runs inline and answers 200 with
        the result. With async: true it runs in the background and the reply is
        202 with a job_id; a token with no user id still runs inline. Post
        {job_id} alone to read the caller's job: status running, done (result
        holds the fields an inline export returns) or error. A running job not
        updated for 10 minutes reads as error. Jobs are kept for 24 hours.
      operationId: exportRecords
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                config_id:
                  type: string
                space_id:
                  type: string
                  description: Required unless folder is set.
                folder:
                  type: string
                  description: Required unless space_id is set.
                format:
                  type: string
                  enum:
                    - csv
                    - json
                  default: csv
                delivery:
                  type: string
                  enum:
                    - email
                    - download
                  default: email
                email:
                  type: string
                  description: Where an emailed export goes. Defaults to the calling user.
                filter:
                  type: string
                sort_by:
                  type: string
                zip:
                  type: boolean
                  default: false
                  description: Wrap the file in a .zip holding it under its usual name.
                async:
                  type: boolean
                  default: false
                  description: >-
                    Run the export as a job and answer 202 {job_id}. Without it
                    the export runs inline and answers 200.
                job_id:
                  type: string
                  description: >-
                    Sent alone, reads the caller's export job instead of
                    starting one, with or without async. Another user's job is
                    404.
              description: config_id is required unless job_id is set.
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Response'
                  - properties:
                      body:
                        type: object
                        properties:
                          message:
                            type: string
                          records:
                            type: integer
                            description: Records in the file.
                          size:
                            type: integer
                            description: File size in bytes.
                          filename:
                            type: string
                          bucket:
                            type: string
                            description: >-
                              Set when the file was stored: always for download,
                              and for an email too large to attach.
                          key:
                            type: string
                            description: >-
                              The stored object's key, readable only by the
                              caller. Set with bucket.
                        description: >-
                          The result of an inline export. A job read instead
                          returns the ExportJob fields: job_id, delivery,
                          status, stage (waiting, reading, writing), read,
                          total, error, result, started_at, updated_at.
        '202':
          description: Export started as a job; only when the request set async
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Response'
                  - properties:
                      body:
                        type: object
                        properties:
                          job_id:
                            type: string
                            description: Post it back as {job_id} to read the job.
        '400':
          description: Request refused or invalid
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: The record set, or the caller's job, was not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    Response:
      type: object
      properties:
        status_code:
          type: integer
          description: HTTP status code echoed in the response body.
        body:
          type: object
          description: Response payload.
    ErrorResponse:
      type: object
      properties:
        status_code:
          type: integer
        body:
          type: object
          properties:
            error:
              type: string
              description: Human-readable error message.
      example:
        status_code: 400
        body:
          error: field 'rating' is required
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
    apiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key

````

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