Account · Concept
Analysis queries
An analysis query is one SQL SELECT over your own records: order decisions, traffic decisions and Trace
assessments. You can write it yourself, or a model can write it for you, as Suggestions does to test a draft rule.
Either way it runs in a sandbox that holds only your account's rows, so it can't read anyone else's.
When to use it
- Count how your rules decided over a period, by outcome, rule, country or day.
- Check a draft rule against your labelled orders before you test it properly.
- Answer a one-off question about your traffic or your agents' actions.
How it works
- You send the query and a window.
POST /v1/account/analysis/querieswithsqlandwindow(fromandto, at most 13 months). - We load your rows. For each view the query names, we read your account's records in the window into a fresh sandbox database. Nothing else is in it: no other account's records and none of our own tables.
- The query runs, read-only. It runs as a role that can only read those views, in a read-only transaction, as one statement. Anything that writes, a second statement and the system catalogs are refused.
- You get the rows. At most 1,000 rows and 1 MB come back; past either the result says
truncated. A query still running after 5 seconds is stopped.
The views
GET /v1/account/analysis/views lists every column with its type. Every view has id and created_at.
| View | Rows | A few columns |
|---|---|---|
orders | Order decisions from checkout assessments | outcome, rule_, order_, order_, billing_, label, stopped, bad, clean |
traffic | Traffic decisions, until they expire | decision, class, rule_, agent_, bot_ |
trace_ | Trace assessments | outcome, rule_, agent_, action_, action_ |
On orders, label is the latest outcome you reported for the order. stopped means the order was challenged or
rejected, bad that you reported a chargeback, fraud or refund abuse, and clean that you reported it legitimate.
Together they give the labelled results:
SELECT rule_id,
count(*) FILTER (WHERE stopped AND bad) AS caught,
count(*) FILTER (WHERE stopped AND clean) AS false_alarms,
count(*) FILTER (WHERE NOT stopped AND bad) AS missed
FROM orders
GROUP BY rule_id
ORDER BY caught DESC
Joins between the views are allowed. Personal columns, such as a billing postal prefix or a request path, can be read once your account has accepted the risk score data terms; until then they aren't in the sandbox.
Who can run it
A signed-in member with the Manage policies permission, or an account API key with the scope of each view it reads:
authorize for orders, identify for traffic, trace for trace_evals. Two queries run for an account at once.
Analysis queries aren't billed.
Errors
| Code | When |
|---|---|
analysis_ (400) | The query isn't one SELECT, names a system catalog or no view, or Postgres refused it; or the window is over 13 months or holds more than 50,000 records of one view. The message says which. |
analysis_ (503) | The query passed 5 seconds, or your records couldn't be read. No partial result is returned. |
rate_ (429) | Two queries are already running for your account. |