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

# Generate CSV document

> Creates a new CSV document from the provided rows of data and returns the new document's metadata.



## OpenAPI

````yaml https://app.stainless.com/api/spec/documented/samplehc/openapi.documented.yml post /api/v2/documents/generate-csv
openapi: 3.0.3
info:
  title: Sample Healthcare API
  description: API for Sample Healthcare
  version: 1.0.0
servers: []
security: []
paths:
  /api/v2/documents/generate-csv:
    post:
      tags:
        - Document
      summary: Generate CSV document
      description: >-
        Creates a new CSV document from the provided rows of data and returns
        the new document's metadata.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                rows:
                  type: array
                  items:
                    type: object
                    additionalProperties:
                      anyOf:
                        - type: string
                        - type: number
                        - type: boolean
                  description: >-
                    Array of objects, where each object represents a row with
                    column headers as keys.
                fileName:
                  type: string
                  description: >-
                    The desired file name for the generated CSV (e.g.,
                    'report.csv').
                options:
                  type: object
                  properties:
                    exportAsExcel:
                      type: boolean
                      description: If true, includes BOM for Excel compatibility.
                    columnOrder:
                      type: array
                      items:
                        type: string
                      description: Optional array of strings to specify column order.
                    columnTypes:
                      type: object
                      additionalProperties:
                        type: string
                        enum:
                          - date
                          - datetime
                          - number
                          - currency
                          - percentage
                      description: >-
                        Map of column names to Excel data types for typed
                        formatting.
                  additionalProperties: false
              required:
                - rows
                - fileName
              additionalProperties: false
        required: true
      responses:
        '200':
          description: CSV document generated successfully.
          content:
            application/json:
              schema:
                type: object
                properties:
                  document:
                    type: object
                    properties:
                      id:
                        type: string
                      fileName:
                        type: string
                    required:
                      - id
                      - fileName
                    additionalProperties: false
                    description: Metadata of the newly generated CSV document.
                required:
                  - document
                additionalProperties: false
        '400':
          description: Default Response
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: The error message.
                  message:
                    type: string
                    description: The message.
                  statusCode:
                    type: number
                    description: The status code.
                  details:
                    type: object
                    additionalProperties: {}
                    description: The details of the error
                additionalProperties: true
        '500':
          description: Default Response
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: Internal server error while generating the CSV document.
                required:
                  - error
                additionalProperties: false
      x-codeSamples:
        - lang: Python
          source: |-
            import os
            from samplehc import SampleHealthcare

            client = SampleHealthcare(
                api_key=os.environ.get("SAMPLEHC_API_KEY"),  # This is the default and can be omitted
            )
            response = client.v2.documents.generate_csv(
                file_name="fileName",
                rows=[{
                    "foo": "string"
                }],
            )
            print(response.document)

````