Skip to main content

GET /api/data/:collectionName

Returns a list of documents from the specified collection. Supports pagination, sorting, and field-level filtering via query parameters.
/api/data/users* is blocked for all keys. Use /api/userAuth/* for user management.

Required Header

x-api-key: your pk_live_… or sk_live_… key.

Path Parameters

collectionName
string
required
The name of the collection to query (e.g., posts, comments, inventory).

Query Parameters

page
number
Page number for pagination. Defaults to 1.
limit
number
Number of documents per page. Defaults to 20.
sort
string
Field to sort by. Prefix with - for descending order (e.g., sort=-createdAt for newest first, sort=title for ascending alphabetical).
filter[field][op]
string
Filter documents by field value. Replace field with the document field name and op with a comparison operator. Example: filter[status][eq]=published&filter[views][gt]=100

RLS Behavior

If the collection has RLS enabled:
  • public-read mode: anyone can read all documents with a valid x-api-key.
  • private mode: requires Authorization: Bearer <accessToken> — only the owner’s documents are returned.

Response Fields

success
boolean
true when the request succeeded.
data
array
Array of document objects matching the query. Each document includes its _id and all stored fields.
message
string
Human-readable status message.

Code Examples

const params = new URLSearchParams({
  page: '1',
  limit: '10',
  sort: '-createdAt',
  'filter[status][eq]': 'published'
});

const res = await fetch(
  `https://api.ub.bitbros.in/api/data/posts?${params}`,
  {
    headers: {
      'x-api-key': 'pk_live_YOUR_KEY'
    }
  }
);

const { success, data, message } = await res.json();
// data is an array of matching documents

Success Response

{
  "success": true,
  "data": [
    {
      "_id": "64fd1234abcd5678ef901234",
      "title": "Why BaaS is the future",
      "status": "published",
      "createdAt": "2024-01-15T10:30:00.000Z"
    },
    {
      "_id": "64fd5678abcd1234ef905678",
      "title": "Getting started with urBackend",
      "status": "published",
      "createdAt": "2024-01-14T08:00:00.000Z"
    }
  ],
  "message": "Documents fetched successfully"
}

Errors

StatusCause
401 UnauthorizedMissing/invalid API key, or missing Bearer token on a private collection
403 Forbiddenpk_live write attempt without RLS, or quota exceeded
404 Not FoundCollection does not exist