| ← Back to README | Documentation Index | API Docs | Developer Guide |
This guide explains how to use the website management endpoints to register and manage websites for analytics tracking.
Before you can track analytics for a website, you need to:
/api/v1/auth/register/api/v1/auth/login/api/v1/websitesEndpoint: POST /api/v1/websites
Authentication: Required (Bearer token)
Request Body:
{
"name": "My Blog",
"domain": "https://example.com",
"description": "My personal blog"
}
Response (201 Created):
{
"id": "clp0a1b2c3d4e5f6g7h8i9j0",
"userId": "clp0a1b2c3d4e5f6g7h8i9j0",
"name": "My Blog",
"domain": "https://example.com",
"description": "My personal blog",
"trackingCode": "pm-a7x9k2-1706425600000",
"createdAt": "2026-01-28T10:30:00.000Z",
"updatedAt": "2026-01-28T10:30:00.000Z"
}
Endpoint: GET /api/v1/websites
Authentication: Required (Bearer token)
Response:
{
"websites": [
{
"id": "clp0a1b2c3d4e5f6g7h8i9j0",
"userId": "clp0a1b2c3d4e5f6g7h8i9j0",
"name": "My Blog",
"domain": "https://example.com",
"description": "My personal blog",
"trackingCode": "pm-a7x9k2-1706425600000",
"createdAt": "2026-01-28T10:30:00.000Z",
"updatedAt": "2026-01-28T10:30:00.000Z"
}
],
"total": 1
}
Endpoint: GET /api/v1/websites/:id
Authentication: Required (Bearer token)
Response:
{
"id": "clp0a1b2c3d4e5f6g7h8i9j0",
"userId": "clp0a1b2c3d4e5f6g7h8i9j0",
"name": "My Blog",
"domain": "https://example.com",
"description": "My personal blog",
"trackingCode": "pm-a7x9k2-1706425600000",
"createdAt": "2026-01-28T10:30:00.000Z",
"updatedAt": "2026-01-28T10:30:00.000Z"
}
Endpoint: PUT /api/v1/websites/:id
Authentication: Required (Bearer token)
Request Body (all fields optional):
{
"name": "Updated Blog Name",
"domain": "https://newdomain.com",
"description": "Updated description"
}
Response:
{
"id": "clp0a1b2c3d4e5f6g7h8i9j0",
"userId": "clp0a1b2c3d4e5f6g7h8i9j0",
"name": "Updated Blog Name",
"domain": "https://newdomain.com",
"description": "Updated description",
"trackingCode": "pm-a7x9k2-1706425600000",
"createdAt": "2026-01-28T10:30:00.000Z",
"updatedAt": "2026-01-28T11:00:00.000Z"
}
Endpoint: DELETE /api/v1/websites/:id
Authentication: Required (Bearer token)
Response:
{
"success": true,
"message": "Website deleted successfully"
}
curl -X POST http://localhost:3000/api/v1/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "SecurePass123",
"name": "John Doe"
}'
curl -X POST http://localhost:3000/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "SecurePass123"
}'
Save the accessToken from the response.
curl -X POST http://localhost:3000/api/v1/websites \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-d '{
"name": "My Blog",
"domain": "https://example.com",
"description": "My personal blog"
}'
curl -X GET http://localhost:3000/api/v1/websites \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
curl -X GET http://localhost:3000/api/v1/websites/WEBSITE_ID \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
curl -X PUT http://localhost:3000/api/v1/websites/WEBSITE_ID \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-d '{
"name": "Updated Blog Name",
"description": "Updated description"
}'
curl -X DELETE http://localhost:3000/api/v1/websites/WEBSITE_ID \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
{
"error": "VALIDATION_ERROR",
"message": "Invalid request body",
"details": {
"fieldErrors": {
"domain": ["Invalid domain URL"]
}
}
}
{
"error": "UNAUTHORIZED",
"message": "Missing or invalid authorization header"
}
{
"error": "NOT_FOUND",
"message": "Website not found"
}
{
"error": "CONFLICT",
"message": "This domain is already registered for your account"
}
{
"error": "INTERNAL_ERROR",
"message": "Failed to create website"
}
Each website is automatically assigned a unique tracking code when created. This code is used to identify your website when submitting analytics events.
Format: pm-{random}-{timestamp}
Example: pm-a7x9k2-1706425600000
You can use the tracking code in your website to:
Once you’ve registered a website, you can: