Skip to content

Latest commit

 

History

History
169 lines (137 loc) · 4.73 KB

get-all.mdx

File metadata and controls

169 lines (137 loc) · 4.73 KB
title List Documents
description Retrieve all documents in a collection with optional filtering, sorting, and pagination.

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

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

Query parameters

Page number for pagination. Defaults to `1`. Number of documents per page. Defaults to `100`, maximum `1000`. Field to sort by. Prefix with `-` for descending order (e.g., `sort=-createdAt` for newest first, `sort=title` for ascending alphabetical). Filter documents by field value. Append an operator suffix to the field name for comparisons (e.g., `_gt`, `_lt`, `_ne`, `_in`, `_regex`). For exact matches, use the field name without a suffix. Example: `status=published&views_gt=100` Setting `include_deleted` to `true` includes soft-deleted documents; it defaults to `false`

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

`true` when the request succeeded. Object containing the results and pagination metadata. Array of document objects matching the query. Total number of documents matching the query (ignoring pagination). Current page number (present in offset-based pagination). Current cursor (present in cursor-based pagination). Cursor for the next page, or `null`. Number of results per page. Human-readable status message.

Code examples

const params = new URLSearchParams({
  page: '1',
  limit: '10',
  sort: '-createdAt',
  status: 'published',
  include_deleted: 'true'
});

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

const { data } = await res.json();
// data.items contains the array of matching documents
// data.total contains the total count
curl "https://api.urbackend.in/api/data/posts?page=1&limit=10&sort=-createdAt&status=published&include_deleted=true" \
  -H "x-api-key: pk_live_YOUR_KEY"
const res = await fetch('https://api.urbackend.in/api/data/notes', {
  headers: {
    'x-api-key': 'pk_live_YOUR_KEY',
    'Authorization': `Bearer ${accessToken}` // Required for private-mode collections
  }
});

Success response

{
  "success": true,
  "data": {
    "items": [
      {
        "_id": "64fd1234abcd5678ef901234",
        "title": "Why BaaS is the future",
        "status": "published",
        "isDeleted": false,
        "deletedAt": null,
        "createdAt": "2024-01-15T10:30:00.000Z"
      },
      {
        "_id": "64fd5678abcd1234ef905678",
        "title": "Getting started with urBackend",
        "status": "published",
        "isDeleted": true,
        "deletedAt": "2026-05-20T10:30:00.000Z",
        "createdAt": "2024-01-14T08:00:00.000Z"
      }
    ],
    "total": 42,
    "page": 1,
    "limit": 10
  },
  "message": "Data fetched successfully"
}

Errors

Status Cause
401 Unauthorized Missing/invalid API key, or missing Bearer token on a private collection
403 Forbidden pk_live write attempt without RLS, or quota exceeded
404 Not Found Collection does not exist