{
  "openapi": "3.1.0",
  "info": {
    "title": "PostalCodeCheck Postal Code API",
    "version": "1.0",
    "description": "Free postal / ZIP / postcode lookup: city, region and coordinates for 887,000+ codes across 95 countries (GeoNames, CC BY 4.0). No key required.\n",
    "contact": {
      "name": "IPNOVA SYSTEMS LTD",
      "url": "https://postalcodecheck.com/postal-code-api",
      "email": "hello@ipnova.com"
    },
    "license": {
      "name": "Free to use, attribution appreciated",
      "url": "https://postalcodecheck.com/postal-code-api"
    }
  },
  "servers": [
    {
      "url": "https://postalcodecheck.com"
    }
  ],
  "security": [
    {},
    {
      "ApiKeyHeader": []
    },
    {
      "ApiKeyQuery": []
    }
  ],
  "paths": {
    "/api/postal/{cc}/{code}": {
      "get": {
        "summary": "Look up a postal code",
        "operationId": "lookupPostal",
        "parameters": [
          {
            "name": "cc",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z]{2}$",
              "example": "US"
            }
          },
          {
            "name": "code",
            "in": "path",
            "required": true,
            "description": "Postal code; case, spaces and hyphens are ignored",
            "schema": {
              "type": "string",
              "example": "90210"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Code found",
            "headers": {
              "X-Credits-Remaining": {
                "$ref": "#/components/headers/XCreditsRemaining"
              },
              "X-Credits-Used": {
                "$ref": "#/components/headers/XCreditsUsed"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    },
                    "country": {
                      "type": "string",
                      "example": "US"
                    },
                    "country_name": {
                      "type": "string",
                      "example": "United States"
                    },
                    "code": {
                      "type": "string",
                      "example": "90210"
                    },
                    "places": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "place": {
                            "type": "string",
                            "example": "Beverly Hills"
                          },
                          "admin1": {
                            "type": "string",
                            "example": "California"
                          },
                          "admin2": {
                            "type": "string",
                            "example": "Los Angeles"
                          },
                          "lat": {
                            "type": "string",
                            "example": "34.0901"
                          },
                          "lng": {
                            "type": "string",
                            "example": "-118.4065"
                          }
                        }
                      }
                    },
                    "url": {
                      "type": "string",
                      "format": "uri"
                    },
                    "source": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "invalid_input: country code is not two letters",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "invalid_key: the API key is malformed, unknown, revoked or expired",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found: country not covered or code not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limit (30/minute per IP), daily_limit (100/day per IP) or credits_exhausted (keyed monthly allowance used up)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/countries": {
      "get": {
        "summary": "List supported countries",
        "operationId": "listCountries",
        "responses": {
          "200": {
            "description": "Countries with code counts and format patterns",
            "headers": {
              "X-Credits-Remaining": {
                "$ref": "#/components/headers/XCreditsRemaining"
              },
              "X-Credits-Used": {
                "$ref": "#/components/headers/XCreditsUsed"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    },
                    "countries": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "country": {
                            "type": "string",
                            "example": "DE"
                          },
                          "name": {
                            "type": "string",
                            "example": "Germany"
                          },
                          "codes": {
                            "type": "integer",
                            "example": 16481
                          },
                          "format": {
                            "type": "string",
                            "example": "NNNNN",
                            "description": "N = digit, A = letter"
                          }
                        }
                      }
                    },
                    "source": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "invalid_key: the API key is malformed, unknown, revoked or expired",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limit (30/minute per IP), daily_limit (100/day per IP) or credits_exhausted (keyed monthly allowance used up)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Error": {
        "type": "object",
        "description": "Shared error envelope for every non-200 response across all IPNOVA APIs.",
        "required": [
          "success",
          "error",
          "reason",
          "message",
          "docs"
        ],
        "properties": {
          "success": {
            "type": "boolean",
            "enum": [
              false
            ]
          },
          "error": {
            "type": "boolean",
            "enum": [
              true
            ]
          },
          "reason": {
            "type": "string",
            "enum": [
              "invalid_input",
              "invalid_key",
              "not_found",
              "rate_limit",
              "daily_limit",
              "credits_exhausted"
            ]
          },
          "message": {
            "type": "string",
            "example": "Code not found for US."
          },
          "docs": {
            "type": "string",
            "format": "uri",
            "example": "https://postalcodecheck.com/postal-code-api"
          }
        }
      }
    },
    "securitySchemes": {
      "ApiKeyHeader": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Api-Key",
        "description": "Optional. A free api.ipnova.com key applies your plan allowance instead of the per-IP limits."
      },
      "ApiKeyQuery": {
        "type": "apiKey",
        "in": "query",
        "name": "key",
        "description": "Optional. Same key, passed as a query parameter instead of the header."
      }
    },
    "headers": {
      "XCreditsRemaining": {
        "description": "Credits left in the current plan cycle for keyed requests; \"unavailable\" if the key service could not be reached.",
        "schema": {
          "type": "string",
          "example": "4999"
        }
      },
      "XCreditsUsed": {
        "description": "Credits charged for this call. Only 200 responses consume credits.",
        "schema": {
          "type": "string",
          "example": "1"
        }
      }
    }
  }
}
