Skip to main content

POST /api/user/init

Initialize user profile after Supabase authentication. This endpoint is idempotent - if the user already exists, it returns the existing profile without creating a duplicate.
This endpoint must be called after Supabase signup/login and before accessing other protected endpoints.

Authentication

Requires valid JWT token from Supabase Auth in the Authorization header.

Request Body

display_name
string
required
User’s display name. Can be derived from OAuth provider (e.g., Google full name) or email username.

Request Example

curl -X POST https://scribeapi.manitmishra.com/api/user/init \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "display_name": "John Doe"
  }'

Response

id
string (UUID)
User’s unique identifier (matches Supabase auth.users ID)
email
string
User’s email address from Supabase Auth
display_name
string | null
User’s display name
generation_count
integer
Total number of emails generated by the user
template_count
integer
Total number of templates created by the user
onboarded
boolean
Whether the user has completed onboarding flow
email_template
string | null
User’s default email template with placeholders
created_at
string (ISO 8601)
Timestamp when user profile was created

Response Example

{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "email": "[email protected]",
  "display_name": "John Doe",
  "generation_count": 0,
  "template_count": 0,
  "onboarded": false,
  "email_template": null,
  "created_at": "2025-01-24T10:30:00Z"
}

Error Responses

401 Unauthorized
Invalid or missing JWT token
{
  "detail": "Could not validate credentials"
}
422 Validation Error
Invalid request body format
{
  "detail": [
    {
      "loc": ["body", "display_name"],
      "msg": "field required",
      "type": "value_error.missing"
    }
  ]
}
500 Internal Server Error
Database or system error
{
  "detail": "Failed to create user: <error details>"
}

GET /api/user/profile

Retrieve the current user’s profile. Requires that the user has been initialized via POST /api/user/init.

Authentication

Requires valid JWT token from Supabase Auth in the Authorization header.

Request Example

curl -X GET https://scribeapi.manitmishra.com/api/user/profile \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Response

Returns the same UserResponse schema as the /init endpoint with current user data.

Response Example

{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "email": "[email protected]",
  "display_name": "John Doe",
  "generation_count": 42,
  "template_count": 3,
  "onboarded": true,
  "email_template": "Dear {{professor_name}}, I'm interested in {{research_area}}...",
  "created_at": "2025-01-24T10:30:00Z"
}

Error Responses

401 Unauthorized
Invalid or missing JWT token
404 Not Found
User profile not initialized. Call POST /api/user/init first.
{
  "detail": "User not found. Please initialize your profile first."
}

PATCH /api/user/onboarding

Mark the current user as having completed the onboarding flow. This is used to track whether the user has seen the initial setup wizard.

Authentication

Requires valid JWT token from Supabase Auth in the Authorization header.

Request Example

curl -X PATCH https://scribeapi.manitmishra.com/api/user/onboarding \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Response

Returns the updated UserResponse with onboarded set to true.

Response Example

{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "email": "[email protected]",
  "display_name": "John Doe",
  "generation_count": 0,
  "template_count": 0,
  "onboarded": true,
  "email_template": null,
  "created_at": "2025-01-24T10:30:00Z"
}

PATCH /api/user/template

Update the user’s default email template. This template is used as the default for batch email generation.

Authentication

Requires valid JWT token from Supabase Auth in the Authorization header.

Request Body

template
string
required
Email template text with variable placeholders (e.g., {{professor_name}}, {{research_area}}). Must be between 1-10,000 characters and cannot be only whitespace.

Request Example

curl -X PATCH https://scribeapi.manitmishra.com/api/user/template \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "template": "Dear {{professor_name}},\n\nI am writing to express my interest in your research on {{research_area}}. I have experience in...\n\nBest regards"
  }'

Response

Returns the updated UserResponse with the new template.

Response Example

{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "email": "[email protected]",
  "display_name": "John Doe",
  "generation_count": 5,
  "template_count": 1,
  "onboarded": true,
  "email_template": "Dear {{professor_name}},\n\nI am writing to express my interest in your research on {{research_area}}...",
  "created_at": "2025-01-24T10:30:00Z"
}

Error Responses

422 Validation Error
Template validation failed (empty, too short/long, or whitespace only)
{
  "detail": [
    {
      "loc": ["body", "template"],
      "msg": "Template cannot be empty or whitespace only",
      "type": "value_error"
    }
  ]
}

Build docs developers (and LLMs) love