{
  "openapi": "3.1.0",
  "info": {
    "title": "Fishbowl External Loyalty API",
    "version": "2026-09-12",
    "description": "Server-to-server transactional loyalty API for approved POS and kiosk partners. Fishbowl provisions the credentials and permissions. Monetary amounts are expressed in currency units, such as 12.50 for twelve dollars and fifty cents."
  },
  "servers": [
    {
      "url": "https://api.fishbowl.com/api/l/loyalty",
      "description": "Fishbowl API"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/oauth/token": {
      "post": {
        "operationId": "createPartnerToken",
        "summary": "Exchange Fishbowl-provisioned credentials for a one-hour Bearer token",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/TokenRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Token issued",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/TokenResponse" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/Error" },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/accounts/resolve": {
      "post": {
        "operationId": "resolveAccount",
        "summary": "Find or create an account using a verified international phone number",
        "parameters": [
          { "$ref": "#/components/parameters/ContractVersion" }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/ResolveAccountRequest" }
            }
          }
        },
        "responses": {
          "200": { "$ref": "#/components/responses/ResolvedAccount" },
          "201": { "$ref": "#/components/responses/ResolvedAccount" },
          "400": { "$ref": "#/components/responses/Error" },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "409": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/accounts/{accountId}/inquiries": {
      "post": {
        "operationId": "inquireAccount",
        "summary": "Return rewards that are eligible for the current order without changing the ledger",
        "parameters": [
          { "$ref": "#/components/parameters/AccountId" },
          { "$ref": "#/components/parameters/ContractVersion" }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/InquiryRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Available points and eligible rewards",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/InquiryResponse" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/Error" },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/accounts/{accountId}/redemptions": {
      "post": {
        "operationId": "redeemReward",
        "summary": "Redeem one reward against the current order",
        "parameters": [
          { "$ref": "#/components/parameters/AccountId" },
          { "$ref": "#/components/parameters/ContractVersion" }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/RedemptionRequest" }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Reward redeemed",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/RedemptionResponse" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/Error" },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "409": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/accounts/{accountId}/accruals": {
      "post": {
        "operationId": "accruePurchase",
        "summary": "Accrue points for a completed purchase",
        "parameters": [
          { "$ref": "#/components/parameters/AccountId" },
          { "$ref": "#/components/parameters/ContractVersion" }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/AccrualRequest" }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Purchase accrual applied",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/AccrualResponse" }
              }
            }
          },
          "202": {
            "description": "Purchase accrual accepted for reconciliation",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/AccrualResponse" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/Error" },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "409": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    },
    "parameters": {
      "ContractVersion": {
        "name": "Fishbowl-Loyalty-Version",
        "in": "header",
        "required": true,
        "schema": { "type": "string", "const": "2026-09-12" }
      },
      "AccountId": {
        "name": "accountId",
        "in": "path",
        "required": true,
        "schema": { "type": "string", "format": "uuid" }
      }
    },
    "schemas": {
      "TokenRequest": {
        "type": "object",
        "required": ["grant_type", "client_id", "client_secret"],
        "properties": {
          "grant_type": { "type": "string", "const": "client_credentials" },
          "client_id": { "type": "string", "format": "uuid" },
          "client_secret": {
            "type": "string",
            "minLength": 47,
            "maxLength": 47,
            "pattern": "^fbl_[A-Za-z0-9_-]{43}$"
          }
        },
        "additionalProperties": false
      },
      "TokenResponse": {
        "type": "object",
        "required": ["access_token", "token_type", "expires_in", "scope"],
        "properties": {
          "access_token": { "type": "string" },
          "token_type": { "type": "string", "const": "Bearer" },
          "expires_in": { "type": "integer", "const": 3600 },
          "scope": {
            "type": "string",
            "example": "loyalty:account:resolve loyalty:inquire loyalty:redeem loyalty:accrue"
          }
        },
        "additionalProperties": false
      },
      "ResolveAccountRequest": {
        "type": "object",
        "required": ["phoneNumber", "phoneVerified"],
        "properties": {
          "programId": { "type": "string", "format": "uuid" },
          "phoneNumber": { "type": "string", "pattern": "^\\+[1-9][0-9]{7,14}$" },
          "phoneVerified": {
            "type": "boolean",
            "const": true,
            "description": "Assertion that the confidential partner backend already verified possession of this phone number."
          },
          "createIfMissing": { "type": "boolean", "default": true },
          "firstName": { "type": "string", "maxLength": 100 },
          "lastName": { "type": "string", "maxLength": 100 },
          "emailAddress": { "type": "string", "format": "email" },
          "birthdate": { "type": "string", "format": "date" }
        },
        "additionalProperties": false
      },
      "ResolvedAccount": {
        "type": "object",
        "required": ["accountId", "created"],
        "properties": {
          "accountId": { "type": "string", "format": "uuid" },
          "created": { "type": "boolean" }
        },
        "additionalProperties": false
      },
      "Order": {
        "type": "object",
        "required": ["subtotal", "items"],
        "properties": {
          "subtotal": {
            "type": "number",
            "minimum": 0,
            "description": "Current pre-tax order subtotal in currency units after existing non-loyalty discounts."
          },
          "items": {
            "type": "array",
            "maxItems": 500,
            "items": { "$ref": "#/components/schemas/OrderLineItem" }
          }
        },
        "additionalProperties": false
      },
      "OrderLineItem": {
        "type": "object",
        "required": ["lineItemId", "unitPrice", "quantity"],
        "properties": {
          "lineItemId": {
            "type": "string",
            "maxLength": 200,
            "description": "Stable identifier for this line within the partner order."
          },
          "productId": { "type": "string", "maxLength": 200 },
          "name": { "type": "string", "maxLength": 300 },
          "categoryId": { "type": "string", "maxLength": 200 },
          "categoryName": { "type": "string", "maxLength": 300 },
          "unitPrice": { "type": "number", "minimum": 0 },
          "quantity": { "type": "integer", "minimum": 1, "maximum": 10000 },
          "tags": {
            "type": "array",
            "maxItems": 100,
            "items": { "type": "string", "maxLength": 200 }
          },
          "discounted": { "type": "boolean", "default": false },
          "comped": { "type": "boolean", "default": false },
          "voided": { "type": "boolean", "default": false }
        },
        "additionalProperties": false
      },
      "InquiryRequest": {
        "type": "object",
        "required": ["order"],
        "properties": {
          "order": { "$ref": "#/components/schemas/Order" }
        },
        "additionalProperties": false
      },
      "Points": {
        "type": "object",
        "required": ["available", "monetaryValue"],
        "properties": {
          "available": { "type": "number" },
          "monetaryValue": { "type": "number" }
        },
        "additionalProperties": false
      },
      "LineItemDiscount": {
        "type": "object",
        "required": ["lineItemId", "discountAmount"],
        "properties": {
          "lineItemId": { "type": "string" },
          "discountAmount": { "type": "number", "minimum": 0 }
        },
        "additionalProperties": false
      },
      "TransactionReward": {
        "type": "object",
        "required": ["rewardId", "name", "description", "discountAmount", "lineItemDiscounts"],
        "properties": {
          "rewardId": { "type": "string", "format": "uuid" },
          "name": { "type": "string" },
          "description": { "type": "string" },
          "discountAmount": {
            "type": "number",
            "minimum": 0,
            "description": "Total discount for this reward in currency units."
          },
          "lineItemDiscounts": {
            "type": "array",
            "description": "Line-level discount allocation for item-specific rewards. Empty for an order-level reward.",
            "items": { "$ref": "#/components/schemas/LineItemDiscount" }
          }
        },
        "additionalProperties": false
      },
      "InquiryResult": {
        "type": "object",
        "required": ["points", "rewards"],
        "properties": {
          "points": { "$ref": "#/components/schemas/Points" },
          "rewards": {
            "type": "array",
            "description": "Only rewards currently eligible for the supplied order.",
            "items": { "$ref": "#/components/schemas/TransactionReward" }
          }
        },
        "additionalProperties": false
      },
      "RedemptionRequest": {
        "type": "object",
        "required": ["transactionId", "rewardId", "order"],
        "properties": {
          "transactionId": {
            "type": "string",
            "maxLength": 200,
            "description": "Stable partner order identifier. Reuse this value and the same request body when retrying redemption."
          },
          "rewardId": { "type": "string", "format": "uuid" },
          "order": { "$ref": "#/components/schemas/Order" }
        },
        "additionalProperties": false
      },
      "Redemption": {
        "type": "object",
        "required": ["transactionId", "reward", "points"],
        "properties": {
          "transactionId": { "type": "string" },
          "reward": { "$ref": "#/components/schemas/TransactionReward" },
          "points": { "$ref": "#/components/schemas/Points" }
        },
        "additionalProperties": false
      },
      "AccrualRequest": {
        "type": "object",
        "required": ["transactionId", "amount"],
        "properties": {
          "transactionId": {
            "type": "string",
            "maxLength": 200,
            "description": "Stable partner order identifier. Use the same value as redemption and reuse it with the same request body when retrying accrual."
          },
          "amount": {
            "type": "number",
            "minimum": 0,
            "description": "Final qualifying purchase amount in currency units."
          }
        },
        "additionalProperties": false
      },
      "Accrual": {
        "type": "object",
        "required": ["transactionId", "status", "pointsAwarded"],
        "properties": {
          "transactionId": { "type": "string" },
          "status": { "type": "string", "enum": ["applied", "queued"] },
          "pointsAwarded": { "type": ["number", "null"] },
          "reconciliationId": { "type": "string" }
        },
        "additionalProperties": false
      },
      "Error": {
        "type": "object",
        "required": ["success", "message"],
        "properties": {
          "success": { "type": "boolean", "const": false },
          "message": { "type": "string" },
          "details": { "type": ["object", "null"], "additionalProperties": true }
        },
        "additionalProperties": false
      },
      "SuccessResponse": {
        "type": "object",
        "required": ["success", "message", "data"],
        "properties": {
          "success": { "type": "boolean", "const": true },
          "message": { "type": "string" }
        }
      },
      "ResolvedAccountResponse": {
        "allOf": [
          { "$ref": "#/components/schemas/SuccessResponse" },
          { "type": "object", "properties": { "data": { "$ref": "#/components/schemas/ResolvedAccount" } } }
        ]
      },
      "InquiryResponse": {
        "allOf": [
          { "$ref": "#/components/schemas/SuccessResponse" },
          { "type": "object", "properties": { "data": { "$ref": "#/components/schemas/InquiryResult" } } }
        ]
      },
      "RedemptionResponse": {
        "allOf": [
          { "$ref": "#/components/schemas/SuccessResponse" },
          { "type": "object", "properties": { "data": { "$ref": "#/components/schemas/Redemption" } } }
        ]
      },
      "AccrualResponse": {
        "allOf": [
          { "$ref": "#/components/schemas/SuccessResponse" },
          { "type": "object", "properties": { "data": { "$ref": "#/components/schemas/Accrual" } } }
        ]
      }
    },
    "responses": {
      "ResolvedAccount": {
        "description": "Account resolved",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/ResolvedAccountResponse" }
          }
        }
      },
      "Error": {
        "description": "Request rejected",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Error" }
          }
        }
      },
      "RateLimited": {
        "description": "The application or source-IP request allowance is exhausted. Honor Retry-After when present.",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Error" }
          }
        }
      }
    }
  }
}
