---
updatedAt: 2026-09-17T21:36:03.000Z
agentTools:
  projectIndex: https://docs.observeinc.com/llms.txt
---

# Execute an OPAL query

Execute an OPAL query.

Results can be returned as CSV or NDJSON.
* Set Accept header to `text/csv` or `application/x-ndjson`
* Default: CSV

Either two of `startTime`, `endTime`, and `interval` or `interval` alone can be specified to set the time interval. The `startTime` parameter is inclusive and the `endTime` parameter is exclusive, to prevent overlap from subsequent windows.

* `interval`: An interval relative to now
* `startTime` + `endTime`: The specified time interval
* `startTime` **or** `endTime` + `interval`: The specified time interval relative to the provided start or end time

Inputs are specified as dataset IDs, or previously-defined stages.

Set paginate to true for an asynchronous paginated mode. The response will be 202 Accepted and contain headers for fetching the results via `/v1/meta/export/query/page`. You may also want to increase rowCount to allow large, paginated queries.


# OpenAPI definition

````json
{
  "openapi": "3.1.0",
  "info": {
    "title": "Observe by Snowflake API",
    "description": "# Overview\nWelcome to the Observe API Docs!\n\nThe Observe API is a RESTful API. POST bodies and responses are typically JSON-encoded.\n\n## Authentication\nRequests to the Observe API are authenticated with an API token. The token can be supplied using HTTP Bearer authentication:\n```\n// passing token as bearer token\ncurl -H \"Authorization: Bearer <customerid> <token>\" https://<customerid>.<observe-domain>.com/v1/...\n```\n",
    "version": "1.0.230307"
  },
  "servers": [
    {
      "url": "https://{customerid}.observeinc.com",
      "description": "US west server",
      "variables": {
        "customerid": {
          "default": "OBSERVE_CUSTOMERID",
          "description": "The customer ID for your instance."
        }
      }
    },
    {
      "url": "https://{customerid}.{cluster}.observeinc.com",
      "description": "Specific regional cluster (prod)",
      "variables": {
        "customerid": {
          "default": "OBSERVE_CUSTOMERID",
          "description": "The customer ID for your instance."
        },
        "cluster": {
          "enum": [
            "eu-1",
            "ap-1"
          ],
          "default": "eu-1",
          "description": "For regional clusters, choose one."
        }
      }
    },
    {
      "url": "https://{customerid}.{domain}.com",
      "description": "Specific Observe server",
      "variables": {
        "customerid": {
          "default": "OBSERVE_CUSTOMERID",
          "description": "The customer ID for your instance."
        },
        "domain": {
          "default": "OBSERVE_DOMAIN",
          "description": "The Observe domain for your instance."
        }
      }
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Export",
      "description": "Export query results from Observe.\n"
    }
  ],
  "paths": {
    "/v1/meta/export/query": {
      "post": {
        "summary": "Execute an OPAL query",
        "operationId": "exportQuery",
        "tags": [
          "Export"
        ],
        "description": "Execute an OPAL query.\n\nResults can be returned as CSV or NDJSON.\n* Set Accept header to `text/csv` or `application/x-ndjson`\n* Default: CSV\n\nEither two of `startTime`, `endTime`, and `interval` or `interval` alone can be specified to set the time interval. The `startTime` parameter is inclusive and the `endTime` parameter is exclusive, to prevent overlap from subsequent windows.\n\n* `interval`: An interval relative to now\n* `startTime` + `endTime`: The specified time interval\n* `startTime` **or** `endTime` + `interval`: The specified time interval relative to the provided start or end time\n\nInputs are specified as dataset IDs, or previously-defined stages.\n\nSet paginate to true for an asynchronous paginated mode. The response will be 202 Accepted and contain headers for fetching the results via `/v1/meta/export/query/page`. You may also want to increase rowCount to allow large, paginated queries.\n",
        "parameters": [
          {
            "name": "startTime",
            "in": "query",
            "description": "Beginning of time window (inclusive) as ISO time.",
            "schema": {
              "type": "string"
            },
            "required": false,
            "examples": {
              "A start time": {
                "value": "2023-04-20T16:20:00Z"
              }
            }
          },
          {
            "name": "endTime",
            "in": "query",
            "description": "End of time window (exclusive) as ISO time. Defaults to now if just `interval` is specified.",
            "schema": {
              "type": "string"
            },
            "required": false,
            "examples": {
              "An end time": {
                "value": "2023-04-20T16:30:00Z"
              }
            }
          },
          {
            "name": "interval",
            "in": "query",
            "description": "Length of time window (if start or end is missing).",
            "schema": {
              "type": "string"
            },
            "required": false,
            "examples": {
              "An interval": {
                "value": "10m",
                "summary": "A duration in h / m / s units"
              }
            }
          },
          {
            "name": "stage",
            "in": "query",
            "description": "Which stage to get the data from. Defaults to last stage.",
            "schema": {
              "type": "string"
            },
            "required": false
          },
          {
            "name": "paginate",
            "in": "query",
            "description": "Whether to switch to an asynchronous paginated mode. Defaults to false.",
            "schema": {
              "type": "boolean"
            },
            "required": false
          }
        ],
        "requestBody": {
          "description": "The OPAL query text and input dataset bindings.",
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "query"
                ],
                "properties": {
                  "query": {
                    "description": "Encodes the actual OPAL query and its inputs.",
                    "type": "object",
                    "required": [
                      "stages"
                    ],
                    "properties": {
                      "outputStage": {
                        "type": "string",
                        "description": "The name of the stage that will be used as output. Defaults to the last specified stage."
                      },
                      "stages": {
                        "type": "array",
                        "description": "Describes one or more stage pipelines to execute. Stages can reference each other, but not in a cyclic fashion.",
                        "items": {
                          "type": "object",
                          "required": [
                            "input",
                            "stageID",
                            "pipeline"
                          ],
                          "properties": {
                            "input": {
                              "description": "Describes the @name bindings for input datasets or stages. The first input is provided as the default input to the pipeline.",
                              "type": "array",
                              "items": {
                                "$ref": "#/components/schemas/InputDefinition"
                              }
                            },
                            "stageID": {
                              "description": "The ID to assign to this stage when binding as input to other datasets.",
                              "type": "string"
                            },
                            "pipeline": {
                              "description": "The actual OPAL pipeline to execute. You can use embedded newlines,\nor the pipe | character to separate verb clauses. You can include\nembedded sub-queries, too.\n",
                              "type": "string"
                            },
                            "parameters": {
                              "$ref": "#/components/schemas/ParameterArray"
                            },
                            "parameterValues": {
                              "$ref": "#/components/schemas/ParameterValueArray"
                            }
                          }
                        }
                      },
                      "parameters": {
                        "$ref": "#/components/schemas/ParameterArray"
                      },
                      "parameterValues": {
                        "$ref": "#/components/schemas/ParameterValueArray"
                      }
                    }
                  },
                  "rowCount": {
                    "description": "The maximum number of rows to return. Defaults to 100,000, which is the maximum if paginate=false. If paginate=true rowCount can be up to the maximum value of int64 (9,223,372,036,854,775,807).",
                    "type": "string",
                    "format": "int64",
                    "minimum": 0,
                    "maximum": 100000
                  },
                  "presentation": {
                    "$ref": "#/components/schemas/StagePresentationInput"
                  }
                }
              },
              "example": {
                "query": {
                  "outputStage": "myStage",
                  "stages": [
                    {
                      "input": [
                        {
                          "inputName": "main",
                          "datasetId": "41007104"
                        },
                        {
                          "inputName": "rds",
                          "datasetPath": "Workspace.aws/RDS Cluster"
                        }
                      ],
                      "stageID": "myStage",
                      "pipeline": "pick_col timestamp, log, namespace, containerName, rdsArn\nleftjoin on(rdsArn=@rds.arn), db:@rds.DBClusterIdentifier\n"
                    }
                  ]
                },
                "rowCount": "2"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "## Description of result data formats\n\n### Content-type: application/x-ndjson\nThe results are returned with each row represented as distinct json objects separated by newlines.\nThe contents of the json object representing each row is keys representing each column in the output, with values representing the value of that that column for that row.\n\n### Content-type: text/csv\nThe results are returned in csv format, the first row in csv is a header row with the names of the columns.\n",
            "content": {
              "application/x-ndjson": {
                "schema": {
                  "type": "string"
                },
                "example": "{\"timestamp\":\"2023-03-08T18:59:42.397994726Z\",\"log\":\"I0308 18:59:42.397931             60689787 apiserver/authorize.go:545] msg=\\\"VerifyAuthorization failed\\\" customer_id=999999999999 service=collector operation=2 token=\\\"xxxxxx... (hash h:xxxxxxx)\\\"\",\"namespace\":\"prod\",\"containerName\":\"collector\"}\n{\"timestamp\":\"2023-03-08T18:59:42.674391618Z\",\"log\":\"I0308 18:59:42.397945             60689787 httputil/helpers.go:70] serveStatusError(401): \\\"Unauthorized\\\"\",\"namespace\":\"prod\",\"containerName\":\"collector\"}\n"
              },
              "text/csv": {
                "schema": {
                  "type": "string"
                },
                "example": "\"timestamp\",\"log\",\"namespace\",\"containerName\"\n\"2023-03-08T18:59:42.397994726Z\",\"I0308 18:59:42.397931             60689787 apiserver/authorize.go:545] msg=\"\"VerifyAuthorization failed\"\" customer_id=999999999999 service=collector operation=2 token=\"\"xxxxxx... (hash h:xxxxxxx)\"\"\",\"prod\",\"collector\"\n\"2023-03-08T18:59:42.674391618Z\",\"I0308 18:59:42.397945             60689787 httputil/helpers.go:70] serveStatusError(401): \"\"Unauthorized\"\"\",\"prod\",\"collector\"\n"
              }
            }
          },
          "202": {
            "description": "The paginated query request was accepted and will be executed asynchronously.  The response contains two headers that can be used to fetch the results.  There is no body sent.",
            "headers": {
              "X-Observe-Cursor-Id": {
                "schema": {
                  "type": "string"
                },
                "description": "The ID of a cursor that can be used to fetch the results; to be used with the /v1/meta/export/query/page endpoint.  See that endpoint for more details."
              },
              "X-Observe-Next-Page": {
                "schema": {
                  "type": "string"
                },
                "description": "A link to the first page of results, which will contain the cursor ID query parameter, but will omit the offset and numRows query parameters.\nThose defaults can be overriden by adding them to the query parameters.\n"
              }
            }
          },
          "206": {
            "description": "The query was executed successfully, but the results returned cover only a part of the query window. This happens when the datasets queried are not accelerated for the entire query window.\n## Description of result data formats\n\n### Content-type: application/x-ndjson\nThe results are returned with each row represented as distinct json objects separated by newlines.\nThe contents of the json object representing each row is keys representing each column in the output, with values representing the value of that that column for that row.\n\n### Content-type: text/csv\nThe results are returned in csv format, the first row in csv is a header row with the names of the columns.\n",
            "content": {
              "application/x-ndjson": {
                "schema": {
                  "type": "string"
                },
                "example": "{\"timestamp\":\"2023-03-08T18:59:42.397994726Z\",\"log\":\"I0308 18:59:42.397931             60689787 apiserver/authorize.go:545] msg=\\\"VerifyAuthorization failed\\\" customer_id=999999999999 service=collector operation=2 token=\\\"xxxxxx... (hash h:xxxxxxx)\\\"\",\"namespace\":\"prod\",\"containerName\":\"collector\"}\n{\"timestamp\":\"2023-03-08T18:59:42.674391618Z\",\"log\":\"I0308 18:59:42.397945             60689787 httputil/helpers.go:70] serveStatusError(401): \\\"Unauthorized\\\"\",\"namespace\":\"prod\",\"containerName\":\"collector\"}\n"
              },
              "text/csv": {
                "schema": {
                  "type": "string"
                },
                "example": "\"timestamp\",\"log\",\"namespace\",\"containerName\"\n\"2023-03-08T18:59:42.397994726Z\",\"I0308 18:59:42.397931             60689787 apiserver/authorize.go:545] msg=\"\"VerifyAuthorization failed\"\" customer_id=999999999999 service=collector operation=2 token=\"\"xxxxxx... (hash h:xxxxxxx)\"\"\",\"prod\",\"collector\"\n\"2023-03-08T18:59:42.674391618Z\",\"I0308 18:59:42.397945             60689787 httputil/helpers.go:70] serveStatusError(401): \"\"Unauthorized\"\"\",\"prod\",\"collector\"\n"
              }
            }
          },
          "400": {
            "description": "Query not accepted."
          },
          "401": {
            "description": "Authorization missing."
          },
          "403": {
            "description": "Authorization denied."
          },
          "429": {
            "description": "Rate limit exceeded."
          },
          "500": {
            "description": "Internal error: query error."
          },
          "504": {
            "description": "Internal error: infrastructure error."
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "Authorization: Bearer <customerid> <apitoken>\n"
      }
    },
    "schemas": {
      "InputDefinition": {
        "type": "object",
        "required": [
          "inputName"
        ],
        "properties": {
          "inputName": {
            "description": "The @name used to reference this input in OPAL (without the @ sign)",
            "type": "string"
          },
          "inputRole": {
            "description": "Data or Reference, defaults to Data if not specified.",
            "type": "string"
          },
          "datasetId": {
            "description": "The dataset ID (as int64-string) to bind to this name.",
            "type": "string",
            "format": "int64"
          },
          "datasetPath": {
            "description": "The dataset name as Workspace.path/Name to bind to this name. datasetId takes precedence if both are set; on read, this is populated alongside datasetId as a portable reference.",
            "type": "string"
          },
          "stageId": {
            "description": "The stageID of the previously defined stage to reference, if it's a stage and not a dataset.",
            "type": "string"
          },
          "parameterId": {
            "description": "The parameter ID to take the input dataset reference from. (Advanced usage only)",
            "type": "string"
          }
        }
      },
      "ParameterArray": {
        "description": "Parameters defined for $variables (used for default values)",
        "type": "array",
        "items": {
          "type": "object",
          "required": [
            "id",
            "valueKind",
            "defaultValue"
          ],
          "properties": {
            "id": {
              "type": "string"
            },
            "name": {
              "type": "string"
            },
            "defaultValue": {
              "type": "object",
              "properties": {
                "bool": {
                  "type": "boolean"
                },
                "float64": {
                  "type": "number"
                },
                "int64": {
                  "type": "string",
                  "format": "int64"
                },
                "string": {
                  "type": "string"
                },
                "timestamp": {
                  "type": "string"
                },
                "duration": {
                  "type": "string"
                },
                "nullValueType": {
                  "type": "string"
                }
              }
            },
            "valueKind": {
              "type": "object",
              "required": [
                "type"
              ],
              "properties": {
                "type": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "ParameterValueArray": {
        "description": "Parameter values bound for $variables for this execution.",
        "type": "array",
        "items": {
          "type": "object",
          "required": [
            "id",
            "value"
          ],
          "properties": {
            "id": {
              "type": "string"
            },
            "value": {
              "type": "object",
              "properties": {
                "bool": {
                  "type": "boolean"
                },
                "float64": {
                  "type": "number"
                },
                "int64": {
                  "type": "string",
                  "format": "int64"
                },
                "string": {
                  "type": "string"
                },
                "timestamp": {
                  "type": "string"
                },
                "duration": {
                  "type": "string"
                },
                "nullValueType": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "StagePresentationInput": {
        "type": "object",
        "properties": {
          "limit": {
            "type": "string",
            "format": "int64"
          },
          "linkify": {
            "description": "Turn foreign keys into joined-name columns.",
            "type": "boolean"
          },
          "wantBuckets": {
            "description": "How many timechart / aggregate buckets to use by default.",
            "type": "string",
            "format": "int64"
          },
          "orderColumns": {
            "description": "How to order the output data.",
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "columnName"
              ],
              "properties": {
                "columnName": {
                  "type": "string"
                },
                "ascending": {
                  "type": "boolean"
                },
                "nullOrdering": {
                  "type": "boolean"
                }
              }
            }
          }
        }
      }
    }
  }
}
````