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

# Run a financial report

> Runs the report identified by key. range is an absolute YYYY-MM-DD..YYYY-MM-DD (end exclusive) or last_N_days. compare is previous_period or previous_year.



## OpenAPI

````yaml https://swagger.flexprice.io post /analytics/reports/{key}/query
openapi: 3.0.1
info:
  title: Flexprice API
  description: Flexprice API Service
  contact:
    name: API Support
  license:
    name: AGPL-3.0
    url: https://www.gnu.org/licenses/agpl-3.0.html
  version: '1.0'
servers:
  - url: https://us.api.flexprice.io/v1
    description: US Region
  - url: https://api.cloud.flexprice.io/v1
    description: India Region
security: []
paths:
  /analytics/reports/{key}/query:
    post:
      tags:
        - Analytics
      summary: Run a financial report
      description: >-
        Runs the report identified by key. range is an absolute
        YYYY-MM-DD..YYYY-MM-DD (end exclusive) or last_N_days. compare is
        previous_period or previous_year.
      operationId: runAnalyticsReport
      parameters:
        - name: key
          in: path
          description: Report key
          required: true
          schema:
            type: string
      requestBody:
        description: Report query request
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ReportQueryRequest'
        required: true
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnalyticsQueryResult'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/errors.ErrorResponse'
        '403':
          description: Reports not enabled
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/errors.ErrorResponse'
        '404':
          description: Report not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/errors.ErrorResponse'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/errors.ErrorResponse'
      security:
        - ApiKeyAuth: []
      x-codeSamples:
        - lang: go
          label: Go
          source: "package main\n\nimport(\n\t\"context\"\n\tflexprice \"github.com/flexprice/go-sdk/v2\"\n\t\"github.com/flexprice/go-sdk/v2/models/types\"\n\t\"log\"\n)\n\nfunc main() {\n    ctx := context.Background()\n\n    s := flexprice.New(\n        flexprice.WithSecurity(\"<YOUR_API_KEY_HERE>\"),\n    )\n\n    res, err := s.Analytics.RunAnalyticsReport(ctx, \"<key>\", types.ReportQueryRequest{\n        Range: \"2026-09-01..2026-10-01\",\n        Shape: types.ReportQueryRequestShapeBreakdown,\n    })\n    if err != nil {\n        log.Fatal(err)\n    }\n    if res.AnalyticsQueryResult != nil {\n        // handle response\n    }\n}"
        - lang: python
          label: Python
          source: |-
            from flexprice import Flexprice


            with Flexprice(
                api_key_auth="<YOUR_API_KEY_HERE>",
            ) as f_client:

                res = f_client.analytics.run_analytics_report(key="<key>", range="2026-09-01..2026-10-01", shape="breakdown")

                # Handle response
                print(res)
        - lang: typescript
          label: TypeScript
          source: |-
            import { Flexprice } from "@flexprice/sdk";

            const flexprice = new Flexprice({
              apiKeyAuth: "<YOUR_API_KEY_HERE>",
            });

            async function run() {
              const result = await flexprice.analytics.runAnalyticsReport("<key>", {
                range: "2026-09-01..2026-10-01",
                shape: "breakdown",
              });

              console.log(result);
            }

            run();
components:
  schemas:
    ReportQueryRequest:
      required:
        - range
        - shape
      type: object
      properties:
        compare:
          type: string
          enum:
            - previous_period
            - previous_year
        currency:
          type: string
        dimensions:
          type: array
          items:
            type: string
        filters:
          type: array
          items:
            $ref: '#/components/schemas/ReportFilter'
        grain:
          type: string
          enum:
            - day
            - week
            - month
        limit:
          type: integer
        range:
          type: string
          example: 2026-09-01..2026-10-01
        shape:
          type: string
          enum:
            - timeseries
            - breakdown
            - scalar
        sort:
          type: array
          items:
            $ref: '#/components/schemas/ReportSort'
    AnalyticsQueryResult:
      type: object
      properties:
        columns:
          type: array
          items:
            $ref: '#/components/schemas/AnalyticsColumn'
        meta:
          $ref: '#/components/schemas/AnalyticsQueryMeta'
        rows:
          type: array
          items:
            type: array
            items:
              type: string
    errors.ErrorResponse:
      type: object
      properties:
        code:
          $ref: '#/components/schemas/errors.ErrorCode'
        http_status_code:
          type: integer
        message:
          type: string
      x-speakeasy-name-override: ErrorResponse
    ReportFilter:
      type: object
      properties:
        field:
          type: string
        op:
          type: string
          enum:
            - eq
            - in
        value:
          type: array
          items:
            type: string
    ReportSort:
      type: object
      properties:
        dir:
          type: string
          enum:
            - asc
            - desc
        field:
          type: string
    AnalyticsColumn:
      type: object
      properties:
        currency:
          type: string
        name:
          type: string
        role:
          $ref: '#/components/schemas/types.ColumnRole'
        type:
          $ref: '#/components/schemas/types.ColumnType'
    AnalyticsQueryMeta:
      type: object
      properties:
        from:
          type: string
        prev_from:
          type: string
        prev_to:
          type: string
        query_source:
          type: string
        to:
          type: string
    errors.ErrorCode:
      type: string
      enum:
        - http_client_error
        - system_error
        - internal_error
        - not_found
        - already_exists
        - version_conflict
        - validation_error
        - invalid_operation
        - permission_denied
        - database_error
        - service_unavailable
        - too_many_requests
        - not_implemented
      x-enum-varnames:
        - ErrCodeHTTPClient
        - ErrCodeSystemError
        - ErrCodeInternalError
        - ErrCodeNotFound
        - ErrCodeAlreadyExists
        - ErrCodeVersionConflict
        - ErrCodeValidation
        - ErrCodeInvalidOperation
        - ErrCodePermissionDenied
        - ErrCodeDatabase
        - ErrCodeServiceUnavailable
        - ErrCodeTooManyRequests
        - ErrCodeNotImplemented
      x-speakeasy-name-override: ErrorCode
    types.ColumnRole:
      type: string
      enum:
        - dimension
        - metric
      x-enum-varnames:
        - ColumnRoleDimension
        - ColumnRoleMetric
      x-speakeasy-name-override: ColumnRole
    types.ColumnType:
      type: string
      enum:
        - string
        - decimal
        - datetime
      x-enum-varnames:
        - ColumnTypeString
        - ColumnTypeDecimal
        - ColumnTypeDatetime
      x-speakeasy-name-override: ColumnType
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      description: Enter your API key in the format *x-api-key &lt;api-key&gt;**
      name: x-api-key
      in: header

````

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