Skip to main content

GET /api/data/:collectionName/:id

Fetches one document by its _id. Returns 404 if no document with that ID exists in the collection.

Required Header

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

Path Parameters

collectionName
string
required
The name of the collection (e.g., posts, products).
id
string
required
The MongoDB ObjectId string of the document to retrieve (e.g., 64fd1234abcd5678ef901234).

Response Fields

success
boolean
true when the document was found.
data
object
The full document object, including _id and all stored fields.
message
string
Human-readable status message.

Code Examples

const docId = '64fd1234abcd5678ef901234';

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

const { success, data, message } = await res.json();
// data is the document object

Success Response

{
  "success": true,
  "data": {
    "_id": "64fd1234abcd5678ef901234",
    "title": "Why BaaS is the future",
    "body": "Content goes here...",
    "status": "published",
    "tags": ["tech", "development"],
    "meta": {
      "views": 105,
      "likes": 12
    },
    "createdAt": "2024-01-15T10:30:00.000Z"
  },
  "message": "Document fetched successfully"
}

Errors

StatusCause
401 UnauthorizedMissing or invalid API key, or missing Bearer token on a private collection
404 Not FoundNo document with that ID exists in the collection