HTTP API

To submit a SQL query to the GreptimeDB server via HTTP API, use the following format:

  1. curl -X POST \
  2. -H 'Authorization: Basic {{authentication}}' \
  3. -H 'Content-Type: application/x-www-form-urlencoded' \
  4. -d 'sql={{SQL-statement}}' \
  5. http://{{API-host}}/v1/sql?db={{db-name}}

Method

Use the POST method to submit the SQL statement to the server.

Header

  • Authorization: The credential. Required if you are using GreptimeDB with authentication enabled. Please refer to authentication.
  • Content-Type: application/x-www-form-urlencoded.
  • X-Greptime-Timezone: The time zone for the current SQL query. Optional. Please refer to time zone.

Query params

  • db: The database name. Required if you are using GreptimeDB with authentication enabled. Otherwise, it can be omitted if you are using the default public database.

Body

  • sql: The SQL statement. Required.

Response

The response is a JSON object.

  • code: the result integer code. Zero means success, otherwise failure.
  • output: the SQL executed result, including schema and rows.

Example

Please refer to table management, write data and query data in user guide.