Darwin public API v1

Read the analytics of your Darwin projects.

The API is experimental: a method, a field or a limit can change or go without notice.

Every call needs an API key. Create one on the key management page at /, then send it as Authorization: Bearer <key>. A key reads the organizations you chose when you created it, as long as you can still read them.

The same API as JSON, for a client generator or a tool: OpenAPI 3.1 (REST), OpenRPC 1.3.2 (JSON-RPC and WebSocket), the Darwin description.

API keys

Open the key management page, log in, and create a key. The page shows the key once: copy it then.

Send it on every call as Authorization: Bearer <key>. A call with no key, or with a key that is unknown, revoked or expired, answers UNAUTHENTICATED (HTTP 401) before anything else.

Entry points

Every method answers on the three, with the same params and the same result.

Entry pointHowDocument
RESTPOST /public/v1/api/<method>, the params as the body. The HTTP status carries the error class.OpenAPI 3.1
JSON-RPC 2.0POST https://developer.darwindata.ai/public/v1/json-rpc, one call per request. The answer is HTTP 200, error or not.OpenRPC 1.3.2, or the method rpc.discover
JSON-RPC 2.0 over a WebSocketwss://developer.darwindata.ai/public/v1/ws, one call per text frame, several at once, matched by id.

The description these pages are built from: /public/v1/description.json.

Stability

experimental

Can change or go without notice.

stable

A change keeps the calls that work today working.

deprecated

Still works, and will be removed. Stop using it.

Error classes

Every call can answer the protocol classes (a negative code) and these classes, before its method runs: UNAUTHENTICATED, FORBIDDEN, RATE_LIMITED, UNAVAILABLE. Each method lists the others it can answer.

ClassCodeHTTPMeaning
PARSE_ERROR-32700400

The text is not JSON.

INVALID_REQUEST-32600400

The JSON is not a request: no id, a batch, a wrong jsonrpc.

METHOD_NOT_FOUND-32601404

No method has this name.

INVALID_PARAMS-32602400

The params do not match the input schema of the method.

INTERNAL-32603500

A fault of ours.

UNAUTHENTICATED1401401

The credential is missing, expired or refused.

FORBIDDEN1403403

The caller may not read this resource.

NOT_FOUND1404404

The resource named in the params does not exist in the scope of the call.

NOT_READY1409409

The project has no sealed snapshot yet. Try again later: this is not an empty answer.

INVALID_QUERY1422422

The SQL is not one read-only SELECT, or it failed on the caller's own text.

QUERY_TIMEOUT1408408

The SQL is correct but ran out of the time budget.

QUERY_TOO_LARGE1413413

The SQL is correct but ran out of the memory of its connection. Narrow it.

RATE_LIMITED1429429

The caller sent more calls than its quota.

UNAVAILABLE1503503

A dependency of the service is down. Try again later.

projects/list experimental

The projects your key may read, in all its organizations.

Any key. The answer holds only what the key reads.

Answers the projects of every organization your key reads, from the oldest to the newest.

Page with page.limit and the nextCursor of the previous page. The last page has no nextCursor. A project created after your first page comes on the last page.

The analytics methods read a project only when its state is computed: an assessment of the project completed. While a new assessment runs, the project stays computed, and the analytics methods read the previous assessment until the snapshot of the new one is sealed.

Params

NameTypeRequiredDefaultDescription
pageobjectno{"limit":100}

Which page to return. Omit it for the first page, at the default size.

page.limitinteger (uint32), 1 to 500no100

How many items to return.

page.cursorCursorno

The nextCursor of the previous page. Omit it for the first page.

Result

ProjectSummaryList

Errors

Only the classes of every call.

Examples

A "$projectId" in the params stands for the id of a project your key reads.

The first page

REST:

curl -X POST https://developer.darwindata.ai/public/v1/api/projects/list \
  -H 'Authorization: Bearer <key>' \
  -H 'Content-Type: application/json' \
  -d '{}'

JSON-RPC: send this body to https://developer.darwindata.ai/public/v1/json-rpc, or as a text frame on the WebSocket.

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "projects/list",
  "params": {}
}

Two projects per page

REST:

curl -X POST https://developer.darwindata.ai/public/v1/api/projects/list \
  -H 'Authorization: Bearer <key>' \
  -H 'Content-Type: application/json' \
  -d '{"page":{"limit":2}}'

JSON-RPC: send this body to https://developer.darwindata.ai/public/v1/json-rpc, or as a text frame on the WebSocket.

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "projects/list",
  "params": {
    "page": {
      "limit": 2
    }
  }
}

projects/describe experimental

The relations projects/query can read, and the columns of one.

Scope projectAnalytics: the project must belong to an organization your key reads.

Answers what projects/query can read in a project: every relation, what one row of it is, and worked queries.

Name a relation in relation to get its columns and their SQL types, read from the snapshot of the project. The relations whose kind is fold are computed from the snapshot for the point of view of the query, most of them aggregations: read them rather than rebuild a total from the tables.

The catalogue is the same for every project. The columns need a sealed snapshot of the project: before the first one, the answer is NOT_READY. They are built within 60 seconds; past it, the answer is UNAVAILABLE: retry later.

Params

NameTypeRequiredDefaultDescription
projectIdProjectIdyes

The id of the project, a UUID. projects/list gives the ids your key may read.

relationstringno

A relation of the catalogue, e.g. fold_risks. Give it to get its columns and their types.

Result

ProjectDescription

Errors

NOT_READY, on top of the classes of every call.

Examples

A "$projectId" in the params stands for the id of a project your key reads.

The catalogue

REST:

curl -X POST https://developer.darwindata.ai/public/v1/api/projects/describe \
  -H 'Authorization: Bearer <key>' \
  -H 'Content-Type: application/json' \
  -d '{"projectId":"$projectId"}'

JSON-RPC: send this body to https://developer.darwindata.ai/public/v1/json-rpc, or as a text frame on the WebSocket.

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "projects/describe",
  "params": {
    "projectId": "$projectId"
  }
}

The columns of the risks

REST:

curl -X POST https://developer.darwindata.ai/public/v1/api/projects/describe \
  -H 'Authorization: Bearer <key>' \
  -H 'Content-Type: application/json' \
  -d '{"projectId":"$projectId","relation":"fold_risks"}'

JSON-RPC: send this body to https://developer.darwindata.ai/public/v1/json-rpc, or as a text frame on the WebSocket.

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "projects/describe",
  "params": {
    "projectId": "$projectId",
    "relation": "fold_risks"
  }
}

projects/query experimental

One read-only SQL query over the analytics of a project.

Scope projectAnalytics: the project must belong to an organization your key reads.

Runs one read-only SQL query over the analytics of a project, and answers its rows as JSON objects, one page at a time.

The numbers are the ones the screens compute, with three differences:

Limits:

Page with page.limit and the nextCursor of the previous page. Send the same sql, entityId and ownershipView with it. The last page has no nextCursor. The cursor counts rows: order the rows on a unique key, or a row can move between two pages. A page stops early when its rows hold more than 4 MiB as JSON: follow its nextCursor. When a new assessment replaces the snapshot between two pages, the cursor answers INVALID_PARAMS: start again from the first page.

Params

NameTypeRequiredDefaultDescription
projectIdProjectIdyes

The id of the project, a UUID. projects/list gives the ids your key may read.

entityIdEntityIdno

The entity whose subtree the query reads, a UUID. Omit it for the whole project.

ownershipViewOwnershipViewno"net"

net (the default) or gross.

sqlstringyes

One SELECT over the relations of projects/describe, or a UNION, EXCEPT or INTERSECT of them, with an optional WITH. Anything else is refused. Order the rows on a unique key to page them.

pageobjectno{"limit":100}

Which page of rows to return. Omit it for the first page, at the default size. Send the same sql, entityId and ownershipView with a cursor.

page.limitinteger (uint32), 1 to 500no100

How many items to return.

page.cursorCursorno

The nextCursor of the previous page. Omit it for the first page.

Result

RowList

Errors

NOT_FOUND, NOT_READY, INVALID_QUERY, QUERY_TIMEOUT, QUERY_TOO_LARGE, on top of the classes of every call.

Examples

A "$projectId" in the params stands for the id of a project your key reads.

The impact by IPBES pressure

REST:

curl -X POST https://developer.darwindata.ai/public/v1/api/projects/query \
  -H 'Authorization: Bearer <key>' \
  -H 'Content-Type: application/json' \
  -d '{"projectId":"$projectId","sql":"SELECT ipbes_pressure, value FROM dash_ipbes ORDER BY value DESC"}'

JSON-RPC: send this body to https://developer.darwindata.ai/public/v1/json-rpc, or as a text frame on the WebSocket.

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "projects/query",
  "params": {
    "projectId": "$projectId",
    "sql": "SELECT ipbes_pressure, value FROM dash_ipbes ORDER BY value DESC"
  }
}

The ten largest pressures, gross

REST:

curl -X POST https://developer.darwindata.ai/public/v1/api/projects/query \
  -H 'Authorization: Bearer <key>' \
  -H 'Content-Type: application/json' \
  -d '{"projectId":"$projectId","ownershipView":"gross","sql":"SELECT pressure_indicator, unit, biome, scope, net FROM fold_pressures ORDER BY abs(net) DESC, pressure_indicator, biome, scope","page":{"limit":10}}'

JSON-RPC: send this body to https://developer.darwindata.ai/public/v1/json-rpc, or as a text frame on the WebSocket.

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "projects/query",
  "params": {
    "projectId": "$projectId",
    "ownershipView": "gross",
    "sql": "SELECT pressure_indicator, unit, biome, scope, net FROM fold_pressures ORDER BY abs(net) DESC, pressure_indicator, biome, scope",
    "page": {
      "limit": 10
    }
  }
}

projects/export experimental

One read-only SQL query over the analytics of a project, as a parquet file.

Scope projectAnalytics: the project must belong to an organization your key reads.

Runs one read-only SQL query over the analytics of a project, writes all its rows to one parquet file, and answers a URL to download it. Use it for a relation too large to page with projects/query.

Limits:

Params

NameTypeRequiredDefaultDescription
projectIdProjectIdyes

The id of the project, a UUID. projects/list gives the ids your key may read.

entityIdEntityIdno

The entity whose subtree the query reads, a UUID. Omit it for the whole project.

ownershipViewOwnershipViewno"net"

net (the default) or gross.

sqlstringyes

One SELECT over the relations of projects/describe, or a UNION, EXCEPT or INTERSECT of them, with an optional WITH. Anything else is refused.

Result

ProjectExport

Errors

NOT_FOUND, NOT_READY, INVALID_QUERY, QUERY_TIMEOUT, QUERY_TOO_LARGE, on top of the classes of every call.

Examples

A "$projectId" in the params stands for the id of a project your key reads.

Every dependency row of the project

REST:

curl -X POST https://developer.darwindata.ai/public/v1/api/projects/export \
  -H 'Authorization: Bearer <key>' \
  -H 'Content-Type: application/json' \
  -d '{"projectId":"$projectId","sql":"SELECT * FROM dependency_rows"}'

JSON-RPC: send this body to https://developer.darwindata.ai/public/v1/json-rpc, or as a text frame on the WebSocket.

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "projects/export",
  "params": {
    "projectId": "$projectId",
    "sql": "SELECT * FROM dependency_rows"
  }
}

Schemas

ProjectsListInput

The projects that the key may read, one page at a time.

NameTypeRequiredDescription
pageobjectno

Which page to return. Omit it for the first page, at the default size.

page.limitinteger (uint32), 1 to 500no

How many items to return.

page.cursorCursorno

The nextCursor of the previous page. Omit it for the first page.

Cursor

A position in a list, as the previous page returned it. The caller never builds one.

string

ProjectSummaryList

One page of a list.

NameTypeRequiredDescription
itemsProjectSummary[]yes

The items of this page. Empty when the list is empty.

nextCursorCursorno

Absent on the last page.

ProjectSummary

One project the key may read.

NameTypeRequiredDescription
projectIdProjectIdyes

The id of the project, a UUID.

namestringyes

The name of the project, as Darwin shows it.

organizationOrganizationKeyyes

The key of the organization that owns the project.

stateProjectStateyes

Whether the analytics methods can read the project now.

ProjectId

string (uuid)

OrganizationKey

The key of an organization, such as darwin.

string

ProjectState

Whether the analytics methods can read the project. They read the snapshot of the last completed assessment.

computed

An assessment completed: the analytics methods can read the project. While a new assessment runs, they read the previous one until the snapshot of the new one is sealed.

computing

The first assessment runs: nothing can be read yet.

notComputed

No assessment completed, and none runs: nothing can be read.

ProjectsDescribeInput

The project to describe, and optionally one of its relations.

NameTypeRequiredDescription
projectIdProjectIdyes

The id of the project, a UUID. projects/list gives the ids your key may read.

relationstringno

A relation of the catalogue, e.g. fold_risks. Give it to get its columns and their types.

ProjectDescription

The catalogue of the relations, and the columns of one relation when the input names one.

NameTypeRequiredDescription
relationsRelationSummary[]yes

Every relation a query may read, the computed ones first.

examplesQueryExample[]yes

Worked queries, each with the question it answers.

columnsColumn[]no

The columns of the relation of the input, in order. Absent when the input names none.

RelationSummary

One relation a query may name in FROM.

NameTypeRequiredDescription
namestringyes

The name to write in FROM.

kindRelationKindyes
aboutstringno

What one row is. Absent for a table, whose columns say it.

RelationKind

fold

A relation Darwin computes from the snapshot for the point of view of the query, most of them aggregations. Read one rather than rebuild a total from the tables.

table

A table of the assessment, as Darwin stored it.

QueryExample

A worked query.

NameTypeRequiredDescription
questionstringyes

The question the query answers.

sqlstringyes

The sql to send to projects/query.

Column

One column of a relation.

NameTypeRequiredDescription
namestringyes

The name to write in a query.

typestringyes

The SQL type of the column, e.g. VARCHAR, DOUBLE, UUID.

ProjectsQueryInput

One read-only SQL query over the analytics of a project.

NameTypeRequiredDescription
projectIdProjectIdyes

The id of the project, a UUID. projects/list gives the ids your key may read.

entityIdEntityIdno

The entity whose subtree the query reads, a UUID. Omit it for the whole project.

ownershipViewOwnershipViewno

net (the default) or gross.

sqlstringyes

One SELECT over the relations of projects/describe, or a UNION, EXCEPT or INTERSECT of them, with an optional WITH. Anything else is refused. Order the rows on a unique key to page them.

pageobjectno

Which page of rows to return. Omit it for the first page, at the default size. Send the same sql, entityId and ownershipView with a cursor.

page.limitinteger (uint32), 1 to 500no

How many items to return.

page.cursorCursorno

The nextCursor of the previous page. Omit it for the first page.

EntityId

string (uuid)

OwnershipView

Net or gross ownership.

net

Each entity counts at the ownership share along the path. The screens' default.

gross

Each entity counts at 100%, whatever the ownership.

RowList

One page of a list.

NameTypeRequiredDescription
itemsRow[]yes

The items of this page. Empty when the list is empty.

nextCursorCursorno

Absent on the last page.

Row

One row of the result: each column name, with its value.

object

ProjectsExportInput

One read-only SQL query over the analytics of a project, written whole to one parquet file.

NameTypeRequiredDescription
projectIdProjectIdyes

The id of the project, a UUID. projects/list gives the ids your key may read.

entityIdEntityIdno

The entity whose subtree the query reads, a UUID. Omit it for the whole project.

ownershipViewOwnershipViewno

net (the default) or gross.

sqlstringyes

One SELECT over the relations of projects/describe, or a UNION, EXCEPT or INTERSECT of them, with an optional WITH. Anything else is refused.

ProjectExport

Where to download the file, until when, and what it holds.

NameTypeRequiredDescription
urlstringyes

The URL of the parquet file. Send no header with it: the URL carries its own signature.

expiresAtstring (date-time)yes

When the URL stops working, in RFC 3339.

rowsinteger (uint64), from 0yes

The rows of the file.

bytesinteger (uint64), from 0yes

The size of the file, in bytes.