> ## Documentation Index
> Fetch the complete documentation index at: https://lapscher.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Claim

> Claim an available parking spot

## Overview

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

## Authentication

<Snippet file="auth-required.mdx" />

## Request Body

<ParamField body="availability_id" type="string" required>
  ID of the availability to claim
</ParamField>

<ParamField body="start_time" type="string" required>
  Claim start time (ISO 8601 format, must be within the availability window)
</ParamField>

<ParamField body="end_time" type="string" required>
  Claim end time (ISO 8601 format, must be within the availability window)
</ParamField>

## Response

<ResponseField name="claim" type="object" required>
  Created claim object

  <Expandable title="Claim Object">
    <ResponseField name="id" type="string" required>
      Unique claim identifier (UUID)
    </ResponseField>

    <ResponseField name="availability_id" type="string" required>
      ID of the claimed availability
    </ResponseField>

    <ResponseField name="claimer_id" type="string" required>
      ID of the user who made the claim (authenticated user)
    </ResponseField>

    <ResponseField name="start_time" type="string" required>
      Claim start time (ISO 8601)
    </ResponseField>

    <ResponseField name="end_time" type="string" required>
      Claim end time (ISO 8601)
    </ResponseField>

    <ResponseField name="status" type="string" required>
      Claim status (always "active" on creation)
    </ResponseField>

    <ResponseField name="created_at" type="string" required>
      Claim creation timestamp (ISO 8601)
    </ResponseField>

    <ResponseField name="updated_at" type="string" required>
      Claim last update timestamp (ISO 8601)
    </ResponseField>
  </Expandable>
</ResponseField>

## Example Request

<CodeGroup>
  ```bash cURL theme={null}
  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"
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://harbor-parking.vercel.app/api/claims', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${yourJwtToken}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      availability_id: "789e0123-e89b-12d3-a456-426614174002",
      start_time: "2024-01-16T09:00:00Z",
      end_time: "2024-01-16T17:00:00Z"
    })
  });

  const result = await response.json();
  ```
</CodeGroup>

## Example Response

<ResponseExample>
  ```json Success Response theme={null}
  {
    "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"
    }
  }
  ```
</ResponseExample>

## 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

<ResponseExample>
  ```json 400 Bad Request - Already Claimed theme={null}
  {
    "error": "This availability has already been claimed"
  }
  ```

  ```json 400 Bad Request - Invalid Time Range theme={null}
  {
    "error": "Claim times must be within the availability window"
  }
  ```

  ```json 403 Forbidden - Own Spot theme={null}
  {
    "error": "You cannot claim your own parking spot"
  }
  ```
</ResponseExample>
