{
  "openapi": "3.1.0",
  "info": {
    "title": "Cedar Parcel API",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://sandbox.api.cedar-parcel.example/v1",
      "description": "Sandbox"
    },
    {
      "url": "https://api.cedar-parcel.example/v1",
      "description": "Production"
    }
  ],
  "security": [
    {
      "ServiceBearer": []
    },
    {
      "ParcelKey": []
    }
  ],
  "tags": [
    {
      "name": "Query",
      "description": "Search parcel records."
    }
  ],
  "paths": {
    "/Search/parcels/{scope}": {
      "get": {
        "tags": [
          "Query"
        ],
        "summary": "List parcel records",
        "description": "List records for an account or region. Use `downloadAs` to request a\nfile; the same successful status can return JSON, CSV, or a spreadsheet.\n",
        "operationId": "listParcels",
        "parameters": [
          {
            "name": "scope",
            "in": "path",
            "required": true,
            "description": "The account or region identifier.",
            "schema": {
              "type": "string"
            },
            "example": "region-demo"
          },
          {
            "name": "parameters",
            "in": "query",
            "description": "Placeholder for field/operator filters. Do not send `parameters=`.\nPut each expression directly in the URL, for example\n`declaredValue(gt)=100`.\n\nAccepted fields: `createdAt` (gt, ge, lt, le, eq),\n`declaredValue` (gt, ge, lt, le, eq), `carrier` (eq, ne, in),\n`recipientCity` (eq, ct), and `status` (eq, ne, in).\n`in` values are separated by `|`.\n",
            "schema": {
              "type": "object",
              "additionalProperties": {
                "type": "string"
              }
            },
            "examples": {
              "highValue": {
                "summary": "High declared value",
                "value": {
                  "declaredValue(gt)": 100
                }
              },
              "matchingCity": {
                "summary": "City contains text",
                "value": {
                  "recipientCity(ct)": "port"
                }
              }
            }
          },
          {
            "name": "downloadAs",
            "in": "query",
            "description": "Return a file instead of JSON when specified.",
            "schema": {
              "$ref": "#/components/schemas/ExportFormat"
            }
          },
          {
            "name": "skipRows",
            "in": "query",
            "description": "Number of records to skip.",
            "schema": {
              "type": "integer",
              "default": 0
            }
          },
          {
            "name": "maxRows",
            "in": "query",
            "description": "Maximum records to return. Zero or a negative value requests all records.",
            "schema": {
              "type": "integer",
              "default": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A page of records, or a downloadable file if `downloadAs` is set.\nThe response format depends on the query value.\n",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ParcelPage"
                },
                "examples": {
                  "firstPage": {
                    "summary": "First page",
                    "value": {
                      "records": [
                        {
                          "parcelId": "pcl_demo_001",
                          "status": "in_transit",
                          "declaredValue": 145.5,
                          "recipient": {
                            "city": "Northport",
                            "postalCode": "00012"
                          }
                        }
                      ],
                      "totalRecords": 1,
                      "nextCursor": null
                    }
                  }
                }
              },
              "text/csv": {
                "schema": {
                  "type": "string",
                  "description": "CSV rows with a header line."
                },
                "example": "parcelId,status,declaredValue\npcl_demo_001,in_transit,145.5\n"
              },
              "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": {
                "schema": {
                  "type": "string",
                  "format": "binary",
                  "description": "A spreadsheet download."
                }
              }
            }
          },
          "400": {
            "description": "A field name or comparison operator is unsupported.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ExportFormat": {
        "type": "string",
        "description": "Return a file instead of JSON when specified.",
        "enum": [
          "csv",
          "xlsx"
        ]
      },
      "Parcel": {
        "type": "object",
        "required": [
          "parcelId",
          "status",
          "declaredValue",
          "recipient"
        ],
        "properties": {
          "parcelId": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "label_created",
              "in_transit",
              "delivered",
              "exception"
            ]
          },
          "declaredValue": {
            "type": "number",
            "minimum": 0,
            "multipleOf": 0.01,
            "description": "Value in currency units, to the nearest cent."
          },
          "recipient": {
            "$ref": "#/components/schemas/Recipient"
          },
          "events": {
            "type": "array",
            "description": "Tracking history in chronological order.",
            "items": {
              "type": "object",
              "required": [
                "kind",
                "at"
              ],
              "properties": {
                "kind": {
                  "type": "string",
                  "enum": [
                    "pickup",
                    "scan",
                    "delivery"
                  ]
                },
                "at": {
                  "type": "string",
                  "format": "date-time"
                },
                "details": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              }
            }
          }
        }
      },
      "ParcelPage": {
        "type": "object",
        "minProperties": 3,
        "maxProperties": 3,
        "additionalProperties": false,
        "required": [
          "records",
          "totalRecords",
          "nextCursor"
        ],
        "properties": {
          "records": {
            "type": "array",
            "uniqueItems": true,
            "items": {
              "$ref": "#/components/schemas/Parcel"
            }
          },
          "totalRecords": {
            "type": "integer",
            "minimum": 0
          },
          "nextCursor": {
            "type": [
              "string",
              "null"
            ],
            "description": "Always present; null on the last page."
          }
        }
      },
      "Problem": {
        "type": "object",
        "required": [
          "type",
          "title",
          "status"
        ],
        "properties": {
          "type": {
            "type": "string",
            "format": "uri"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          }
        }
      },
      "Recipient": {
        "type": "object",
        "required": [
          "city",
          "postalCode"
        ],
        "properties": {
          "city": {
            "type": "string"
          },
          "postalCode": {
            "type": "string"
          }
        }
      }
    },
    "securitySchemes": {
      "ParcelKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Parcel-Key",
        "description": "Long-lived account key."
      },
      "ServiceBearer": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "Short-lived service token."
      }
    }
  }
}
