Onyx Cloud Database API Documentation

Welcome to the Onyx Cloud Database API documentation. Here, you’ll learn how to interact with your configured databases: inserting, updating, retrieving, deleting, and querying data. Use this guide as a reference for endpoint details, authentication requirements, request formats, and example payloads.

How to Read This Documentation

You will see placeholders like {databaseId},{MyTable}, and{primaryKey}. Replace these with your actual database identifiers, table names, and real primary keys. When you see example values like 123, use the appropriate real value from your own dataset.

Overview

The Onyx Cloud Database API allows you to interact with a specific database and its tables. By following the endpoints described below, you can perform CRUD operations and more complex queries on your data.

Authentication

The API requires authentication to ensure authorized access. Include the following headers if not relying on user session:

HeaderDescription
x-onyx-keyYour Onyx API key
x-onyx-secretYour Onyx API secret

Ensure you have valid credentials before making requests.

Endpoints

The following endpoints let you create, update, retrieve, delete, and query data. Always replace placeholders with your actual values.

1

Inserting & Updating Data (PUT)

Use this endpoint to create or update one or more entities in a table.

MethodEndpointDescription
PUT/data/{databaseId}/{MyTable}Insert or update entities

Example

Insert or update a record with id = "123":

PUT https://api.onyx.dev/data/{databaseId}/{MyTable}
Content-Type: application/json
x-onyx-key: YOUR_KEY
x-onyx-secret: YOUR_SECRET

[
  {
    
    id": "123",
    "name": "Sample Entity",
    "description": "A descriptive sample entity."
  }
]

Response:

HTTP/1.1 200 OK
Content-Type: application/json

[
  {
    "id": "123",
    "name": "Sample Entity",
    "description": "A descriptive sample entity."
  }
]
2

Retrieving Data by Primary Key (GET)

Fetch a single record by its primary key. Optional parameters let you specify a partition or fetch related data.

MethodEndpointQuery ParamsDescription
GET/data/{databaseId}/{MyTable}/{primaryKey}partition (optional): partition key
fetch (optional): relationships to include
Retrieve a single record

Example

GET https://api.onyx.dev/data/{databaseId}/{MyTable}/123?fetch=relatedData
x-onyx-key: YOUR_KEY
x-onyx-secret: YOUR_SECRET

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
  "id": "123",
  "name": "Sample Entity",
  "description": "A descriptive sample entity.",
  "relatedData": [
    {
      "id": "rel-1",
      "info": "Related item info"
    }
  ]
}
3

Deleting Data by Primary Key (DELETE)

Remove a single record by its primary key.

MethodEndpointQuery ParamsDescription
DELETE/data/{databaseId}/{MyTable}/{primaryKey}partition (optional): partition keyDelete a single record

Example

DELETE https://api.onyx.dev/data/{databaseId}/{MyTable}/123
x-onyx-key: YOUR_KEY
x-onyx-secret: YOUR_SECRET

Response: If successful:

HTTP/1.1 200 OK
4

Querying Data (PUT)

Perform advanced queries to fetch data that meets certain conditions. Provide a SelectQuery in the request body.

Endpoint

MethodEndpointQuery ParamsDescription
PUT/data/{databaseId}/query/{MyTable}pageSize (optional): number of records per page (max 1000)
nextPage (optional): token for retrieving the next page of results
Query data with optional paging.

SelectQuery Structure

FieldDescription
fields (optional)Array of field names to return.
conditions (optional)A condition that defines filtering logic.
sort (optional)Sort results by a specified field.
limit (optional)Limit the number of returned records.
distinct (optional)If true, returns only unique results.
groupBy (optional)Groups results by specified fields.

Paging Support

When specifying a pageSize parameter, if the total records exceed the specified pageSize, the results will be returned in pages. The response will include a nextPage token if more records remain. To retrieve subsequent pages, send another request with the nextPage token as a query parameter.

  • If pageSize is greater than 1000, a 400 Bad Request is returned with an error message.
  • If the provided nextPage token is invalid or expired, a 404 Not Found is returned.
  • If nextPage is omitted, a fresh query is executed and, if needed, caching and paging are set up.

QueryCriteriaOperator

Operators define how to match field values (e.g., EQUAL, NOT_EQUAL, IN, LIKE, etc.).

EQUAL
NOT_EQUAL
IN
NOT_IN
GREATER_THAN
GREATER_THAN_EQUAL
LESS_THAN
LESS_THAN_EQUAL
MATCHES
NOT_MATCHES
BETWEEN
LIKE
NOT_LIKE
CONTAINS
NOT_CONTAINS
STARTS_WITH
NOT_STARTS_WITH
IS_NULL
NOT_NULL

Example (Without Paging)

Query all records where name equals "Sample Entity":

PUT https://api.onyx.dev/data/{databaseId}/query/{MyTable}
Content-Type: application/json
x-onyx-key: YOUR_KEY
x-onyx-secret: YOUR_SECRET

{
  "conditions": {
    "criteria": {
      "field": "name",
      "operator": "EQUAL",
      "value": "Sample Entity"
    }
  }
}

Response:

HTTP/1.1 201 Created
Content-Type: application/json

{
  "records": [
  {
    "id": "123",
    "name": "Sample Entity",
    "description": "A descriptive sample entity."
  }
  ],
  "totalRecords": 1,
  "nextPage": null
}

Example (With Paging)

Suppose you have many matching records and want them in batches of 50. Set pageSize=50:

PUT https://api.onyx.dev/data/{databaseId}/query/{MyTable}?pageSize=50
Content-Type: application/json
x-onyx-key: YOUR_KEY
x-onyx-secret: YOUR_SECRET

{
  "conditions": {
    "criteria": {
      "field": "status",
      "operator": "EQUAL",
      "value": "Active"
    }
  }
}

Response (First Page):

HTTP/1.1 201 Created
Content-Type: application/json

{
  "records": [
    { "id": "100", "name": "Entity A", "status": "Active" },
    { "id": "101", "name": "Entity B", "status": "Active" },
    ...
    // 50 records total
  ],
  "totalRecords": 2000,
  "nextPage": "a1b2c3d4|1" // A token to fetch the next page
}

To fetch the next page, use the returned nextPage token:

PUT https://api.onyx.dev/data/{databaseId}/query/{MyTable}?nextPage=a1b2c3d4|1
Content-Type: application/json
x-onyx-key: YOUR_KEY
x-onyx-secret: YOUR_SECRET

This will return the next batch of 50 records and possibly another nextPage token if more records remain.

5

Updating Data with Queries (PUT)

Use an UpdateQuery to update multiple records that match certain conditions.

UpdateQuery Structure

FieldDescription
conditions (optional)Defines which records to update.
updatesA map of fields to new values.
MethodEndpointDescription
PUT/data/{databaseId}/query/update/{MyTable}Update multiple records using an UpdateQuery

Example

Update all records where name equals "Sample Entity":

PUT https://api.onyx.dev/data/{databaseId}/query/update/{MyTable}
Content-Type: application/json
x-onyx-key: YOUR_KEY
x-onyx-secret: YOUR_SECRET

{
  "conditions": {
    "criteria": {
      "field": "name",
      "operator": "EQUAL",
      "value": "Sample Entity"
    }
  },
  "updates": {
    "description": "Updated description for all matching records."
  }
}

Response:

HTTP/1.1 201 Created
Content-Type: application/json

{
  "updatedCount": 5
}
6

Deleting Data with Queries (PUT)

Use a SelectQuery to identify which records to remove.

MethodEndpointDescription
PUT/data/{databaseId}/query/delete/{MyTable}Delete multiple records that match a SelectQuery

Example

Delete all records where name equals "Obsolete Entity":

PUT https://api.onyx.dev/data/{databaseId}/query/delete/{MyTable}
Content-Type: application/json
x-onyx-key: YOUR_KEY
x-onyx-secret: YOUR_SECRET

{
  "conditions": {
    "criteria": {
      "field": "name",
      "operator": "EQUAL",
      "value": "Obsolete Entity"
    }
  }
}

Response:

HTTP/1.1 201 Created
Content-Type: application/json

{
  "deletedCount": 2
}
7

Streaming Query Results (PUT)

This endpoint allows you to subscribe to real-time changes in query results. You submit a SelectQuery, and the server streams updates as records are created, updated, or deleted. The stream also periodically sends keep-alive messages.

MethodEndpointQuery ParamsDescription
PUT/data/{databaseId}/query/stream/{table}includeQueryResults (optional): If set to true, the initial query response is streamed before live updates begin.Stream query results and subsequent changes in real-time.

Example

The following request sets up a stream for a query. If includeQueryResults=true, the current matching records are sent first. As changes occur (creation, updates, or deletions), the server sends new JSON lines.

PUT https://api.onyx.dev/data/{databaseId}/query/stream/{MyTable}?includeQueryResults=true
Content-Type: application/json
x-onyx-key: YOUR_KEY
x-onyx-secret: YOUR_SECRET

{
  "conditions": {
    "criteria": {
      "field": "name",
      "operator": "EQUAL",
      "value": "Active Entity"
    }
  }
}

Response: This endpoint returns a stream of JSON objects, one per line. Each object has an action field indicating the event type:

  • QUERY_RESPONSE: Initial records that matched your query.
  • CREATE: A new record was added that matches your query.
  • UPDATE: An existing matching record was updated.
  • DELETE: A matching record was removed.
  • KEEP_ALIVE: A periodic message to keep the connection alive.
HTTP/1.1 200 OK
Content-Type: application/json

{"action":"QUERY_RESPONSE","entity":{"id":"123","name":"Active Entity","description":"Currently active record"}}
{"action":"KEEP_ALIVE","entity":null}
{"action":"CREATE","entity":{"id":"124","name":"Active Entity","description":"A newly created matching record"}}
{"action":"UPDATE","entity":{"id":"123","name":"Active Entity","description":"Updated description"}}
{"action":"DELETE","entity":{"id":"124","name":"Active Entity","description":"A newly created matching record"}}
{"action":"KEEP_ALIVE","entity":null}
...

You can continue reading from the stream as long as the connection remains open. The client should handle each line as it arrives.

8

Working with Documents

The Onyx Cloud Database API also allows you to save and serve binary documents (such as images, PDFs, etc.) associated with your database. These documents are stored separately from your tabular data and can be retrieved as needed.

8a

Saving Documents (PUT)

Use this endpoint to store or update a document. The request body should include a JSON-encoded document object with a path for where the document will be stored and a content field containing base64-encoded binary data. If the document does not exist, it will be created. If it does exist, it will be updated.

MethodEndpointDescription
PUT/data/{databaseId}/documentCreate or update a document

Request Body Structure

{
  "path": "folder/subfolder/file.jpg",  // path relative to the database's _documents directory
  "mimeType": "image/jpeg",        // optional, e.g., "image/png", "application/pdf"
  "content": "BASE64_ENCODED_DATA" // base64 string of the file content
}

Example

PUT https://api.onyx.dev/data/{databaseId}/document
Content-Type: application/json
x-onyx-key: YOUR_KEY
x-onyx-secret: YOUR_SECRET

{
  "id": "Sample Document UUID",
  "path": "images/sampleImage.jpg",
  "mimeType": "image/jpeg",
  "content": "/9j/4AAQSkZJRgABAQAAAQABAAD/..." // truncated base64 data
}

Response:

HTTP/1.1 201 Created
Content-Type: application/json

{
  "id": "Sample Document UUID",
  "path": "images/sampleImage.jpg",
  "mimeType": "image/jpeg",
  "content": ""
}
8b

Retrieving Documents (GET)

Retrieve a document by its ID. If the document is an image, you may optionally specify a desired width and height as query parameters to receive a resized version. Non-image documents are returned as-is.

MethodEndpointQuery ParamsDescription
GET/data/{databaseId}/document/{documentId}width (optional): integer
height (optional): integer
Retrieve a document or a resized image

Example

GET https://api.onyx.dev/data/{databaseId}/document/sampleImage?width=200&height=200
x-onyx-key: YOUR_KEY
x-onyx-secret: YOUR_SECRET

Response: Returns the binary contents of the requested document. If the document is an image and resizing parameters were provided, the returned image is resized accordingly.

For non-images, the raw file is returned as-is. For images, if no dimensions are provided, the original image is returned.

8c

Deleting Documents (DELETE)

Use this endpoint to delete a previously stored document by its documentId. If the document or the file does not exist, a 404 error is returned.

MethodEndpointDescription
DELETE/data/{databaseId}/document/{documentId}Delete a stored document

Example

DELETE https://api.onyx.dev/data/{databaseId}/document/sampleImage
x-onyx-key: YOUR_KEY
x-onyx-secret: YOUR_SECRET

Response: If the document and file were successfully deleted:

HTTP/1.1 200 OK

If the document or file doesn’t exist:

HTTP/1.1 404 Not Found
Content-Type: application/json

{
  "error": {
    "message": "Document sampleImage was not found"
  }
}

Next Steps

Need Help?

If you have any questions or need assistance: