DBSheriff
by Sun AI and Data

Back to the demo

Run via API

The API lets a program, or a command line, run the same queries as the SQL box. Not a developer? Use Run a SQL instead: it does the same with buttons.

Before you start

  1. Create your login: open Run a SQL, enter your e-mail address and follow the link we send you.
  2. After you sign in, your API token is shown once. Copy it now.
  3. Open a terminal and give the token a name, then run the commands below.

Sample commands

First put your token in a variable: export DBSHERIFF_TOKEN= followed by the token you were shown. These run in bash or zsh; on Windows use the SQL box or a bash shell such as WSL. The SQL box's Copy as curl button writes the same call with the same variable. The commands print only the body, so tell the answers apart by the code word in error.code, not by a number (add -i to a command to see the status line too). On your first query you may get unavailable: see the list at the end of this section.

1. Who am I: your state, your expiry and, under engines, your pseudonym as login (null until your first statement).

curl -sS https://api-demo.dbsheriff.ai/v1/me \
  -H "Authorization: Bearer $DBSHERIFF_TOKEN"

2. The tables, no token needed. Each has a group: sensitive_real and fixture_synthetic are the sensitive ones, decoy the bait, normal_real the regular ones. The quotes keep zsh happy. Names come without their schema, so write financial_data.credit_cards in SQL.

curl -sS "https://api-demo.dbsheriff.ai/v1/tables?engine=postgresql"

3. A regular table. The body holds engine, statement and an optional max_rows; the answer holds your login, the columns and the rows.

curl -sS -X POST https://api-demo.dbsheriff.ai/v1/query \
  -H "Authorization: Bearer $DBSHERIFF_TOKEN" \
  -H "Content-Type: application/json" \
  --data-binary @- <<'JSON'
{"engine": "postgresql",
 "statement": "SELECT gics_sector, COUNT(*) AS companies FROM securities GROUP BY gics_sector ORDER BY companies DESC",
 "max_rows": 20}
JSON

4. A sensitive table: you get the rows, or statement_ended (HTTP 409).

curl -sS -X POST https://api-demo.dbsheriff.ai/v1/query \
  -H "Authorization: Bearer $DBSHERIFF_TOKEN" \
  -H "Content-Type: application/json" \
  --data-binary @- <<'JSON'
{"engine": "postgresql",
 "statement": "SELECT symbol, period_end, revenue, net_income FROM income_statement WHERE symbol = 'AAPL' ORDER BY period_end DESC LIMIT 5"}
JSON

To run another statement from section 4, put it in the statement field on one line. The answers:

Then watch it in the Monitor UI

Open the demo page and click Monitor UI. Each statement you send appears there under your login name (it starts with dv). Statements that look risky can be ended, and a fast burst of them can get your login locked: that is what the demo is for.