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

# Send Bordereau Export Run to Google Drive

> Delivers the file a **succeeded** bordereau export run produced to Google
Drive as a **new Google Sheets spreadsheet** — the Drive half of
**`POST /policies/bordereau/export-runs`**, replacing the retired
synchronous Google Sheets export endpoint.

The spreadsheet is created **as the caller**, in the Drive folder named by
`folderId`, using the `googleOAuthToken` supplied in the body — the token
is used once to create the spreadsheet and never persisted. The spreadsheet
is named `bordereau-export-{runId}` and carries one tab (`bordereau`) with
exactly the run's CSV cells: the delivery changes the file format, never
the values. Each call creates a fresh spreadsheet; delivering the same run
twice creates two.

**Only a `succeeded` run delivers.** Every other status is a `404`:
`queued` and `running` have no file yet, `failed` never produced one, and
`expired` means the file passed its retention horizon and was deleted. Poll
**`GET .../export-runs/{runId}`** to learn which — the poll stays readable
for every status — and start a new export when the run failed or expired.

**Required permission:** `company.policy:read`




## OpenAPI

````yaml /openapi/generated-external-api.yaml post /api/v1/companies/{companyId}/policies/bordereau/export-runs/{runId}/drive
openapi: 3.0.3
info:
  title: AI Insurance External API
  description: External API for AI Insurance platform
  version: 1.0.0
  contact:
    email: support@aiinsurance.io
servers:
  - url: https://go.aiinsurance.io
    description: Production
security:
  - ApiKeyAuth: []
paths:
  /api/v1/companies/{companyId}/policies/bordereau/export-runs/{runId}/drive:
    post:
      tags:
        - Field Model Bordereau
      summary: Send Bordereau Export Run to Google Drive
      description: >
        Delivers the file a **succeeded** bordereau export run produced to
        Google

        Drive as a **new Google Sheets spreadsheet** — the Drive half of

        **`POST /policies/bordereau/export-runs`**, replacing the retired

        synchronous Google Sheets export endpoint.


        The spreadsheet is created **as the caller**, in the Drive folder named
        by

        `folderId`, using the `googleOAuthToken` supplied in the body — the
        token

        is used once to create the spreadsheet and never persisted. The
        spreadsheet

        is named `bordereau-export-{runId}` and carries one tab (`bordereau`)
        with

        exactly the run's CSV cells: the delivery changes the file format, never

        the values. Each call creates a fresh spreadsheet; delivering the same
        run

        twice creates two.


        **Only a `succeeded` run delivers.** Every other status is a `404`:

        `queued` and `running` have no file yet, `failed` never produced one,
        and

        `expired` means the file passed its retention horizon and was deleted.
        Poll

        **`GET .../export-runs/{runId}`** to learn which — the poll stays
        readable

        for every status — and start a new export when the run failed or
        expired.


        **Required permission:** `company.policy:read`
      operationId: driveBordereauExportRun
      parameters:
        - $ref: '#/components/parameters/companyId'
        - name: runId
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: >
            The run identifier returned by **`POST

            /policies/bordereau/export-runs`**. Runs are scoped to their company
            AND

            their kind: a run id belonging to another company, or to an entity

            export run rather than a bordereau one, returns `404`, exactly as an
            id

            that exists nowhere does.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - folderId
                - googleOAuthToken
              properties:
                folderId:
                  type: string
                  minLength: 1
                  description: >
                    Google Drive folder ID in which to create the new
                    spreadsheet.
                googleOAuthToken:
                  type: string
                  minLength: 1
                  description: |
                    Google OAuth2 access token with write access to the target
                    folder. The spreadsheet is created as this token's user, who
                    owns the resulting file; the token is used once and never
                    persisted.
            examples:
              deliverToFolder:
                summary: Deliver the run's file into a Drive folder
                value:
                  folderId: 1a2b3c4d5e6f7g8h9i0j
                  googleOAuthToken: ya29.a0AfH6SMA...
      responses:
        '200':
          description: The run's file was delivered as a new spreadsheet
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExportRunDriveResponse'
              examples:
                success:
                  summary: Delivery completed
                  value:
                    spreadsheetUrl: >-
                      https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgVE2upms/edit
        '400':
          description: >
            Bad Request - the run id path parameter is missing or is not a UUID,
            or

            the body is missing `folderId` or `googleOAuthToken` (both must be

            non-empty strings).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                invalidRunId:
                  summary: Missing or malformed run id
                  value:
                    error:
                      code: INVALID_RUN_ID
                      message: A run id path parameter is required, and must be a UUID.
                missingFolderId:
                  summary: The body is missing a required property
                  value:
                    error:
                      code: ValidationError
                      message: 'Invalid input: expected string, received undefined'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          description: >
            Not Found — no DELIVERABLE file exists here. Either no bordereau
            export

            run with this id exists for this company (a run id belonging to a

            different company, or to an entity export run, is reported the same

            way), or the run exists but is not `succeeded`: still `queued` or

            `running`, `failed`, or `expired` after its retention horizon. Poll

            the run's status endpoint to learn which.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              examples:
                notFound:
                  summary: Unknown run id for this company's bordereau exports
                  value:
                    error:
                      code: NotFound
                      message: >-
                        Export run 7c9e6679-7425-40de-944b-e07fc1f90ae7 not
                        found.
                notDeliverable:
                  summary: The run exists but has no downloadable artifact
                  value:
                    error:
                      code: NotFound
                      message: >-
                        Export run 7c9e6679-7425-40de-944b-e07fc1f90ae7 has no
                        downloadable artifact (status: expired).
        '500':
          $ref: '#/components/responses/InternalServerError'
      security:
        - BearerAuth: []
        - ApiKeyAuth: []
components:
  parameters:
    companyId:
      name: companyId
      in: path
      required: true
      schema:
        type: string
        format: uuid
      description: Company identifier
  schemas:
    ExportRunDriveResponse:
      type: object
      description: >
        Result of delivering a succeeded export run's file to Google Drive as a
        new

        spreadsheet.
      required:
        - spreadsheetUrl
      properties:
        spreadsheetUrl:
          type: string
          format: uri
          description: >-
            Direct URL to the created Google Sheets spreadsheet, in the caller's
            Drive.
    ErrorResponse:
      type: object
      description: Standard error response for all external API endpoints
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
              description: Machine-readable error code
              example: VALIDATION_ERROR
            message:
              type: string
              description: Human-readable error message
              example: 'submissionId: Required field is missing'
            userMessages:
              type: array
              description: >-
                Clean, verbatim-displayable messages — one entry per failure,
                free of error-code tags, field paths, and internal noise.
                Suitable for showing to end users as-is.
              items:
                type: string
              example:
                - Exposures of type 'company' require an address
            details:
              type: array
              description: Additional details for validation errors (field-level errors)
              items:
                type: object
                properties:
                  field:
                    type: string
                    description: The field that caused the error
                    example: submissionId
                  message:
                    type: string
                    description: Description of the field error
                    example: Required field is missing
  responses:
    Unauthorized:
      description: Unauthorized - Invalid or missing API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            missingApiKey:
              summary: Missing API key
              value:
                error:
                  code: AuthenticationError
                  message: API key authentication required
                  userMessages:
                    - API key authentication required
            invalidApiKey:
              summary: >-
                Invalid API key (e.g. unknown key, or a Bearer token used
                instead of an API key)
              value:
                error:
                  code: AuthenticationError
                  message: Invalid API key
                  userMessages:
                    - Invalid API key
    Forbidden:
      description: Forbidden - Insufficient permissions
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            insufficientPermissions:
              summary: Insufficient permissions
              value:
                error:
                  code: AuthorizationError
                  message: User is not authorized to perform the requested action
                  userMessages:
                    - User is not authorized to perform the requested action
            companyMismatch:
              summary: A valid API key naming another company in the URL
              value:
                error:
                  code: AuthorizationError
                  message: API key is not scoped to the requested company
                  userMessages:
                    - API key is not scoped to the requested company
    InternalServerError:
      description: Internal Server Error - Unexpected error occurred
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            internalError:
              summary: Unexpected server error
              value:
                error:
                  code: UncaughtActionError
                  message: Uncaught error occurred in <actionName>
                  userMessages:
                    - An unexpected error occurred. Please try again later.
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        API key authentication. Send your raw API key as the `Authorization`
        header value with NO scheme prefix — `Authorization: YOUR-API-KEY`. Do
        NOT prefix it with `Bearer ` or `ApiKey `, and do not use an `X-API-Key`
        header; those are not accepted.
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        User-principal OAuth 2.0 Bearer authentication. Send a user-scoped Auth0
        access token (audience = the app API audience) as `Authorization: Bearer
        <jwt>`. The request resolves to the user's identity and is authorized by
        their Role on the `{companyId}` in the path — the same role-based
        permissions the web app enforces. This is the path the MCP connector
        uses to act on a user's behalf; endpoints that accept it list both
        `BearerAuth` and `ApiKeyAuth`.

````