Skip to main content
POST
/
api
/
claims
Create Claim
curl --request POST \
  --url https://harbor-parking.vercel.app/api/claims \
  --header 'Content-Type: application/json' \
  --data '{
  "availability_id": "<string>",
  "start_time": "<string>",
  "end_time": "<string>"
}'
{
  "claim": {
    "id": "abc123de-e89b-12d3-a456-426614174003",
    "availability_id": "789e0123-e89b-12d3-a456-426614174002",
    "claimer_id": "456e7890-e89b-12d3-a456-426614174001",
    "start_time": "2024-01-16T09:00:00Z",
    "end_time": "2024-01-16T17:00:00Z",
    "status": "active",
    "created_at": "2024-01-15T10:30:00Z",
    "updated_at": "2024-01-15T10:30:00Z"
  }
}

Overview

This endpoint allows users to claim an available parking spot for a specific time period.

Authentication

Request Body

availability_id
string
required
ID of the availability to claim
start_time
string
required
Claim start time (ISO 8601 format, must be within the availability window)
end_time
string
required
Claim end time (ISO 8601 format, must be within the availability window)

Response

claim
object
required
Created claim object

Example Request

curl -X POST "https://harbor-parking.vercel.app/api/claims" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "availability_id": "789e0123-e89b-12d3-a456-426614174002",
    "start_time": "2024-01-16T09:00:00Z",
    "end_time": "2024-01-16T17:00:00Z"
  }'

Example Response

{
  "claim": {
    "id": "abc123de-e89b-12d3-a456-426614174003",
    "availability_id": "789e0123-e89b-12d3-a456-426614174002",
    "claimer_id": "456e7890-e89b-12d3-a456-426614174001",
    "start_time": "2024-01-16T09:00:00Z",
    "end_time": "2024-01-16T17:00:00Z",
    "status": "active",
    "created_at": "2024-01-15T10:30:00Z",
    "updated_at": "2024-01-15T10:30:00Z"
  }
}

Validation Rules

  • The availability must not already be claimed
  • Claim times must be within the availability window
  • start_time must be in the future
  • end_time must be after start_time
  • You cannot claim your own parking spots

Error Responses

{
  "error": "This availability has already been claimed"
}