> ## 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.

# Get Document

> Retrieve a single document from a collection by its MongoDB ObjectId.

## 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

<ParamField path="collectionName" type="string" required>
  The name of the collection (e.g., `posts`, `products`).
</ParamField>

<ParamField path="id" type="string" required>
  The MongoDB ObjectId string of the document to retrieve (e.g., `64fd1234abcd5678ef901234`).
</ParamField>

### Query parameters

<ParamField query="include_deleted" type="boolean">
  If `true`, allows retrieval of a soft-deleted document. Defaults to `false`. Without this parameter, requesting a soft-deleted document by ID will return `404 Not Found`.
</ParamField>

### Response fields

The endpoint returns the document object directly.

<ResponseField name="_id" type="string">
  The unique MongoDB ObjectId string for the document.
</ResponseField>

<ResponseField name="isDeleted" type="boolean">
  `true` if the document is in the trash.
</ResponseField>

<ResponseField name="deletedAt" type="string">
  ISO date string of when the document was soft-deleted, or `null`.
</ResponseField>

<ResponseField name="createdAt" type="string">
  ISO date string of when the document was created.
</ResponseField>

<ResponseField name="updatedAt" type="string">
  ISO date string of when the document was last updated.
</ResponseField>

<Note>
  Other fields returned depend on your collection schema.
</Note>

### Code examples

<CodeGroup>
  ```javascript fetch theme={null}
  const docId = '64fd1234abcd5678ef901234';

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

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

  ```bash curl theme={null}
  curl "https://api.ub.bitbros.in/api/data/posts/64fd1234abcd5678ef901234?include_deleted=true" \
    -H "x-api-key: pk_live_YOUR_KEY"
  ```
</CodeGroup>

### Success response

```json theme={null}
{
  "_id": "64fd1234abcd5678ef901234",
  "title": "Why BaaS is the future",
  "body": "Content goes here...",
  "status": "published",
  "isDeleted": false,
  "deletedAt": null,
  "tags": ["tech", "development"],
  "meta": {
    "views": 105,
    "likes": 12
  },
  "createdAt": "2024-01-15T10:30:00.000Z",
  "updatedAt": "2024-01-15T10:30:00.000Z"
}
```

### Errors

| Status             | Cause                                                                       |
| :----------------- | :-------------------------------------------------------------------------- |
| `401 Unauthorized` | Missing or invalid API key, or missing Bearer token on a private collection |
| `404 Not Found`    | No document with that ID exists in the collection                           |
