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

# 解析面板查询

> 把面板查询绑定到数据源并完成变量替换，但不执行。



## OpenAPI

````yaml /api-reference/monitors.openapi.zh.json post /monit/dashboard/runtime/queries/resolve
openapi: 3.1.0
info:
  title: Flashduty 开放 API
  description: >-
    Flashduty 事件管理平台的公开 HTTP API —— 覆盖故障、通知模板、协作空间、值班排班、监控、RUM、以及平台管理。每次调用都需在
    query 中携带 `app_key`，该 key 在 Flashduty 控制台 账户 → APP Key 中签发。所有响应使用统一结构：成功时为
    `{ request_id, data }`，失败时为 `{ request_id, error }`。
  version: 1.0.0
servers:
  - url: https://api.flashcat.cloud
    description: Flashduty Open API
security:
  - AppKeyAuth: []
tags:
  - name: Monitors/告警规则
    description: 创建、管理和导出监控告警规则，查询规则统计和审计历史。
  - name: Monitors/告警数据源
    description: 管理监控告警规则用于查询指标的数据源。
  - name: Monitors/诊断分析
    description: Flashduty AI SRE 使用的诊断与查询接口——数据源即席查询、日志/指标诊断,以及监控对象侧的工具调用。
  - name: Monitors/通用工具
    description: 监控服务开通及数据预览工具。
  - name: Monitors/仪表盘
    description: 创建、搜索、版本化与运行 Monitors 仪表盘，并解析其变量与查询。
  - name: Monitors/规则分组
    description: 列出仪表盘与告警规则所在的监控节点树。
paths:
  /monit/dashboard/runtime/queries/resolve:
    post:
      tags:
        - Monitors/仪表盘
      summary: 解析面板查询
      description: 把面板查询绑定到数据源并完成变量替换，但不执行。
      operationId: monit-dashboard-query-read-resolve
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DashboardQueriesResolveRequest'
            example:
              dashboard_id: 01990d7a-9c5b-7ab0-9c18-33e38f6f2101
              panel_ids:
                - 01990d7a-9c5b-7ab0-9c18-33e38f6f2404
              time:
                from_ms: 1791100800000
                to_ms: 1791104400000
              variables:
                env:
                  kind: values
                  values:
                    - prod
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/SuccessEnvelope'
                  - type: object
                    properties:
                      data:
                        $ref: '#/components/schemas/DashboardQueriesResolveResponse'
              example:
                request_id: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
                data:
                  dashboard_id: 01990d7a-9c5b-7ab0-9c18-33e38f6f2101
                  revision: 7
                  time:
                    from_ms: 1791100800000
                    to_ms: 1791104400000
                  variables:
                    env:
                      kind: values
                      values:
                        - prod
                  panels:
                    - panel_id: 01990d7a-9c5b-7ab0-9c18-33e38f6f2404
                      state: success
                      queries:
                        - ref_id: A
                          datasource:
                            id: 10
                            type: prometheus
                            name: Prometheus Prod
                          mode: range
                          expr: sum(rate(http_requests_total{env="prod"}[5m]))
                          args: {}
                          min_step_seconds: 30
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '500':
          $ref: '#/components/responses/ServerError'
components:
  schemas:
    DashboardQueriesResolveRequest:
      type: object
      description: 只解析所选面板的查询而不执行，便于客户端预览数据源绑定与变量替换结果。
      properties:
        dashboard_id:
          type: string
          pattern: >-
            ^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$
          description: 仪表盘的 canonical UUIDv7。
        panel_ids:
          type: array
          items:
            type: string
            pattern: >-
              ^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$
          minItems: 1
          maxItems: 100
          description: 要解析的面板，1～100 个唯一 ID。面板不存在时产生 `error` 分支，而不会让调用失败。
        time:
          $ref: '#/components/schemas/DashboardAbsoluteTimeRange'
        variables:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/DashboardSelection'
          description: 按变量名索引的选择，最多 20 项。
      required:
        - dashboard_id
        - panel_ids
        - time
        - variables
    SuccessEnvelope:
      type: object
      description: >-
        成功响应结构。2xx 响应中 `request_id` 标识本次调用（同时出现在 `Flashcat-Request-Id`
        响应头中），`data` 为接口业务 payload。失败响应使用不同结构，参见 `ErrorResponse`。
      properties:
        request_id:
          type: string
          description: 本次请求的唯一 ID，也会在 Flashcat-Request-Id 响应头中返回。反馈问题时请一并附上。
          example: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
        data:
          description: 每个接口自己的业务 payload，详见各接口的 200 响应 schema。
      required:
        - request_id
        - data
    DashboardQueriesResolveResponse:
      type: object
      description: 每个请求的面板对应一个条目，顺序与请求一致。
      properties:
        dashboard_id:
          type: string
          pattern: >-
            ^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$
          description: 仪表盘 ID。
        revision:
          type: integer
          format: uint64
          minimum: 1
          description: 本次解析所依据的版本号。
        time:
          $ref: '#/components/schemas/DashboardAbsoluteTimeRange'
        variables:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/DashboardSelection'
          description: 解析成功的变量选择。
        panels:
          type: array
          items:
            $ref: '#/components/schemas/DashboardResolvedPanelQueries'
          description: 每个面板的结果。
      required:
        - dashboard_id
        - revision
        - time
        - variables
        - panels
    DashboardAbsoluteTimeRange:
      type: object
      description: >-
        绝对求值窗口。两个边界都是 Unix 毫秒时间戳，`from_ms` 必须小于 `to_ms`，且都不得超过 JavaScript
        安全整数上限。
      properties:
        from_ms:
          type: integer
          format: int64
          minimum: 0
          description: Unix 时间戳（毫秒）。
        to_ms:
          type: integer
          format: int64
          minimum: 1
          description: Unix 时间戳（毫秒）。
      required:
        - from_ms
        - to_ms
    DashboardSelection:
      type: object
      description: 变量取值的具体选择。空的 `values` 数组是合法输入，表示未解析——服务端不会为其回退到默认值。
      properties:
        kind:
          type: string
          enum:
            - values
            - all
          description: '`values` 选择列出的项，`all` 表示全选（仅当 `include_all` 为 true 时可用）。'
        values:
          type: array
          items:
            type: string
            minLength: 1
            maxLength: 1024
          maxItems: 1000
          description: 已选值，需唯一且不得为 `$__all`。`kind` 为 `all` 时必须为空。
      required:
        - kind
    DashboardResolvedPanelQueries:
      type: object
      description: 单个面板的解析结果。所有查询都成功时 `state` 为 `success`，部分成功为 `partial`，全部失败为 `error`。
      properties:
        panel_id:
          type: string
          pattern: >-
            ^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$
          description: 面板 ID。
        state:
          type: string
          enum:
            - success
            - partial
            - error
          description: 该面板查询的整体状态：`success` = 全部查询解析成功；`partial` = 部分成功；`error` = 全部失败。
        queries:
          type: array
          items:
            $ref: '#/components/schemas/DashboardResolvedQuery'
          description: 解析成功的查询。
        error:
          $ref: '#/components/schemas/DashboardRuntimeError'
      required:
        - panel_id
        - state
        - queries
    ErrorResponse:
      type: object
      description: 错误响应结构。`error` 必填，`data` 不存在。
      properties:
        request_id:
          type: string
          example: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
          description: 本次请求的唯一追踪 ID（trace ID），反馈问题时请提供该值以便检索日志。
        error:
          $ref: '#/components/schemas/DutyError'
      required:
        - request_id
        - error
    DashboardResolvedQuery:
      type: object
      description: 一条已绑定到具体数据源、且变量已替换完成的查询。
      properties:
        ref_id:
          type: string
          pattern: ^[A-Z]$
          description: 面板内的查询引用名。
        datasource:
          $ref: '#/components/schemas/DashboardRuntimeDatasource'
        mode:
          type: string
          enum:
            - range
            - instant
            - window
          description: 求值模式：`range` = 按步长采样的时序；`instant` = 单个时间点；`window` = 有界时间窗口内的原始行。
        expr:
          type: string
          description: 已完成变量替换的表达式。
        args:
          type: object
          additionalProperties:
            type: string
          description: 查询参数；无参数时为空对象。
        min_step_seconds:
          type:
            - integer
            - 'null'
          format: int64
          minimum: 1
          description: 最小步长（秒）；未设置时为 null。
      required:
        - ref_id
        - datasource
        - mode
        - expr
        - args
    DashboardRuntimeError:
      type: object
      description: 变量级或查询级的失败。单个分支失败不会导致整个调用失败。
      properties:
        reason:
          type: string
          description: >-
            机器可读的失败原因。已观察到的取值包括
            `invalid_request`、`variable_invalid`、`panel_missing`、`field_missing`、`datasource_permission_denied`、`timeout`、`panel_deadline`、`panel_canceled`、`canceled`、`overloaded`、`source_too_large`、`edge_unavailable`、`edge_upgrade_required`、`edge_version_unknown`、`mixed_edge_versions`、`internal`。
        message:
          type: string
          description: 失败的可读详情。
      required:
        - reason
        - message
    DutyError:
      type: object
      description: 响应结构中的错误 payload，仅在非 2xx 响应时出现。
      properties:
        code:
          $ref: '#/components/schemas/ErrorCode'
        message:
          type: string
          description: 用户可读的错误描述，语言会跟随调用方的 Accept-Language。可能包含字段名、ID 等请求上下文。
          example: The specified parameter template_id is not valid.
        reason:
          description: 可选的机器可读拒绝原因，包含数据源工具错误；结合 HTTP 状态及 code 判断。
          type: string
          x-flashduty-preserve-absence: true
      required:
        - code
        - message
    DashboardRuntimeDatasource:
      type: object
      description: 运行时查询实际绑定的数据源。
      properties:
        id:
          type: integer
          format: uint64
          minimum: 1
          description: 数据源 ID。
        type:
          type: string
          pattern: ^[a-z][a-z0-9_]{0,63}$
          description: 数据源类型标识。
        name:
          type: string
          description: 数据源名称。
      required:
        - id
        - type
        - name
    ErrorCode:
      type: string
      description: >-
        Flashduty 错误码枚举。每个失败响应的 `error.code` 都是下列稳定值之一，HTTP 状态码仅作参考。


        | 错误码 | HTTP | 含义 |

        |---|---|---|

        | `OK` | 200 | 保留值，正常错误响应不会返回。 |

        | `InvalidParameter` | 400 | 必填参数缺失或未通过校验。 |

        | `BadRequest` | 400 | 通用的 400 错误，通常是请求本身不合法。 |

        | `InvalidContentType` | 400 | 请求头 `Content-Type` 不是 `application/json`。
        |

        | `ResourceNotFound` | 400 | 目标资源不存在。注意 HTTP 状态码是 400 而非 404（历史设计）。 |

        | `NoLicense` | 400 | 功能需要有效授权，但未找到可用的 license。 |

        | `ReferenceExist` | 400 | 该资源仍被其他实体引用，无法删除。 |

        | `Unauthorized` | 401 | `app_key` 缺失、无效或已过期。 |

        | `BalanceNotEnough` | 402 | 账户余额不足，无法执行需要计费的操作。 |

        | `AccessDenied` | 403 | 身份认证通过，但 RBAC 权限不足以执行该操作。 |

        | `RouteNotFound` | 404 | 请求的 URL 路径不是已知路由。 |

        | `MethodNotAllowed` | 405 | 当前路径不接受所使用的 HTTP 方法。 |

        | `UndonedOrderExist` | 409 | 账户存在未完成的订单，请稍后重试。 |

        | `RequestLocked` | 423 | 因连续失败被临时锁定。 |

        | `EntityTooLarge` | 413 | 请求体超过允许的最大长度。 |

        | `RequestTooFrequently` | 429 | 命中限流（全局、账户级或集成级）。 |

        | `RequestVerifyRequired` | 428 | 操作需要二次验证码，但未提供。 |

        | `DangerousOperation` | 428 | 危险操作，需要进行 MFA 验证。 |

        | `InternalError` | 500 | 服务端未预期错误。反馈问题请附上 `request_id`。 |

        | `ServiceUnavailable` | 503 | 后端依赖不可用，请稍后重试。 |
      enum:
        - OK
        - InvalidParameter
        - BadRequest
        - InvalidContentType
        - ResourceNotFound
        - NoLicense
        - ReferenceExist
        - Unauthorized
        - BalanceNotEnough
        - AccessDenied
        - RouteNotFound
        - MethodNotAllowed
        - UndonedOrderExist
        - RequestLocked
        - EntityTooLarge
        - RequestTooFrequently
        - RequestVerifyRequired
        - DangerousOperation
        - InternalError
        - ServiceUnavailable
      x-enumDescriptions:
        OK: 保留值，正常错误响应不会返回。
        InvalidParameter: 必填参数缺失或未通过校验。
        BadRequest: 通用的 400 错误，通常是请求本身不合法。
        InvalidContentType: 请求头 `Content-Type` 不是 `application/json`。
        ResourceNotFound: 目标资源不存在。注意 HTTP 状态码是 400 而非 404（历史设计）。
        NoLicense: 功能需要有效授权，但未找到可用的 license。
        ReferenceExist: 该资源仍被其他实体引用，无法删除。
        Unauthorized: '`app_key` 缺失、无效或已过期。'
        BalanceNotEnough: 账户余额不足，无法执行需要计费的操作。
        AccessDenied: 身份认证通过，但 RBAC 权限不足以执行该操作。
        RouteNotFound: 请求的 URL 路径不是已知路由。
        MethodNotAllowed: 当前路径不接受所使用的 HTTP 方法。
        UndonedOrderExist: 账户存在未完成的订单，请稍后重试。
        RequestLocked: 因连续失败被临时锁定。
        EntityTooLarge: 请求体超过允许的最大长度。
        RequestTooFrequently: 命中限流（全局、账户级或集成级）。
        RequestVerifyRequired: 操作需要二次验证码，但未提供。
        DangerousOperation: 危险操作，需要进行 MFA 验证。
        InternalError: 服务端未预期错误。反馈问题请附上 `request_id`。
        ServiceUnavailable: 后端依赖不可用，请稍后重试。
      example: InvalidParameter
  responses:
    BadRequest:
      description: 请求非法 — 通常是参数缺失或格式不正确。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            missingParameter:
              value:
                request_id: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
                error:
                  code: InvalidParameter
                  message: The specified parameter is not valid.
    Unauthorized:
      description: app_key 缺失或无效。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            missingAppKey:
              value:
                request_id: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
                error:
                  code: Unauthorized
                  message: You are unauthorized.
    Forbidden:
      description: app_key 有效但没有执行该操作的权限。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            noEditPermission:
              value:
                request_id: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
                error:
                  code: AccessDenied
                  message: Access Denied.
    NotFound:
      description: >-
        目标资源不存在或已被删除。注意：Flashduty 对业务实体的缺失通常返回 HTTP 400 +
        code=`ResourceNotFound`，真正的 404 只用于未知路由。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            resourceMissing:
              value:
                request_id: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
                error:
                  code: ResourceNotFound
                  message: The resource you request is not found
    TooManyRequests:
      description: 命中限流。可能是全局 API 限流、账户级限流或集成级限流。限流按账户聚合。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            rateLimited:
              value:
                request_id: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
                error:
                  code: RequestTooFrequently
                  message: Request too frequently.
    ServerError:
      description: 服务端未预期错误。反馈问题时请携带 request_id。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            internal:
              value:
                request_id: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
                error:
                  code: InternalError
                  message: >-
                    We encountered an internal error, and it has been reported.
                    Please try again later.
  securitySchemes:
    AppKeyAuth:
      type: apiKey
      in: query
      name: app_key
      description: >-
        在 Flashduty 控制台 账户 → APP Key 中签发的 app_key。调用任何公开 API
        时都必须携带。它等同于所属账户的身份凭证，请妥善保管。

````

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