Skip to content

Latest commit

 

History

History
920 lines (522 loc) · 16.1 KB

File metadata and controls

920 lines (522 loc) · 16.1 KB

API Reference

VisitRomagna REST API — 60+ endpoints for the agritourism booking platform

Base URL: http://localhost:3000/api

Common Patterns

Authentication

Cookie-based session authentication via vr_session cookie. Obtain a session by calling POST /api/auth/login.

# Dev bypass (development mode only)
curl http://localhost:3000/api/admin/stats?dev=true

Error Responses

All errors follow a consistent format:

{
  "error": "Description of the error",
  "code": "ERROR_CODE",
  "details": {},
  "requestId": "req_1234567890_1"
}
Code HTTP Status Description
VALIDATION_ERROR 400 Request body/query failed Zod validation
INVALID_JSON 400 Malformed JSON body
AUTH_REQUIRED 401 No valid session cookie
FORBIDDEN 403 Insufficient role permissions
NOT_FOUND 404 Resource not found
CONFLICT 409 Duplicate or state conflict
RATE_LIMITED 429 Too many requests
INTERNAL_ERROR 500 Unexpected server error

Rate Limiting

Per-IP, per-endpoint limits. Responses include X-RateLimit-* headers when exceeded.

Endpoint Group Limit
/api/auth/* 10 req/min
/api/experiences 200 req/min
/api/payments/webhook 500 req/min
/api/health 1000 req/min
All other endpoints 100 req/min

Pagination

Endpoints returning lists accept page and pageSize query parameters:

GET /api/bookings?page=2&pageSize=10

Response includes pagination metadata:

{
  "data": [...],
  "meta": {
    "page": 2,
    "pageSize": 10,
    "total": 47,
    "hasMore": true
  }
}

Authentication

POST /api/auth/register

Register a new user account.

Body:

{
  "email": "mario@example.com",
  "name": "Mario Rossi",
  "role": "tourist"
}

Roles: tourist (default), host, admin

Response: 200 — Sets vr_session cookie

{
  "user": { "id": "...", "email": "...", "name": "...", "role": "tourist" },
  "message": "Registration successful"
}

POST /api/auth/login

Authenticate by email (simplified — no password in dev mode).

Body:

{ "email": "mario@example.com" }

Response: 200 — Sets vr_session cookie

POST /api/auth/logout

End the current session.

Response: 200 — Clears vr_session cookie

GET /api/auth/me

Get the currently authenticated user.

Response: 200

{
  "user": { "id": "...", "email": "...", "name": "...", "role": "host" }
}

Experiences

GET /api/experiences

List experiences with optional filters.

Query Parameters:

Param Type Description
category string Filter by category (e.g., "Vino & Vigneti")
location string Filter by location (e.g., "Bertinoro")
maxPrice number Maximum price filter

Response: 200 — Array of experience objects

GET /api/experiences/[id]

Get a single experience by ID.

Response: 200 — Full experience object with host profile, reviews, availability

POST /api/experiences

Create a new experience. Auth: host, admin

Body (Zod-validated):

{
  "title": "Degustazione Sangiovese al tramonto",
  "shortDescription": "Wine tasting at sunset in Bertinoro",
  "description": "Full description...",
  "category": "Vino & Vigneti",
  "location": "Bertinoro",
  "priceValue": 45.00,
  "priceLabel": "€45/persona",
  "duration": "2 ore",
  "hostName": "Marco Rossi",
  "hostTitle": "Sommelier",
  "hostBio": "Bio text...",
  "included": ["Wine tasting", "Light snacks"],
  "languages": ["Italiano", "English"],
  "groupSize": "2-12 persone",
  "meetingPoint": "Piazza della Libertà, Bertinoro"
}

Categories: Vino & Vigneti, Corsi di Cucina, Agriturismi, Cicloturismo, Cultura, Natura & Benessere

Locations: Forlì, Bertinoro, Castrocaro, Predappio, Meldola, Premilcuore


Bookings

GET /api/bookings

List bookings. Auth: authenticated user

Query: status — Filter by booking status

Response: 200 — Array of booking objects

POST /api/bookings

Create a new booking. Auth: authenticated user

Body (Zod-validated):

{
  "experienceId": "exp_123",
  "date": "2025-08-15",
  "guests": 2,
  "giftCardCode": "GIFT-ABC-123"
}

Emits: booking.created domain event

PATCH /api/bookings

Update booking status. Auth: host (own bookings), admin

Body:

{
  "bookingId": "bk_123",
  "status": "confirmed",
  "reason": "Optional cancellation reason"
}

Statuses: pendingconfirmedcompleted | cancelled


Reviews

GET /api/reviews

List reviews for an experience.

Query: experienceId — Required

POST /api/reviews

Submit a review. Auth: authenticated user

Body (Zod-validated):

{
  "experienceId": "exp_123",
  "bookingId": "bk_456",
  "rating": 5,
  "comment": "Esperienza fantastica! Il Sangiovese era eccezionale.",
  "photos": ["https://example.com/photo1.jpg"]
}

Constraints: rating 1–5, comment 10–2000 chars, max 5 photos

Emits: review.submitted domain event

PATCH /api/reviews

Add host response to a review. Auth: host, admin

Body:

{
  "reviewId": "rev_123",
  "response": "Grazie mille! Vi aspettiamo ancora."
}

Availability

GET /api/availability/[experienceId]

Get availability slots for an experience.

Query: month — Format: YYYY-MM

Response: 200 — Array of availability slots with dates, times, capacity


Pricing

GET /api/pricing

Calculate price for an experience.

Query:

Param Type Description
experienceId string Experience ID
date string Booking date
guests number Number of guests

POST /api/pricing

Create a pricing rule. Auth: host, admin

PATCH /api/pricing

Update a pricing rule.

DELETE /api/pricing

Delete a pricing rule. Query: id

Pricing Rule Types: seasonal, day_of_week, early_bird, last_minute, group_discount


Payments

POST /api/payments/webhook

Stripe webhook handler. Processes payment lifecycle events.

Body: Stripe event payload

Headers: stripe-signature — Webhook signature (required in production)

Rate Limit: 500 req/min


Gift Cards

GET /api/gift-cards

List gift cards. Query: code (lookup by code), userId (by purchaser)

POST /api/gift-cards

Purchase a gift card. Auth: authenticated user


Itinerary

POST /api/itinerary/ai

Generate an AI-powered itinerary.

Body:

{
  "message": "Weekend romantico con vino e cucina",
  "days": 3,
  "budget": "medium",
  "interests": ["wine", "cooking", "nature"]
}

GET /api/itinerary-cart

Get itinerary cart. Query: userId, id, shareSlug

POST /api/itinerary-cart

Create/update itinerary cart.


Messaging

GET /api/conversations

List conversations for a user. Query: userId

POST /api/conversations

Create a new conversation.

GET /api/messages

List messages in a conversation. Query: conversationId

POST /api/messages

Send a message.

PATCH /api/messages

Mark messages as read.

GET /api/notifications

List notifications for a user. Query: userId

POST /api/notifications

Create a notification.

PATCH /api/notifications

Mark notifications as read.


Real-Time (SSE)

GET /api/sse

Open a Server-Sent Events stream.

Query: channel — Channel to subscribe to (e.g., user:abc123, host:xyz, admin)

Response: 200text/event-stream

Events:

Event Data Trigger
connected { clientId, channel } On connection
notification RealtimeNotification Booking, message, review, etc.
availability { date, availableSpots } Availability change

Cycling

GET /api/strava

Strava integration endpoints.

Query:

Param Description
userId Get user's Strava connection
routeId Get activity logs for a route
type=challenges List cycling challenges

POST /api/strava

Create activity log or connect Strava account.

GET /api/activity-logs

List cycling activity logs.


Campaigns & Festivals

GET /api/campaigns

List campaigns. Query: slug, status

POST /api/campaigns

Create a campaign. Auth: admin

PATCH /api/campaigns

Update campaign status.

GET /api/festivals

List festivals. Query: category, slug, upcoming, links

POST /api/festivals

Create a festival. Auth: admin


Group Bookings & B2B

GET /api/group-bookings

List group bookings. Query: id, organizerId, status

POST /api/group-bookings

Submit a group booking inquiry.

Group Types: corporate, wedding, school, private

GET /api/b2b-proposals

List B2B proposals. Auth: agent, admin. Query: orgId

POST /api/b2b-proposals

Create a B2B proposal. Auth: agent, admin

PATCH /api/b2b-proposals

Update proposal status.

GET /api/agents

List travel agents. Auth: agent, admin. Query: id, status, rates

POST /api/agents

Register a new agent.


Loyalty & Referrals

GET /api/referrals

Get referral info for a user. Query: userId

POST /api/referrals

Create/redeem a referral.

GET /api/loyalty

Get loyalty tier/credits. Query: userId


CRM

GET /api/guest-crm

Get CRM profiles and stats. Auth: admin

Query: profileId, segment, stats, events

POST /api/guest-crm

Create/update CRM entry.


Host Dashboard

GET /api/channels

List distribution channels. Query: experienceId

POST /api/channels

Create a channel listing.

PATCH /api/channels

Update channel status/pricing.

GET /api/channels/analytics

Get channel performance analytics.

GET /api/media

List media assets. Query: entityType, entityId

POST /api/media

Upload media.

DELETE /api/media

Delete media. Query: id

GET /api/calendar-sync

List calendar sync connections. Query: experienceId

POST /api/calendar-sync

Create calendar sync connection.

DELETE /api/calendar-sync

Remove calendar sync. Query: id


Financial

GET /api/financial

Get host financial profile. Auth: host, admin. Query: hostId, summary, taxProfile

POST /api/financial

Save tax profile/financial info.

GET /api/invoices

List invoices. Query: recipientId, type

POST /api/invoices

Generate an invoice (supports FatturaPA XML).

GET /api/payouts

List host payouts.

GET /api/tax-profiles

List tax profiles.


Revenue Intelligence

GET /api/revenue-intelligence/insights

Revenue insights. Auth: host, admin. Query: hostId

GET /api/revenue-intelligence/forecasts

Revenue forecasts. Query: experienceId, days

GET /api/revenue-intelligence/benchmarks

Market benchmarks. Query: category, location

GET /api/revenue-intelligence/yield

Yield pricing settings. Query: experienceId

POST /api/revenue-intelligence/yield

Save yield pricing settings.


Admin

GET /api/admin/stats

Platform-wide statistics. Auth: admin

GET /api/admin/actions

Admin action log. Auth: admin. Query: limit

POST /api/admin/actions

Record an admin action.

GET /api/admin/disputes

List disputes. Auth: admin. Query: status

PATCH /api/admin/disputes

Resolve a dispute.

GET /api/admin/moderation

List moderation queue. Auth: admin. Query: status

PATCH /api/admin/moderation

Apply moderation decision.

GET /api/experiments

List A/B experiments. Auth: admin

POST /api/experiments

Create experiment.

PATCH /api/experiments

Update experiment (start, stop, declare winner).

GET /api/feature-flags

List feature flags. Auth: admin

PATCH /api/feature-flags

Toggle a feature flag.


Observability & Safety

GET /api/health

Health check endpoint. No auth required.

Response: 200

{ "status": "ok", "timestamp": "...", "version": "0.1.0" }

GET /api/observability

List observability logs. Auth: admin. Query: level, route, type

POST /api/observability

Record a log/event.

GET /api/incidents

List incidents. Auth: admin. Query: experienceId, status

POST /api/incidents

Report an incident.

GET /api/safety-ratings

Get safety ratings for an experience. Query: experienceId

GET /api/trust

Get trust/verification records. Query: userId, type

POST /api/trust

Create trust verification.

GET /api/insurance

Get insurance policies. Query: coverageType


Discovery & Regions

GET /api/recommendations

Get personalized recommendations. Query: userId

POST /api/recommendations

Record a recommendation interaction event.

GET /api/regions

List regions. Auth: admin. Query: slug, activeOnly, memberships

POST /api/regions

Create a region.

GET /api/transport

Transport options. Query: experienceId, from, to, location, hubs

GET /api/transport/ride-share

List ride-share offers. Query: date, toLocation

POST /api/transport/ride-share

Create a ride-share offer.

GET /api/qr-placements

List QR placements. Query: partnerId, slug

POST /api/qr-placements

Create a QR placement.

GET /api/partner-locations

List partner locations. Query: id, status, stats, referrals

POST /api/partner-locations

Create a partner location.


Other Endpoints

GET /api/demand-intelligence

Demand signals dashboard. Auth: admin

GET /api/supply-gaps

Supply gap analysis.

GET /api/guest-questions

List guest questions. Query: experienceId

POST /api/guest-questions

Ask a question.

PATCH /api/guest-questions

Answer a question.

GET /api/waitlist

List waitlist entries. Query: experienceId

POST /api/waitlist

Join a waitlist.

GET /api/host-forum

Host community forum. Auth: host, admin. Query: category

POST /api/host-forum

Create a forum post.

GET /api/host-network

Host collaboration network. Auth: host, admin. Query: hostId

POST /api/host-network

Send a connection request.

PATCH /api/host-network

Accept/decline a connection.

GET /api/webhooks

List webhook subscriptions. Auth: host, admin

POST /api/webhooks

Create a webhook subscription.

DELETE /api/webhooks

Delete a webhook subscription. Query: id or subscriptionId

GET /api/api-keys

List API keys. Auth: agent, admin. Query: hostId

POST /api/api-keys

Create an API key.

DELETE /api/api-keys

Revoke an API key. Query: id

GET /api/accessibility

Accessibility profiles and filters. Query: experienceId, wheelchairOnly, minScore, dietary

POST /api/accessibility

Upsert accessibility profile.

GET /api/immersive-media

List immersive (360°/VR) media. Query: experienceId

POST /api/immersive-media

Upload immersive media.

DELETE /api/immersive-media

Delete immersive media. Query: id

GET /api/bundles

List experience bundles. Query: id, status

POST /api/bundles

Create a bundle.

GET /api/journals

List travel journals. Query: id, limit

POST /api/journals

Create/update a journal.

GET /api/journals/entries

List journal entries. Query: journalId

POST /api/journals/entries

Create a journal entry.

GET /api/events

List domain events. Query: entityId, eventType, limit

POST /api/events

Record a domain event.

GET /api/moonshots

List moonshot features. Query: view

GET /api/moonshots/[slug]

Get a specific moonshot. Query: view

GET /api/docs

API documentation endpoint.