REST API first steps

Create an API key and make your first calls with curl.

Create an API key and make your first REST API calls with curl. Each route is equivalent to a MongoDB command.

Requirements

  • Access to teseladb admin on a node and the cluster CA.

Create the key

Shell
teseladb admin apikey create
export TESELADB_API_KEY=tdb_…

List the databases

Shell
curl --cacert ca.pem https://node-01:27080/v1/databases -H "Authorization: Bearer $TESELADB_API_KEY"

Insert and find

Shell
curl --cacert ca.pem -X POST https://node-01:27080/v1/databases/shop/collections/orders/insertOne \
  -H "Authorization: Bearer $TESELADB_API_KEY" -H "Content-Type: application/json" -d '{"document": {"total": 10}}'
curl --cacert ca.pem -X POST https://node-01:27080/v1/databases/shop/collections/orders/find \
  -H "Authorization: Bearer $TESELADB_API_KEY" -H "Content-Type: application/json" -d '{"filter": {}}'

Check

The last call, the one that searches orders with an empty filter, returns the document you just inserted with insertOne.

Common problems

  • The call is refused because the Authorization header is missing or the key expired.

See also