openapi: 3.1.0
info:
  title: Pear Shipping API
  version: 2026-12-05
  description: Role-aware direct-carrier shipping API for hosted, embedded, and server integrations.
  license:
    name: Proprietary
    identifier: LicenseRef-Proprietary
servers:
  - url: https://app.pearshipping.com
security:
  - bearerAuth: []
paths:
  /v1/sandbox/scenarios:
    get:
      security: []
      operationId: listSandboxScenarios
      summary: List safe simulated carrier and operations scenarios
      responses:
        "200": { description: Non-purchasable sample scenario catalog }
  /v1/sandbox/run:
    post:
      security: []
      operationId: runSandboxScenario
      summary: Run a deterministic sample without carrier calls or postage purchase
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [scenario]
              properties: { scenario: { type: string }, input: { type: object } }
      responses:
        "200": { description: Clearly watermarked, non-purchasable sample result }
        default: { $ref: "#/components/responses/Problem" }
  /v1/operations/overview:
    get:
      operationId: getOperationsOverview
      summary: Retrieve tenant shipment, webhook, purchase, adjustment, and carrier totals
      responses:
        "200": { description: Operations summary }
        default: { $ref: "#/components/responses/Problem" }
  /v1/operations/carriers:
    get:
      operationId: getCarrierReadiness
      summary: Retrieve redacted connection, approval, and safety-gate status for launch carriers
      responses:
        "200": { description: Carrier readiness states }
        default: { $ref: "#/components/responses/Problem" }
  /v1/operations/review:
    get:
      operationId: listOperationsReviewQueue
      summary: List shipments and purchase attempts requiring human review
      responses:
        "200": { description: Human review queue }
        default: { $ref: "#/components/responses/Problem" }
  /v1/operations/reconciliation:
    get:
      operationId: listReconciliation
      summary: Compare payment, postage purchase, and carrier adjustment records
      responses:
        "200": { description: Reconciliation states }
        default: { $ref: "#/components/responses/Problem" }
  /v1/operations/audit:
    get:
      operationId: listAuditLog
      summary: Retrieve security-sensitive administrative and carrier action history
      responses:
        "200": { description: Tenant audit trail }
        default: { $ref: "#/components/responses/Problem" }
  /v1/carrier-connections:
    get:
      operationId: listCarrierConnections
      summary: List redacted carrier connections
      responses:
        "200": { description: Redacted carrier connection metadata }
        default: { $ref: "#/components/responses/Problem" }
    post:
      operationId: upsertCarrierConnection
      summary: Encrypt and activate a carrier connection for the current environment
      responses:
        "201": { description: Carrier connection saved }
        default: { $ref: "#/components/responses/Problem" }
  /v1/carrier-connections/{connectionId}/disable:
    post:
      operationId: disableCarrierConnection
      summary: Disable a carrier connection without deleting credentials or audit history
      parameters:
        - { name: connectionId, in: path, required: true, schema: { type: string, format: uuid } }
      responses:
        "200": { description: Connection disabled }
        default: { $ref: "#/components/responses/Problem" }
  /v1/capabilities:
    get:
      security: []
      operationId: getCapabilities
      summary: Discover supported integration and carrier capabilities
      responses:
        "200":
          description: Current capabilities
          content:
            application/json:
              schema: { type: object }
        "400": { $ref: "#/components/responses/Problem" }
  /v1/pricing:
    get:
      security: []
      operationId: getPricing
      summary: Retrieve published Pear pricing and an optional monthly estimate
      parameters:
        - { name: plan, in: query, schema: { type: string, enum: [sandbox, free, pro, platform] } }
        - { name: labels, in: query, schema: { type: integer, minimum: 0 } }
      responses:
        "200": { description: Published pricing terms and optional estimate }
        "400": { $ref: "#/components/responses/Problem" }
        default: { $ref: "#/components/responses/Problem" }
  /v1/integrations/catalog:
    get:
      security: []
      operationId: listIntegrationCatalog
      summary: Discover Pear integration foundations, API-ready platforms, and planned native connectors
      responses:
        "200": { description: Versioned integration catalog }
        default: { $ref: "#/components/responses/Problem" }
  /v1/integrations/recipes:
    get:
      security: []
      operationId: listIntegrationRecipes
      summary: List reusable order, shipping, tracking, exception, and return workflows
      responses:
        "200": { description: Versioned integration recipes }
        default: { $ref: "#/components/responses/Problem" }
  /v1/integrations/connections:
    get:
      operationId: listIntegrationConnections
      summary: List redacted integration connections for the authenticated business
      responses:
        "200": { description: Integration connections }
        default: { $ref: "#/components/responses/Problem" }
    post:
      operationId: createIntegrationConnection
      summary: Create an encrypted connection for an available Pear integration foundation
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [provider]
              properties:
                provider: { type: string }
                displayName: { type: string, maxLength: 100 }
                externalAccountId: { type: string, maxLength: 160 }
                connectionMode: { type: string, enum: [api, webhook, manual, file] }
                credentials: { type: object }
                scopes: { type: array, items: { type: string } }
                capabilities: { type: array, items: { type: string } }
                settings: { type: object }
      responses:
        "201": { description: Encrypted integration connection created }
        default: { $ref: "#/components/responses/Problem" }
  /v1/public/branding:
    get:
      security: []
      operationId: getPublicBranding
      summary: Retrieve the verified public theme for a Pear workspace or custom hostname
      parameters:
        - { name: workspace, in: query, schema: { type: string, maxLength: 100 } }
      responses:
        "200":
          description: Public-safe brand theme
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Branding" }
        default: { $ref: "#/components/responses/Problem" }
  /v1/package-intelligence/analyze:
    post:
      security: []
      operationId: analyzePackage
      summary: Calculate DIM risk and carrier packaging-program candidates without quoting or purchasing postage
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/Parcel" }
      responses:
        "200":
          description: Advisory packaging analysis; a live carrier response still controls eligibility and price
          content:
            application/json:
              schema: { $ref: "#/components/schemas/PackageAnalysis" }
        default: { $ref: "#/components/responses/Problem" }
  /v1/branding:
    get:
      operationId: getBranding
      summary: Retrieve Business Pro branding for the authenticated workspace
      responses:
        "200":
          description: Workspace branding
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Branding" }
        default: { $ref: "#/components/responses/Problem" }
    put:
      operationId: updateBranding
      summary: Save Business Pro branding; Platform workspaces may also stage a custom domain
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/Branding" }
      responses:
        "200":
          description: Updated workspace branding
          content:
            application/json:
              schema: { $ref: "#/components/schemas/Branding" }
        default: { $ref: "#/components/responses/Problem" }
  /v1/public/shipments:
    post:
      security: []
      operationId: createPublicShipment
      summary: Start a rate-comparison shipment without an API key when public shipping is enabled
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: "#/components/schemas/CreateShipment"
                - type: object
                  description: Public shipments always use merchant mode and cannot add business handling fees.
      responses:
        "201": { description: Public shipment and private merchant link created }
        default: { $ref: "#/components/responses/Problem" }
  /v1/intents/interpret:
    post:
      operationId: interpretShippingIntent
      summary: Preview how Pear translates a business outcome into a controlled shipping workflow
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/ShippingIntent" }
      responses:
        "200": { description: Deterministic intent interpretation }
        "400": { $ref: "#/components/responses/Problem" }
        default: { $ref: "#/components/responses/Problem" }
  /v1/intents:
    post:
      operationId: createShippingIntent
      summary: Create the correct shipment or linked shipment group from one universal intent
      parameters:
        - $ref: "#/components/parameters/IdempotencyKey"
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/ShippingIntent" }
      responses:
        "201": { description: Shipment or shipment group created from the intent }
        "400": { $ref: "#/components/responses/Problem" }
        default: { $ref: "#/components/responses/Problem" }
  /v1/shipments:
    post:
      operationId: createShipment
      summary: Create a shipping intent and role-scoped links
      parameters:
        - $ref: "#/components/parameters/IdempotencyKey"
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/CreateShipment" }
      responses:
        "201":
          description: Shipment created
          content:
            application/json:
              schema: { $ref: "#/components/schemas/CreatedShipment" }
        "400": { $ref: "#/components/responses/Problem" }
        default: { $ref: "#/components/responses/Problem" }
    get:
      operationId: listShipments
      summary: List shipments for the authenticated tenant
      parameters:
        - { name: limit, in: query, schema: { type: integer, minimum: 1, maximum: 100, default: 25 } }
        - { name: cursor, in: query, schema: { type: string, format: date-time } }
        - { name: state, in: query, schema: { $ref: "#/components/schemas/ShipmentState" } }
      responses:
        "200":
          description: Shipment page
          content:
            application/json:
              schema:
                type: object
                required: [data]
                properties:
                  data: { type: array, items: { $ref: "#/components/schemas/Shipment" } }
                  nextCursor: { type: [string, "null"], format: date-time }
        "400": { $ref: "#/components/responses/Problem" }
        default: { $ref: "#/components/responses/Problem" }
  /v1/shipments/{shipmentId}:
    get:
      operationId: getShipment
      summary: Retrieve a shipment and active rates
      parameters: [ { $ref: "#/components/parameters/ShipmentId" } ]
      responses:
        "200":
          description: Shipment
          content:
            application/json:
              schema:
                type: object
                properties:
                  shipment: { $ref: "#/components/schemas/Shipment" }
                  rates: { type: array, items: { $ref: "#/components/schemas/Rate" } }
        "400": { $ref: "#/components/responses/Problem" }
        default: { $ref: "#/components/responses/Problem" }
  /v1/shipments/{shipmentId}/quotes:
    post:
      operationId: quoteShipment
      summary: Validate required data and compare connected carriers
      parameters: [ { $ref: "#/components/parameters/ShipmentId" } ]
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                recipient: { $ref: "#/components/schemas/Address" }
                parcel: { $ref: "#/components/schemas/Parcel" }
      responses:
        "200":
          description: Normalized eligible rates
          content:
            application/json:
              schema:
                type: object
                properties:
                  shipment: { $ref: "#/components/schemas/Shipment" }
                  rates: { type: array, items: { $ref: "#/components/schemas/Rate" } }
                  carrierStatus: { type: object, additionalProperties: { type: string } }
        "400": { $ref: "#/components/responses/Problem" }
        default: { $ref: "#/components/responses/Problem" }
  /v1/shipments/{shipmentId}/checkout:
    post:
      operationId: startCheckout
      summary: Select an eligible rate and fund the shipment
      parameters: [ { $ref: "#/components/parameters/ShipmentId" } ]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [rateId]
              properties:
                rateId: { type: string, format: uuid }
                returnPath: { type: string, maxLength: 500 }
      responses:
        "200":
          description: Checkout transition
          content:
            application/json:
              schema:
                type: object
                properties:
                  state: { type: string }
                  checkoutUrl: { type: [string, "null"], format: uri }
        "400": { $ref: "#/components/responses/Problem" }
        default: { $ref: "#/components/responses/Problem" }
  /v1/shipments/{shipmentId}/tracking:
    get:
      operationId: getTracking
      summary: Retrieve a normalized tracking timeline
      parameters: [ { $ref: "#/components/parameters/ShipmentId" } ]
      responses:
        "200":
          description: Tracking timeline
          content:
            application/json:
              schema: { type: object }
        "400": { $ref: "#/components/responses/Problem" }
        default: { $ref: "#/components/responses/Problem" }
  /v1/shipments/{shipmentId}/label:
    get:
      operationId: downloadLabel
      summary: Download a private label when the caller role permits it
      parameters: [ { $ref: "#/components/parameters/ShipmentId" } ]
      responses:
        "200": { description: Carrier label, content: { application/pdf: {}, image/gif: {}, image/png: {}, application/zpl: {} } }
        "400": { $ref: "#/components/responses/Problem" }
        default: { $ref: "#/components/responses/Problem" }
  /v1/shipments/{shipmentId}/labels:
    get:
      operationId: listShipmentLabels
      summary: List every package label and tracking number in a multi-package shipment
      parameters: [ { $ref: "#/components/parameters/ShipmentId" } ]
      responses:
        "200": { description: Ordered shipment labels }
        default: { $ref: "#/components/responses/Problem" }
  /v1/shipments/{shipmentId}/labels/{labelId}:
    get:
      operationId: downloadShipmentLabel
      summary: Download one package label
      parameters:
        - { $ref: "#/components/parameters/ShipmentId" }
        - { name: labelId, in: path, required: true, schema: { type: string, format: uuid } }
      responses:
        "200": { description: Carrier label, content: { application/pdf: {}, image/png: {}, application/zpl: {} } }
        default: { $ref: "#/components/responses/Problem" }
  /v1/shipments/{shipmentId}/cancel:
    post:
      operationId: cancelShipment
      summary: Cancel an issued shipment before carrier acceptance
      parameters: [ { $ref: "#/components/parameters/ShipmentId" } ]
      responses:
        "200": { description: Carrier-confirmed cancellation }
        default: { $ref: "#/components/responses/Problem" }
  /v1/carrier-connections:
    post:
      operationId: connectCarrier
      summary: Store encrypted direct-carrier credentials
      requestBody:
        required: true
        content:
          application/json:
            schema: { type: object }
      responses:
        "201": { description: Carrier connection stored }
        "400": { $ref: "#/components/responses/Problem" }
        default: { $ref: "#/components/responses/Problem" }
  /v1/fedex/eula:
    get:
      security: []
      operationId: getFedexEula
      summary: Read the current hosted FedEx EULA metadata and required acceptance label
      responses:
        "200": { description: FedEx EULA metadata }
        default: { $ref: "#/components/responses/Problem" }
  /v1/fedex/onboarding:
    post:
      operationId: startFedexOnboarding
      summary: Start FedEx customer-account registration after EULA acceptance
      requestBody:
        required: true
        content:
          application/json:
            schema: { type: object }
      responses:
        "201": { description: FedEx onboarding session created }
        default: { $ref: "#/components/responses/Problem" }
  /v1/fedex/onboarding/{sessionId}:
    get:
      operationId: getFedexOnboarding
      summary: Read a redacted FedEx onboarding session
      parameters:
        - { name: sessionId, in: path, required: true, schema: { type: string, format: uuid } }
      responses:
        "200": { description: FedEx onboarding status }
        default: { $ref: "#/components/responses/Problem" }
  /v1/fedex/onboarding/{sessionId}/pin:
    post:
      operationId: sendFedexOnboardingPin
      summary: Send a FedEx account-registration verification PIN
      parameters:
        - { name: sessionId, in: path, required: true, schema: { type: string, format: uuid } }
      responses:
        "200": { description: PIN delivery initiated }
        default: { $ref: "#/components/responses/Problem" }
  /v1/fedex/onboarding/{sessionId}/verify-pin:
    post:
      operationId: verifyFedexOnboardingPin
      summary: Verify a FedEx PIN and save encrypted child credentials
      parameters:
        - { name: sessionId, in: path, required: true, schema: { type: string, format: uuid } }
      responses:
        "200": { description: FedEx account connected }
        default: { $ref: "#/components/responses/Problem" }
  /v1/fedex/onboarding/{sessionId}/verify-invoice:
    post:
      operationId: verifyFedexOnboardingInvoice
      summary: Verify FedEx invoice details and save encrypted child credentials
      parameters:
        - { name: sessionId, in: path, required: true, schema: { type: string, format: uuid } }
      responses:
        "200": { description: FedEx account connected }
        default: { $ref: "#/components/responses/Problem" }
  /v1/fedex/validation-evidence:
    get:
      operationId: listFedexValidationEvidence
      summary: List private redacted FedEx validation request and response evidence
      responses:
        "200": { description: FedEx validation evidence index }
        default: { $ref: "#/components/responses/Problem" }
  /v1/fedex/pickups/availability:
    post:
      operationId: getFedexPickupAvailability
      summary: Check FedEx pickup availability for an address and package set
      responses:
        "200": { description: Eligible pickup windows }
        default: { $ref: "#/components/responses/Problem" }
  /v1/fedex/pickups:
    post:
      operationId: createFedexPickup
      summary: Schedule a FedEx pickup when the account and production gates allow it
      responses:
        "201": { description: Confirmed pickup }
        default: { $ref: "#/components/responses/Problem" }
  /v1/fedex/pickups/{pickupId}/cancel:
    post:
      operationId: cancelFedexPickup
      summary: Cancel a previously scheduled FedEx pickup
      parameters:
        - { name: pickupId, in: path, required: true, schema: { type: string, format: uuid } }
      responses:
        "200": { description: Pickup cancelled }
        default: { $ref: "#/components/responses/Problem" }
  /v1/webhook-endpoints:
    post:
      operationId: createWebhookEndpoint
      summary: Register an HTTPS endpoint and receive a one-time signing secret
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [url]
              properties:
                url: { type: string, format: uri }
                eventTypes: { type: array, items: { type: string } }
      responses:
        "201": { description: Webhook endpoint created }
        "400": { $ref: "#/components/responses/Problem" }
        default: { $ref: "#/components/responses/Problem" }
  /v1/webhook-events:
    get:
      operationId: listWebhookEvents
      summary: Inspect recent event delivery outcomes
      parameters:
        - { name: limit, in: query, schema: { type: integer, minimum: 1, maximum: 100, default: 25 } }
      responses:
        "200": { description: Recent events and delivery counts }
        "400": { $ref: "#/components/responses/Problem" }
        default: { $ref: "#/components/responses/Problem" }
  /v1/webhook-events/{eventId}/replay:
    post:
      operationId: replayWebhookEvent
      summary: Queue a safe replay of a tenant-owned event
      parameters:
        - name: eventId
          in: path
          required: true
          schema: { type: string, format: uuid }
      responses:
        "202": { description: Replay queued }
        "400": { $ref: "#/components/responses/Problem" }
        default: { $ref: "#/components/responses/Problem" }
  /v1/shipment-groups:
    post:
      operationId: createShipmentGroup
      summary: Create linked shipping legs for a trade, exchange, return, repair, consignment, or drop shipment
      parameters:
        - $ref: "#/components/parameters/IdempotencyKey"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [purpose, legs]
              properties:
                externalId: { type: string, maxLength: 100 }
                purpose: { type: string, enum: [single, trade, exchange, return, repair, consignment, drop_ship] }
                title: { type: string, maxLength: 120 }
                policy: { $ref: "#/components/schemas/Policy" }
                metadata: { type: object }
                legs:
                  type: array
                  minItems: 1
                  maxItems: 6
                  items:
                    allOf:
                      - $ref: "#/components/schemas/CreateShipment"
                      - type: object
                        properties: { key: { type: string, maxLength: 40 } }
      responses:
        "201": { description: Linked shipment group created }
        "400": { $ref: "#/components/responses/Problem" }
        default: { $ref: "#/components/responses/Problem" }
  /v1/shipment-groups/{groupId}:
    get:
      operationId: getShipmentGroup
      summary: Retrieve a linked shipment group and every leg
      parameters:
        - name: groupId
          in: path
          required: true
          schema: { type: string, format: uuid }
      responses:
        "200": { description: Linked shipment group }
        "400": { $ref: "#/components/responses/Problem" }
        default: { $ref: "#/components/responses/Problem" }
  /v1/orders:
    post:
      operationId: importOrder
      summary: Idempotently ingest a normalized order from any channel and optionally create its shipment
      parameters:
        - $ref: "#/components/parameters/IdempotencyKey"
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/ImportedOrder" }
      responses:
        "200": { description: Order imported or updated }
        "400": { $ref: "#/components/responses/Problem" }
        default: { $ref: "#/components/responses/Problem" }
  /v1/orders/{orderId}:
    get:
      operationId: getOrder
      summary: Retrieve a normalized imported order
      parameters:
        - name: orderId
          in: path
          required: true
          schema: { type: string, format: uuid }
      responses:
        "200": { description: Imported order }
        "400": { $ref: "#/components/responses/Problem" }
        default: { $ref: "#/components/responses/Problem" }
  /v1/rules:
    get:
      operationId: listRules
      summary: List deterministic shipping rules
      responses:
        "200": { description: Shipping rules }
        "400": { $ref: "#/components/responses/Problem" }
        default: { $ref: "#/components/responses/Problem" }
    post:
      operationId: createRule
      summary: Create a deterministic shipping rule
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: "#/components/schemas/ShippingRule" }
      responses:
        "201": { description: Shipping rule created }
        "400": { $ref: "#/components/responses/Problem" }
        default: { $ref: "#/components/responses/Problem" }
  /v1/rules/{ruleId}/status:
    post:
      operationId: setRuleStatus
      summary: Activate, pause, or archive a rule
      parameters:
        - name: ruleId
          in: path
          required: true
          schema: { type: string, format: uuid }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [status]
              properties: { status: { type: string, enum: [active, paused, archived] } }
      responses:
        "200": { description: Updated rule }
        "400": { $ref: "#/components/responses/Problem" }
        default: { $ref: "#/components/responses/Problem" }
  /v1/shipments/{shipmentId}/returns:
    post:
      operationId: createReturn
      summary: Create a linked reverse shipment from an original shipment
      parameters:
        - $ref: "#/components/parameters/ShipmentId"
        - $ref: "#/components/parameters/IdempotencyKey"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [reasonCode]
              properties:
                reasonCode: { type: string, enum: [changed_mind, wrong_item, damaged, defective, not_as_described, size_or_fit, exchange, repair, other] }
                reasonText: { type: string, maxLength: 500 }
                disposition: { type: string, maxLength: 80 }
                parcel: { $ref: "#/components/schemas/Parcel" }
                policy: { $ref: "#/components/schemas/Policy" }
      responses:
        "201": { description: Return request and reverse shipment created }
        "400": { $ref: "#/components/responses/Problem" }
        default: { $ref: "#/components/responses/Problem" }
  /v1/returns/{returnId}:
    get:
      operationId: getReturn
      summary: Retrieve a return and its original and reverse shipments
      parameters:
        - name: returnId
          in: path
          required: true
          schema: { type: string, format: uuid }
      responses:
        "200": { description: Return request }
        "400": { $ref: "#/components/responses/Problem" }
        default: { $ref: "#/components/responses/Problem" }
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: Pear API key
  parameters:
    ShipmentId:
      name: shipmentId
      in: path
      required: true
      schema: { type: string, format: uuid }
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: true
      schema: { type: string, minLength: 8, maxLength: 128 }
  responses:
    Problem:
      description: Pear problem response
      content:
        application/json:
          schema:
            type: object
            required: [error]
            properties:
              error:
                type: object
                required: [code, message]
                properties:
                  code: { type: string }
                  message: { type: string }
                  details: {}
  schemas:
    ShippingIntent:
      type: object
      required: [goal]
      properties:
        specification: { type: string, const: pear-shipping-intent/1.0 }
        externalId: { type: string, maxLength: 100 }
        goal: { type: string, enum: [deliver, return, exchange, trade, repair, consignment, drop_ship] }
        payer: { type: string, enum: [merchant, recipient, supplier], default: merchant }
        chooser: { type: string, enum: [merchant, recipient, supplier] }
        packer: { type: string, enum: [merchant, recipient, supplier], default: merchant }
        speed: { type: string, enum: [lowest_cost, ground, fastest, arrive_by], default: lowest_cost }
        arriveBy: { type: string, format: date }
        merchantCoversCents: { type: integer, minimum: 0 }
        handlingFeeCents: { type: integer, minimum: 0 }
        preferences: { type: array, items: { type: string } }
        allowedCarriers: { type: array, items: { type: string, enum: [USPS, UPS, FEDEX, DHL] } }
        hiddenServices: { type: array, items: { type: string } }
        sender: { $ref: "#/components/schemas/Address" }
        recipient: { $ref: "#/components/schemas/Address" }
        parcel: { $ref: "#/components/schemas/Parcel" }
        legs: { type: array, minItems: 1, maxItems: 6, items: { $ref: "#/components/schemas/CreateShipment" } }
    Address:
      type: object
      required: [name, street1, city, state, postalCode]
      properties:
        name: { type: string, maxLength: 100 }
        company: { type: string, maxLength: 100 }
        street1: { type: string, maxLength: 120 }
        street2: { type: string, maxLength: 120 }
        city: { type: string, maxLength: 80 }
        state: { type: string, minLength: 2, maxLength: 3 }
        postalCode: { type: string, minLength: 3, maxLength: 10 }
        country: { type: string, pattern: "^[A-Z]{2}$", default: US }
        phone: { type: string }
        email: { type: string, format: email }
        residential: { type: boolean, default: true }
    Parcel:
      type: object
      required: [lengthIn, widthIn, heightIn, weightOz]
      properties:
        lengthIn: { type: number, exclusiveMinimum: 0, maximum: 108 }
        widthIn: { type: number, exclusiveMinimum: 0, maximum: 108 }
        heightIn: { type: number, exclusiveMinimum: 0, maximum: 108 }
        weightOz: { type: number, exclusiveMinimum: 0, maximum: 2400 }
        packaging: { type: string, default: CUSTOM }
        declaredValueCents: { type: integer, minimum: 0, maximum: 5000000 }
        description: { type: string, maxLength: 100 }
    Branding:
      type: object
      properties:
        displayName: { type: string, maxLength: 100 }
        tagline: { type: string, maxLength: 160 }
        logoUrl: { type: [string, "null"] }
        primaryColor: { type: string, pattern: "^#[0-9A-Fa-f]{6}$" }
        accentColor: { type: string, pattern: "^#[0-9A-Fa-f]{6}$" }
        backgroundColor: { type: string, pattern: "^#[0-9A-Fa-f]{6}$" }
        supportEmail: { type: string, format: email }
        websiteUrl: { type: [string, "null"], format: uri }
        customDomain: { type: [string, "null"] }
        customDomainStatus: { type: string, enum: [not_configured, pending, active, failed] }
        poweredByPear: { type: boolean }
        whiteLabelEnabled: { type: boolean }
    PackageProgram:
      type: object
      properties:
        code: { type: string }
        carrier: { type: string, enum: [USPS, UPS, FEDEX] }
        name: { type: string }
        eligible: { type: boolean }
        packaging: { type: string }
        explanation: { type: string }
        validation: { type: string, enum: [live_rate, account_validation, carrier_packaging] }
    PackageAnalysis:
      type: object
      required: [rulesVersion, calculations, risk, guidance, programs, eligiblePrograms, disclosure]
      properties:
        rulesVersion: { type: string }
        measurements: { type: object }
        calculations: { type: object }
        risk: { type: string, enum: [low, medium, high] }
        guidance: { type: array, items: { type: string } }
        programs: { type: array, items: { $ref: "#/components/schemas/PackageProgram" } }
        eligiblePrograms: { type: array, items: { $ref: "#/components/schemas/PackageProgram" } }
        recommendedProgramCode: { type: [string, "null"] }
        disclosure: { type: string }
    Policy:
      type: object
      properties:
        allowedCarriers:
          type: array
          items: { type: string, enum: [UPS, USPS, FEDEX, DHL] }
        hiddenServices: { type: array, items: { type: string } }
        packageProgram: { type: [string, "null"], description: Advisory comparison candidate selected by the shipper; live carrier eligibility and price still control. }
        subsidyCapCents: { type: integer, minimum: 0 }
        handlingFeeCents: { type: integer, minimum: 0 }
        requireTracking: { type: boolean, default: true }
        signature: { type: string }
        speed: { type: string, enum: [lowest_cost, ground, fastest, arrive_by] }
        arriveBy: { type: [string, "null"], format: date }
        preferredCarrier: { type: string, enum: [UPS, USPS, FEDEX, DHL], default: FEDEX }
        labelFormat: { type: string, enum: [PDF, PNG, ZPLII], default: PDF }
        shipDate: { type: [string, "null"], format: date }
        pickupType: { type: string, enum: [DROPOFF_AT_FEDEX_LOCATION, USE_SCHEDULED_PICKUP, CONTACT_FEDEX_TO_SCHEDULE] }
        packagingType: { type: string }
        serviceType: { type: [string, "null"] }
        saturdayDelivery: { type: boolean }
        alcohol: { type: boolean }
        authenticatedDelivery: { type: boolean }
        homeDeliveryType: { type: [string, "null"], enum: [APPOINTMENT, DATE_CERTAIN, EVENING, null] }
        returnType: { type: [string, "null"], enum: [PRINT_RETURN_LABEL, EMAIL_RETURN_LABEL, null] }
        declaredValueCents: { type: integer, minimum: 0, maximum: 5000000 }
        customs: { type: [object, "null"] }
        notifications: { type: array, maxItems: 6, items: { type: object } }
        billing: { type: object }
        testCaseId: { type: [string, "null"], maxLength: 80 }
    CreateShipment:
      type: object
      required: [mode, sender]
      properties:
        externalId: { type: string, maxLength: 100 }
        mode: { type: string, enum: [merchant, buyer, guided, supplier] }
        sender: { $ref: "#/components/schemas/Address" }
        recipient: { $ref: "#/components/schemas/Address" }
        parcel: { $ref: "#/components/schemas/Parcel" }
        packages:
          type: array
          minItems: 1
          maxItems: 200
          items: { $ref: "#/components/schemas/Parcel" }
        policy: { $ref: "#/components/schemas/Policy" }
    CreatedShipment:
      type: object
      required: [id, state, mode, merchantUrl, expiresAt]
      properties:
        id: { type: string, format: uuid }
        state: { type: string }
        mode: { type: string }
        merchantUrl: { type: string, format: uri }
        recipientUrl: { type: [string, "null"], format: uri }
        supplierUrl: { type: [string, "null"], format: uri }
        expiresAt: { type: string, format: date-time }
    ShipmentState:
      type: string
      enum: [draft, quoted, checkout, funded, purchasing, issued, in_transit, delivered, exception, cancelled, review]
    Shipment:
      type: object
      required: [id, mode, state, role, createdAt, updatedAt]
      properties:
        id: { type: string, format: uuid }
        externalId: { type: string }
        mode: { type: string, enum: [merchant, buyer, guided, supplier] }
        state: { $ref: "#/components/schemas/ShipmentState" }
        role: { type: string, enum: [merchant, recipient, supplier] }
        sender: { $ref: "#/components/schemas/Address" }
        recipient: { $ref: "#/components/schemas/Address" }
        parcel: { $ref: "#/components/schemas/Parcel" }
        policy: { $ref: "#/components/schemas/Policy" }
        carrier: { type: [string, "null"] }
        serviceCode: { type: [string, "null"] }
        trackingNumber: { type: [string, "null"] }
        labelAvailable: { type: boolean }
        labelCount: { type: integer, minimum: 0 }
        createdAt: { type: string, format: date-time }
        updatedAt: { type: string, format: date-time }
    Rate:
      type: object
      required: [id, carrier, serviceCode, serviceName, currency, amountDueCents, purchasable]
      properties:
        id: { type: string, format: uuid }
        carrier: { type: string }
        serviceCode: { type: string }
        serviceName: { type: string }
        currency: { type: string, enum: [usd] }
        postageCents: { type: integer, minimum: 0 }
        subsidyCents: { type: integer, minimum: 0 }
        handlingCents: { type: integer, minimum: 0 }
        platformFeeCents: { type: integer, minimum: 0 }
        pearServiceFeeCents: { type: integer, minimum: 0 }
        usageFeeCents: { type: integer, minimum: 0 }
        pearFeeCents: { type: integer, minimum: 0 }
        amountDueCents: { type: integer, minimum: 0 }
        deliveryDays: { type: [integer, "null"] }
        deliveryDate: { type: [string, "null"] }
        purchasable: { type: boolean }
    ImportedOrder:
      type: object
      required: [channel, externalOrderId, items]
      properties:
        channel: { type: string, maxLength: 50 }
        externalOrderId: { type: string, maxLength: 120 }
        status: { type: string, default: open }
        currency: { type: string, default: usd }
        totalCents: { type: integer, minimum: 0 }
        sender: { $ref: "#/components/schemas/Address" }
        recipient: { $ref: "#/components/schemas/Address" }
        order: { type: object }
        items:
          type: array
          maxItems: 500
          items:
            type: object
            required: [title, quantity]
            properties:
              externalItemId: { type: string }
              sku: { type: string }
              title: { type: string }
              quantity: { type: integer, minimum: 1 }
              unitPriceCents: { type: integer, minimum: 0 }
              weightOz: { type: number, minimum: 0 }
              dimensions: { type: object }
              metadata: { type: object }
        shipment: { $ref: "#/components/schemas/CreateShipment" }
    ShippingRule:
      type: object
      required: [name, conditions, actions]
      properties:
        name: { type: string, maxLength: 100 }
        priority: { type: integer, minimum: 0, maximum: 10000, default: 100 }
        conditions:
          type: object
          description: Use either `all` or `any` with up to 20 deterministic conditions.
        actions:
          type: object
          properties:
            allowedCarriers: { type: array, items: { type: string, enum: [UPS, USPS, FEDEX, DHL] } }
            hiddenServices: { type: array, items: { type: string } }
            subsidyCapCents: { type: integer, minimum: 0 }
            handlingFeeCents: { type: integer, minimum: 0 }
            signature: { type: string }
            requireTracking: { type: boolean }
