openapi: 3.1.0
info:
  title: Padero Partner API
  license:
    name: Proprietary
    url: https://paderoclub.com/tos
  version: "1.0"
  description: |
    Padero is the club's single source of truth for court time. Connected systems read it
    (courts, free time, busy time) and write to it (open, change, cancel bookings). If Padero
    says a court is taken, the booking is not opened: the same hour is never sold twice.

    Authentication: `Authorization: Bearer <key>`. The club creates the key in its Padero panel
    (Club settings → Integrations) and pastes it into your system. One key = one club and one
    partner; the club comes from the key, never from the request. Keys start with `pdr_live_`
    (production) or `pdr_test_` (sandbox). Never send the key in the URL (400 `key_in_url`).

    The sandbox (https://sandbox.paderoclub.com/api/v1) is a separate environment with its own
    database. Your test key only works with the test club set up for you. Build and test there
    first; Padero opens your production access after a short review.

    Times are ISO 8601 with an offset (`2026-11-05T20:00:00+03:00`). Times without an offset are
    rejected. Responses are in UTC.

    Rate limits per key: 120 reads and 30 writes per minute, 120 new bookings per hour.
    A 429 carries `Retry-After` (seconds).

    Errors: `{ "error": { "code": "slot_taken", "message": "..." } }`. Branch on `code`.
servers:
  - url: https://paderoclub.com/api/v1
    description: Production
  - url: https://sandbox.paderoclub.com/api/v1
    description: Sandbox
security:
  - bearer: []
components:
  securitySchemes:
    bearer:
      type: http
      scheme: bearer
  schemas:
    Error:
      type: object
      required: [error]
      properties:
        error:
          type: object
          required: [code, message]
          properties:
            code:
              type: string
              enum: [invalid_key, key_in_url, rate_limited, slot_taken, booking_cancelled, booking_finished,
                     external_id_reused, outside_hours,
                     closed_day, court_inactive, court_unknown, court_required, booking_not_found,
                     invalid_external_id, invalid_time, invalid_duration, in_past, too_far, field_too_long,
                     invalid_players, invalid_range, range_too_long, invalid_date, invalid_body,
                     field_not_allowed, internal_error]
            message: { type: string }
    Court:
      type: object
      properties:
        id: { type: string, format: uuid, description: Padero court id }
        name: { type: string }
        active: { type: boolean }
        external_id: { type: [string, "null"], description: "Your court id, if the club mapped it" }
        opening_hours:
          type: array
          items:
            type: object
            properties:
              day_of_week: { type: integer, minimum: 0, maximum: 6, description: "0 = Sunday" }
              open: { type: string, example: "09:00" }
              close: { type: string, example: "23:59", description: "23:59 means end of day; a close before open runs past midnight" }
    Booking:
      type: object
      properties:
        id: { type: string, format: uuid }
        external_id: { type: string }
        court_id: { type: string, format: uuid }
        external_court_id: { type: [string, "null"] }
        start: { type: string, format: date-time }
        end: { type: string, format: date-time }
        status:
          type: string
          enum: [pending, confirmed, cancelled, completed, no_show]
          description: "`completed` and `no_show` are set by the club after the hour; such a booking can no longer be changed."
        price: { type: [number, "null"], description: "Informational. Padero does not collect it." }
        customer_name: { type: [string, "null"] }
        customer_phone: { type: [string, "null"] }
        players: { type: integer }
        notes: { type: [string, "null"] }
        created_at: { type: string, format: date-time }
        cancelled_at: { type: [string, "null"], format: date-time }
    BookingWrite:
      type: object
      additionalProperties: false
      properties:
        court_id: { type: string, format: uuid, description: "Padero court id. Send this or external_court_id." }
        external_court_id: { type: string, description: "Your court id, as the club mapped it in Padero." }
        start: { type: string, format: date-time }
        end: { type: string, format: date-time }
        customer_name: { type: string, maxLength: 120 }
        customer_phone: { type: string, maxLength: 32 }
        players: { type: integer, minimum: 1, maximum: 8 }
        notes: { type: string, maxLength: 500 }
  responses:
    Error:
      description: Error
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    BadRequest:
      description: The key was sent in the URL (`key_in_url`)
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    Unauthorized:
      description: Missing, wrong, rotated or revoked key (`invalid_key`)
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
    TooManyRequests:
      description: Rate limit (`rate_limited`). Wait the number of seconds in `Retry-After`.
      headers:
        Retry-After: { schema: { type: integer } }
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Error" }
paths:
  /club:
    get:
      operationId: getClub
      summary: The key's club, its courts, opening hours and closed days (next 90 days)
      responses:
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  club:
                    type: object
                    properties:
                      id: { type: string, format: uuid }
                      name: { type: string }
                      timezone: { type: string, example: Europe/Istanbul }
                      address: { type: [string, "null"] }
                      city: { type: [string, "null"] }
                      phone: { type: [string, "null"] }
                  courts: { type: array, items: { $ref: "#/components/schemas/Court" } }
                  closed_days: { type: array, items: { type: string, format: date } }
  /courts:
    get:
      operationId: getCourts
      summary: Courts and closed days only
      responses:
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  courts: { type: array, items: { $ref: "#/components/schemas/Court" } }
                  closed_days: { type: array, items: { type: string, format: date } }
  /availability:
    get:
      operationId: getAvailability
      summary: Free time ranges of one day, per court
      description: |
        Opening hours minus every booking, block and live payment hold. Ranges, not slots:
        cut them with your own grid. Use `/busy` for a sync over several days.
      parameters:
        - { name: date, in: query, required: true, schema: { type: string, format: date } }
        - { name: court, in: query, required: false, schema: { type: string, format: uuid } }
      responses:
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  date: { type: string, format: date }
                  courts:
                    type: array
                    items:
                      type: object
                      properties:
                        court_id: { type: string, format: uuid }
                        external_id: { type: [string, "null"] }
                        name: { type: string }
                        free:
                          type: array
                          items:
                            type: object
                            properties:
                              start: { type: string, format: date-time }
                              end: { type: string, format: date-time }
        "422": { $ref: "#/components/responses/Error" }
  /busy:
    get:
      operationId: getBusy
      summary: Every taken range, without who (max 31 days)
      description: |
        For the first sync and to recover after missed webhooks. `external_id` is filled only
        for bookings your connection opened. `kind: hold` is a player paying right now; it turns
        into a booking or disappears within minutes.
      parameters:
        - { name: from, in: query, required: true, schema: { type: string, format: date-time } }
        - { name: to, in: query, required: true, schema: { type: string, format: date-time } }
      responses:
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  from: { type: string, format: date-time }
                  to: { type: string, format: date-time }
                  busy:
                    type: array
                    items:
                      type: object
                      properties:
                        id: { type: string, format: uuid }
                        court_id: { type: string, format: uuid }
                        external_court_id: { type: [string, "null"] }
                        start: { type: string, format: date-time }
                        end: { type: string, format: date-time }
                        kind: { type: string, enum: [booking, blocked, hold] }
                        external_id: { type: [string, "null"] }
                        expires_at: { type: [string, "null"], format: date-time }
        "422": { $ref: "#/components/responses/Error" }
  /bookings:
    get:
      operationId: listBookings
      summary: Bookings your connection opened, by start time (max 31 days), cancellations included
      description: |
        To reconcile after missed webhooks: the club may have cancelled, moved or completed a
        booking you opened. Each booking comes with its current `status`.
      parameters:
        - { name: from, in: query, required: true, schema: { type: string, format: date-time } }
        - { name: to, in: query, required: true, schema: { type: string, format: date-time } }
      responses:
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  from: { type: string, format: date-time }
                  to: { type: string, format: date-time }
                  bookings: { type: array, items: { $ref: "#/components/schemas/Booking" } }
        "422": { $ref: "#/components/responses/Error" }
    post:
      operationId: createBooking
      summary: Open a booking
      description: |
        Call this before you confirm the booking to your customer. 201 = opened. 409 `slot_taken` =
        tell your customer the hour is taken. Idempotent on `external_id`: sending the same id again
        with the same court and time returns 200 and the same booking, nothing changes (check its
        `status`: it may have been cancelled since). The same id with another court or time is 409
        `external_id_reused`: use a new id for a new booking. Send `end` or `duration_minutes`
        (30 to 240). At most 90 days ahead. Padero's own booking rules for players (opening for
        bookings, 30-minute grid) do not apply; opening hours, closed days and inactive courts do.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: "#/components/schemas/BookingWrite"
                - type: object
                  required: [external_id, start]
                  properties:
                    external_id: { type: string, pattern: "^[A-Za-z0-9._:-]{1,100}$", description: Your booking id }
                    duration_minutes: { type: integer, minimum: 30, maximum: 240 }
      responses:
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "201": { description: Opened, content: { application/json: { schema: { $ref: "#/components/schemas/Booking" } } } }
        "200": { description: Already opened with this external_id, content: { application/json: { schema: { $ref: "#/components/schemas/Booking" } } } }
        "409": { $ref: "#/components/responses/Error" }
        "422": { $ref: "#/components/responses/Error" }
  /bookings/{external_id}:
    parameters:
      - { name: external_id, in: path, required: true, schema: { type: string } }
    get:
      operationId: getBooking
      summary: A booking your connection opened
      responses:
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/Booking" } } } }
        "404": { $ref: "#/components/responses/Error" }
    patch:
      operationId: updateBooking
      summary: Move or edit a booking your connection opened
      description: |
        Only time, court, customer name/phone, players and notes. Status, price, payment and source
        cannot be set (422 `field_not_allowed`). All or nothing: if the new time is taken you get 409
        and the booking keeps its old time. Send only `start` to move it and keep its length.
        A cancelled booking is 409 `booking_cancelled`; a completed or no-show one is 409 `booking_finished`.
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/BookingWrite" }
      responses:
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/Booking" } } } }
        "404": { $ref: "#/components/responses/Error" }
        "409": { $ref: "#/components/responses/Error" }
        "422": { $ref: "#/components/responses/Error" }
  /bookings/{external_id}/cancel:
    parameters:
      - { name: external_id, in: path, required: true, schema: { type: string } }
    post:
      operationId: cancelBooking
      summary: Cancel a booking your connection opened
      description: |
        The booking is kept with status `cancelled`. Calling again returns 200 and the same booking.
        A completed or no-show booking cannot be cancelled (409 `booking_finished`).
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              properties:
                reason: { type: string, maxLength: 500 }
      responses:
        "400": { $ref: "#/components/responses/BadRequest" }
        "401": { $ref: "#/components/responses/Unauthorized" }
        "429": { $ref: "#/components/responses/TooManyRequests" }
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/Booking" } } } }
        "404": { $ref: "#/components/responses/Error" }
        "409": { $ref: "#/components/responses/Error" }
webhooks:
  booking:
    post:
      operationId: bookingEvent
      summary: Something changed in the club's calendar
      description: |
        Sent for every booking in the club (app, front desk, other partners, yours), so you can
        close or reopen the hour on your side. Types: `booking.created`, `booking.updated`,
        `booking.cancelled`, `block.created`, `block.removed`. `booking.updated` is sent when the time,
        court, status (`completed`, `no_show`) or details change. Bookings that did not come from your
        connection carry no customer name, phone, players or notes.

        Order: deliveries run in parallel and retries can arrive late, so events may arrive out of
        order. `sequence` grows with every event; for each booking `data.id`, ignore an event whose
        `sequence` is lower than the last one you applied.

        Headers: `Padero-Event-Id` (same on retries; process each id once), `Padero-Event-Type`,
        `Padero-Delivery-Attempt`, `Padero-Signature: t=<unix seconds>,v1=<hex>` where
        v1 = HMAC-SHA256(secret, "<t>.<raw body>"). Reject if no `v1` matches or t is more than
        5 minutes old. For 24 hours after the secret is rotated the header carries two `v1` values
        (new and old secret); accept the event if either matches.

        Answer 2xx within 5 seconds. Anything else is retried after 1 min, 5 min, 30 min, 2 h and
        12 h, then dropped; use `GET /bookings` and `/busy` to recover. Redirects are not followed.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                id: { type: string, format: uuid, description: Event id (same as Padero-Event-Id) }
                sequence: { type: integer, description: Grows with every event; use it to order events per booking }
                type: { type: string, enum: [booking.created, booking.updated, booking.cancelled, block.created, block.removed] }
                created_at: { type: string, format: date-time }
                club_id: { type: string, format: uuid }
                data:
                  type: object
                  properties:
                    id: { type: string, format: uuid }
                    court_id: { type: string, format: uuid }
                    external_court_id: { type: [string, "null"] }
                    start: { type: string, format: date-time }
                    end: { type: string, format: date-time }
                    status: { type: string }
                    kind: { type: string, enum: [booking, blocked] }
                    external_id: { type: [string, "null"] }
                    customer_name: { type: [string, "null"] }
                    customer_phone: { type: [string, "null"] }
                    players: { type: [integer, "null"] }
                    notes: { type: [string, "null"] }
      responses:
        "200": { description: Received }
