Takazudo Modular Docs

Type to search...

to open search from anywhere

POST /api/admin-stats

POST /api/admin-stats

Get dashboard statistics for the zpreorder admin interface.

Request

Method

POST

Headers

HeaderValue
AuthorizationBearer {ADMIN_API_TOKEN}
Content-Typeapplication/json

Body

Empty object or no body required.

{}

Response

Success (200)

{
  "success": true,
  "stats": {
    "notify": {
      "total": 15,
      "byStatus": {
        "pending": 10,
        "notified": 3,
        "unsubscribed": 2
      },
      "byProduct": {
        "oxi-one-mk2": 8,
        "n32b-slim": 5,
        "module-x": 2
      }
    },
    "reservations": {
      "total": 12,
      "byStatus": {
        "pending": 5,
        "confirmed": 4,
        "fulfilled": 2,
        "cancelled": 1
      },
      "byProduct": {
        "oxi-one-mk2": 6,
        "n32b-slim": 4,
        "module-x": 2
      }
    }
  }
}

Response Fields

FieldTypeDescription
stats.notify.totalnumberTotal notify subscriptions
stats.notify.byStatusobjectSubscription count by status
stats.notify.byProductobjectSubscription count by product slug
stats.reservations.totalnumberTotal reservations
stats.reservations.byStatusobjectReservation count by status
stats.reservations.byProductobjectReservation count by product slug

Unauthorized (401)

{
  "success": false,
  "error": "Unauthorized"
}

Server Error (500)

{
  "success": false,
  "error": "Internal server error"
}

Example

cURL

curl -X POST https://takazudomodular.com/api/admin-stats \
  -H "Authorization: Bearer YOUR_ADMIN_TOKEN" \
  -H "Content-Type: application/json"

JavaScript (fetch)

const response = await fetch('/api/admin-stats', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${ADMIN_API_TOKEN}`,
    'Content-Type': 'application/json',
  },
});

const data = await response.json();

if (data.success) {
  console.log('Notify stats:', data.stats.notify);
  console.log('Reservation stats:', data.stats.reservations);
}

Implementation Details

Source File

netlify/functions/admin-stats.ts

Behavior

  1. Validates Bearer token authentication
  2. Fetches all notify subscriptions from Netlify Blobs
  3. Fetches all reservations from Netlify Blobs
  4. Aggregates counts by status and product
  5. Returns combined statistics