{
  "openapi": "3.1.0",
  "info": {
    "title": "PlanningMapsUK Maps API",
    "version": "1.0.0",
    "description": "Approved business access. \u00a350/month including VAT plus prepaid map generation. Live product availability is returned by the catalogue. Test keys accept only the fixed Cambridge fixture: latitude 52.20425, longitude 0.11535, hectares 5.0625, map_type mastermap, layers []. Output format may vary; other test parameters return 422 sandbox_parameters."
  },
  "servers": [
    {
      "url": "https://planningmapsuk.co.uk/api/v1"
    }
  ],
  "security": [
    {
      "ApiKey": []
    }
  ],
  "paths": {
    "/catalog": {
      "get": {
        "summary": "Products, limits and public price bands",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "default": {
            "description": "Request rejected",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/quotes": {
      "post": {
        "summary": "Create a 15-minute fixed-price quote",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/QuoteRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "id",
                    "price_pence",
                    "expires_at"
                  ],
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "price_pence": {
                      "type": "integer"
                    },
                    "currency": {
                      "const": "GBP"
                    },
                    "expires_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "location": {
                      "type": "object"
                    },
                    "coverage": {
                      "type": "object"
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Request rejected",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/maps": {
      "post": {
        "summary": "Reserve funds and queue a map",
        "parameters": [
          {
            "in": "header",
            "name": "Idempotency-Key",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "quote_id"
                ],
                "properties": {
                  "quote_id": {
                    "type": "string",
                    "format": "uuid"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Map"
                }
              }
            }
          },
          "default": {
            "description": "Request rejected",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "get": {
        "summary": "Generation history",
        "parameters": [
          {
            "in": "query",
            "name": "offset",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 10000,
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "maps": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "next_offset": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Request rejected",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/maps/{id}": {
      "get": {
        "summary": "Status and fresh 15-minute download link",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Map"
                }
              }
            }
          },
          "default": {
            "description": "Request rejected",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/balance": {
      "get": {
        "summary": "Available and reserved balance",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "available_pence": {
                      "type": "integer"
                    },
                    "reserved_pence": {
                      "type": "integer"
                    },
                    "currency": {
                      "const": "GBP"
                    },
                    "environment": {
                      "enum": [
                        "live",
                        "test"
                      ]
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Request rejected",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/maps/{id}/download": {
      "get": {
        "summary": "Download a completed map",
        "description": "Streams the private file through PlanningMapsUK. Use the short-lived token URL returned by GET /maps/{id}; no bearer header is required for this signed link.",
        "security": [],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Map file attachment"
          },
          "403": {
            "description": "Invalid or expired download link"
          },
          "404": {
            "description": "File unavailable or retention expired"
          },
          "429": {
            "description": "Download rate limit exceeded"
          },
          "503": {
            "description": "Download temporarily unavailable"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "pmuk_live_\u2026 or pmuk_test_\u2026"
      }
    },
    "schemas": {
      "QuoteRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "location",
          "map_type",
          "hectares",
          "file_type"
        ],
        "properties": {
          "location": {
            "oneOf": [
              {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "uprn"
                ],
                "properties": {
                  "uprn": {
                    "type": "string",
                    "pattern": "^[0-9]{1,12}$"
                  }
                }
              },
              {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "address"
                ],
                "properties": {
                  "address": {
                    "type": "string",
                    "minLength": 8,
                    "maxLength": 250
                  }
                }
              },
              {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "latitude",
                  "longitude"
                ],
                "properties": {
                  "latitude": {
                    "type": "number",
                    "minimum": -90,
                    "maximum": 90
                  },
                  "longitude": {
                    "type": "number",
                    "minimum": -180,
                    "maximum": 180
                  }
                }
              }
            ]
          },
          "map_type": {
            "enum": [
              "mastermap",
              "opendata"
            ]
          },
          "hectares": {
            "type": "number",
            "minimum": 0.1,
            "maximum": 25
          },
          "file_type": {
            "enum": [
              "png",
              "pdf",
              "cad"
            ]
          },
          "file_format": {
            "enum": [
              "dxf",
              "dwg"
            ],
            "description": "Required only for CAD. OpenData CAD is unavailable."
          },
          "layers": {
            "type": "array",
            "maxItems": 0
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "file_type": {
                  "const": "cad"
                }
              }
            },
            "then": {
              "required": [
                "file_format"
              ],
              "properties": {
                "map_type": {
                  "const": "mastermap"
                }
              }
            },
            "else": {
              "not": {
                "required": [
                  "file_format"
                ]
              }
            }
          }
        ]
      },
      "Map": {
        "type": "object",
        "required": [
          "id",
          "status"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "enum": [
              "queued",
              "processing",
              "completed",
              "failed"
            ]
          },
          "charged_pence": {
            "type": "integer",
            "minimum": 0
          },
          "currency": {
            "const": "GBP"
          },
          "download_url": {
            "type": "string",
            "format": "uri"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "download_expired": {
            "type": "boolean"
          },
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "code",
          "message",
          "request_id"
        ],
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "request_id": {
            "type": "string",
            "format": "uuid"
          },
          "details": {
            "type": "object"
          }
        }
      }
    }
  }
}
