---
title: "Get a document (with input)"
method: POST
path: "/v1/data/{path}"
tags: ["Data API"]
---

# Get a document (with input)

`POST /v1/data/{path}`

The server will return a *bad request* (400) response if either:
- The query requires an input document and you do not provide it
- You provided an input document but the query has already defined it.

If `path` indexes into an array, the server will attempt to convert the array index to an integer. If the path element cannot be converted to an integer, a *not found* response (404) will be returned.

## Query parameters

- `pretty` boolean
- `provenance` boolean
- `explain` string
- `metrics` boolean
- `instrument` boolean

## Response `200`

Success

- object
  - `result` object[]
    - `id` string — The name of a policy module
    - `raw` string — A string representation of the full Rego policy
    - `ast` object — The types for declarations and runtime objects passed to your implementation. This consists of an abstract syntax tree (AST) of policy modules, package and import declarations, rules, expressions, and terms.
      - `package` object
        - `path` object[] — The path to the package
          - `type` 'import' | 'package' — The type of the path operation
          - `value` string — The path variable
      - `rules` object[] — When OPA evaluates a rule, it generates the content of a [virtual documents](https://www.openpolicyagent.org/docs/latest/philosophy/#the-opa-document-model)
        - `head` object
          - `name` string — The head of the rule
          - `key` object — The type/value pairing for this rule's head
            - `type` string — The type of the head
            - `value` string — The value of the head
        - `body` object[] — A list of the terms in this rule
          - `index` number — The location of this term in the list (starts at 0)
          - `terms` object[] — The type/value pairing for this term
            - `type` string — The type of the term variable
            - `value` object[] — The list of types and values for the term variable
              - …
  - `provenance` object
    - `version` string — The version of this OPA instance
    - `build_commit` string — The Git commit id of this OPA build.
    - `build_timestamp` string — When this OPA instance was built (in [ISO8601 format](https://www.w3.org/TR/NOTE-datetime))
    - `build_hostname` string — The hostname where this instance was built.
    - `bundles` object — A set of key-value pairs describing each bundle activated on the server.
  - `metrics` object
    - `timer_rego_input_parse_ns` number — Time taken (in nanonseconds) to parse the input
    - `timer_rego_query_parse_ns` number — Time taken (in nanoseconds) to parse the query
    - `timer_rego_query_compile_ns` number — Time taken (in nanoseconds) to compile the query
    - `timer_rego_query_eval_ns` number — Time taken (in nanonseconds) to evaluate the query
    - `timer_rego_module_parse_ns` number — Time taken (in nanoseconds) to parse the input policy module
    - `timer_rego_module_compile_ns` number — Time taken (in nanonseconds) to compile the loaded policy modules
    - `timer_server_handler_ns` number — Time taken (in nanoseconds) to handle the API request
    - `timer_server_read_bytes_ns` number — *Description is forthcoming*
    - `counter_server_query_cache_hit` number — *Description is forthcoming*
    - `timer_query_compile_stage_build_comprehension_index_ns` number — (Only returned if `instrument` is true.) *Description is forthcoming*
    - `timer_query_compile_stage_check_safety_ns` number — (Only returned if `instrument` is true.) *Description is forthcoming*
    - `timer_query_compile_stage_check_types_ns` number — (Only returned if `instrument` is true.) *Description is forthcoming*
    - `timer_query_compile_stage_check_undefined_funcs_ns` number — (Only returned if `instrument` is true.) *Description is forthcoming*
    - `timer_query_compile_stage_check_unsafe_builtins_ns` number — (Only returned if `instrument` is true.) *Description is forthcoming*
    - `timer_query_compile_stage_resolve_refs_ns` number — (Only returned if `instrument` is true.) *Description is forthcoming*
    - `timer_query_compile_stage_rewrite_comprehension_terms_ns` number — (Only returned if `instrument` is true.) *Description is forthcoming*
    - `timer_query_compile_stage_rewrite_dynamic_terms_ns` number — (Only returned if `instrument` is true.) *Description is forthcoming*
    - `timer_query_compile_stage_rewrite_expr_terms_ns` number — (Only returned if `instrument` is true.) *Description is forthcoming*
    - `timer_query_compile_stage_rewrite_local_vars_ns` number — (Only returned if `instrument` is true.) *Description is forthcoming*
    - `timer_query_compile_stage_rewrite_to_capture_value_ns` number — (Only returned if `instrument` is true.) *Description is forthcoming*
    - `timer_query_compile_stage_rewrite_with_values_ns` number — (Only returned if `instrument` is true.) *Description is forthcoming*
  - `explanation` object[]
    - `op` 'enter' | 'exit' | 'eval' | 'fail' | 'redo' — The kind of *trace event* Each trace event represents a step in the query evaluation process. Trace events are emitted at the following points: - enter - before a body or rule is evaluated - exit - after a body or rule has evaluated successfully - eval - before an expression is evaluated - fail - after an expression has evaluated to false. - redo - before evaluation restarts from a body, rule, or expression. By default, OPA searches for all sets of term bindings that make all expressions in the query evaluate to true. Because there may be multiple answers, the search can restart when OPA determines the query is true or false. When the search restarts, a *redo trace event* is emitted.
    - `query_id` number — The query that the trace event was emitted for. Use this field to distinguish trace events emitted by from different queries.
    - `parent_id` number — The parent query. Use this field to identify trace events from related queries. For example, if query A references rule R, trace events emitted when evaluating rule R will have the *parent_id* field set to query A’s *query_id*.
    - `type` 'expr' | 'rule' | 'body' — The type of the **node** field
    - `node` object — The AST element associated with the evaluation step.
      - `index` number — Node number
      - `terms` object[]
        - `type` string
        - `value` string
    - `locals` object[] — The query's term bindings at the point when the trace event was emitted.
      - `key` object
        - `type` string
        - `value` string
      - `value` object
        - `type` string
        - `value` string

## Other responses

- `400` — Bad request
- `500` — Server error

---

[API](https://skmtc.net/open-policy-agent/apis/open-policy-agent-opa-rest-api.md) · [All operations](https://skmtc.net/open-policy-agent/apis/open-policy-agent-opa-rest-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/open-policy-agent/open-policy-agent-opa-rest-api/revisions/47f6f2062932/schema)
