Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.ub.bitbros.in/llms.txt

Use this file to discover all available pages before exploring further.

POST /api/data/:collectionName

Inserts a new document into the specified collection and returns the created document on success.

Required header

x-api-key: sk_live_… by default. pk_live_… is accepted only when the collection has RLS enabled and the request includes a valid Authorization: Bearer <accessToken> header.

Path parameters

collectionName
string
required
The name of the collection to insert into (e.g., posts, orders).

Request body

Send a JSON object containing the document fields. The fields must conform to the collection’s schema if one is defined.
When using pk_live with RLS enabled, the owner field (e.g., userId) is automatically injected from the authenticated user’s JWT if you omit it. If you include the owner field but it doesn’t match the token’s user ID, the request is rejected with 403.

Response fields

The endpoint returns the created document object directly.
_id
string
The assigned unique MongoDB ObjectId string.
isDeleted
boolean
Always false for new documents.
deletedAt
string
Always null for new documents.
createdAt
string
ISO date string of when the document was created.
updatedAt
string
ISO date string of when the document was last updated.
Other fields returned depend on your collection schema and the data sent.

Code examples

// Use sk_live from your server — never expose it in frontend code
const res = await fetch('https://api.ub.bitbros.in/api/data/posts', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'x-api-key': 'sk_live_YOUR_SECRET_KEY'
  },
  body: JSON.stringify({
    title: 'Why BaaS is the future',
    body: 'Content goes here...',
    tags: ['tech', 'development'],
    meta: { views: 0, likes: 0 },
    userId: 'USER_ID'
  })
});

const doc = await res.json();
// doc is the created document object

Success response

{
  "_id": "64fd1234abcd5678ef901234",
  "title": "My first post",
  "body": "Hello world",
  "userId": "64fd0000abcd5678ef900001",
  "isDeleted": false,
  "deletedAt": null,
  "createdAt": "2024-01-15T10:30:00.000Z",
  "updatedAt": "2024-01-15T10:30:00.000Z"
}

Errors

StatusCause
400 Bad RequestSchema validation failed — missing required field or wrong type
401 UnauthorizedMissing/invalid API key, or missing Bearer token when using pk_live with RLS
403 Forbiddenpk_live without RLS enabled, or owner field in body doesn’t match the token’s user ID