{
  "openapi": "3.0.3",
  "info": {
    "title": "CCRAB Platforms API",
    "version": "1.0.0",
    "description": "Platform metadata, display configuration, ingestion mappings, and observations. Other CCRAB APIs are outside this reference."
  },
  "tags": [
    {
      "name": "Platforms"
    }
  ],
  "paths": {
    "/api/platforms/": {
      "get": {
        "operationId": "listPlatforms",
        "summary": "List platforms",
        "description": "Returns an unpaginated GeoJSON FeatureCollection. Sensors follow the platform's serving policy.",
        "tags": [
          "Platforms"
        ],
        "parameters": [
          {
            "name": "name",
            "in": "query",
            "required": false,
            "description": "Case-insensitive partial short_name match. Takes precedence over bbox.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "bbox",
            "in": "query",
            "required": false,
            "description": "Bounding box: min_lon,min_lat,max_lon,max_lat. Malformed values are ignored.",
            "schema": {
              "type": "string"
            },
            "example": "-80.1,32.7,-79.8,33.0"
          }
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "deprecated": false,
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PlatformCollection"
                }
              }
            }
          },
          "401": {
            "description": "Missing, expired, or invalid bearer token."
          }
        }
      }
    },
    "/api/platforms/{short_name}/": {
      "get": {
        "operationId": "getPlatform",
        "summary": "Get a platform",
        "description": "Returns the first case-insensitive partial short_name match, optionally constrained by bbox.",
        "tags": [
          "Platforms"
        ],
        "parameters": [
          {
            "name": "short_name",
            "in": "path",
            "required": true,
            "description": "Platform short name (partial match).",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "bbox",
            "in": "query",
            "required": false,
            "description": "Bounding box: min_lon,min_lat,max_lon,max_lat. Malformed values are ignored.",
            "schema": {
              "type": "string"
            },
            "example": "-80.1,32.7,-79.8,33.0"
          }
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "deprecated": false,
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Platform"
                }
              }
            }
          },
          "404": {
            "description": "No matching platform.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, expired, or invalid bearer token."
          }
        }
      }
    },
    "/api/v1/platforms/": {
      "get": {
        "operationId": "legacyPlatformList",
        "summary": "Legacy public platform list",
        "description": "Public alias for the platform collection; prefer the authenticated collection for API integrations.",
        "tags": [
          "Platforms"
        ],
        "parameters": [
          {
            "name": "name",
            "in": "query",
            "required": false,
            "description": "Case-insensitive partial short_name match. Takes precedence over bbox.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "bbox",
            "in": "query",
            "required": false,
            "description": "Bounding box: min_lon,min_lat,max_lon,max_lat. Malformed values are ignored.",
            "schema": {
              "type": "string"
            },
            "example": "-80.1,32.7,-79.8,33.0"
          }
        ],
        "security": [],
        "deprecated": true,
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PlatformCollection"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/platform_info/": {
      "get": {
        "operationId": "legacyPlatformInfo",
        "summary": "Legacy authenticated platform list",
        "description": "Alias for the authenticated platform collection.",
        "tags": [
          "Platforms"
        ],
        "parameters": [
          {
            "name": "name",
            "in": "query",
            "required": false,
            "description": "Case-insensitive partial short_name match. Takes precedence over bbox.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "bbox",
            "in": "query",
            "required": false,
            "description": "Bounding box: min_lon,min_lat,max_lon,max_lat. Malformed values are ignored.",
            "schema": {
              "type": "string"
            },
            "example": "-80.1,32.7,-79.8,33.0"
          }
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "deprecated": true,
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PlatformCollection"
                }
              }
            }
          },
          "401": {
            "description": "Missing, expired, or invalid bearer token."
          }
        }
      }
    },
    "/api/v1/platform_configuration/": {
      "get": {
        "operationId": "getPlatformConfiguration",
        "summary": "Get platform display configuration",
        "description": "Includes all sensors and their display flags, including sensors excluded from served observations. Uses the first partial short_name match.",
        "tags": [
          "Platforms"
        ],
        "parameters": [
          {
            "name": "short_name",
            "in": "query",
            "required": true,
            "description": "Platform short name (partial match).",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "bbox",
            "in": "query",
            "required": false,
            "description": "Bounding box: min_lon,min_lat,max_lon,max_lat. Malformed values are ignored.",
            "schema": {
              "type": "string"
            },
            "example": "-80.1,32.7,-79.8,33.0"
          }
        ],
        "security": [],
        "deprecated": false,
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PlatformConfiguration"
                }
              }
            }
          },
          "400": {
            "description": "Missing short_name.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No matching platform.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/system/platform_configuration/": {
      "get": {
        "operationId": "getSourceConfiguration",
        "summary": "Get ingestion source configuration",
        "description": "Requires a JWT for a user in the private_api_access group. Returns active platforms for the selected active data source, grouped by organization, with observation mappings.",
        "tags": [
          "Platforms"
        ],
        "parameters": [
          {
            "name": "data_source",
            "in": "query",
            "required": false,
            "description": "Data source key. Defaults to purple_air.",
            "schema": {
              "type": "string"
            },
            "example": "purple_air"
          }
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "deprecated": false,
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SourceConfiguration"
                }
              }
            }
          },
          "403": {
            "description": "User lacks private_api_access group membership.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, expired, or invalid bearer token."
          }
        }
      }
    },
    "/api/v1/platform_data_request/": {
      "get": {
        "operationId": "getPlatformObservations",
        "summary": "Request observations",
        "description": "Returns a GeoJSON Feature with JSON timeseries in properties.timeseries. Date bounds are inclusive; start_date must not exceed end_date. Only served observation/order pairs are accepted. No readings returns timeseries: [].",
        "tags": [
          "Platforms"
        ],
        "parameters": [
          {
            "name": "platform_handle",
            "in": "query",
            "required": true,
            "description": "Exact platform_handle from platform properties.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "start_date",
            "in": "query",
            "required": true,
            "description": "ISO 8601 datetime; use an explicit timezone.",
            "schema": {
              "type": "string"
            },
            "example": "2026-01-01T00:00:00Z"
          },
          {
            "name": "end_date",
            "in": "query",
            "required": true,
            "description": "ISO 8601 datetime; use an explicit timezone.",
            "schema": {
              "type": "string"
            },
            "example": "2026-01-02T00:00:00Z"
          },
          {
            "name": "observations",
            "in": "query",
            "required": true,
            "description": "Comma-separated '<obs_standard_name> <s_order>' pairs from the platform's sensors. Duplicate pairs are removed.",
            "schema": {
              "type": "string"
            },
            "example": "pm2_5 1,air_temperature 1"
          }
        ],
        "security": [],
        "deprecated": false,
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ObservationFeature"
                }
              }
            }
          },
          "400": {
            "description": "Missing or invalid parameters, unknown platform, reversed dates, or unavailable observation/order pair.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "description": "A detail message or field names mapped to validation error lists.",
        "additionalProperties": true
      },
      "Sensor": {
        "type": "object",
        "properties": {
          "short_name": {
            "type": "string",
            "nullable": true
          },
          "obs_standard_name": {
            "type": "string",
            "nullable": true
          },
          "obs_definition": {
            "type": "string",
            "nullable": true
          },
          "info_url": {
            "type": "string",
            "nullable": true
          },
          "uom_display": {
            "type": "string",
            "nullable": true
          },
          "uom_standard_name": {
            "type": "string",
            "nullable": true
          },
          "uom_definition": {
            "type": "string",
            "nullable": true
          },
          "s_order": {
            "type": "integer",
            "nullable": true
          },
          "active": {
            "type": "integer",
            "nullable": true
          }
        }
      },
      "Geometry": {
        "type": "object",
        "nullable": true,
        "properties": {
          "type": {
            "type": "string",
            "example": "Point"
          },
          "coordinates": {
            "type": "array",
            "items": {
              "type": "number"
            }
          }
        }
      },
      "Platform": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "Feature"
            ]
          },
          "geometry": {
            "$ref": "#/components/schemas/Geometry"
          },
          "properties": {
            "type": "object",
            "properties": {
              "sensors": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/Sensor"
                }
              },
              "begin_date": {
                "type": "string",
                "nullable": true
              },
              "end_date": {
                "type": "string",
                "nullable": true
              },
              "short_name": {
                "type": "string",
                "nullable": true
              },
              "long_name": {
                "type": "string",
                "nullable": true
              },
              "platform_handle": {
                "type": "string",
                "nullable": true
              },
              "description": {
                "type": "string",
                "nullable": true
              },
              "neighborhood": {
                "type": "string",
                "nullable": true
              },
              "manufacturer": {
                "type": "string",
                "nullable": true
              },
              "serial_number": {
                "type": "string",
                "nullable": true
              },
              "firmware_version": {
                "type": "string",
                "nullable": true
              },
              "country_name": {
                "type": "string",
                "nullable": true
              },
              "city": {
                "type": "string",
                "nullable": true
              },
              "url": {
                "type": "string",
                "nullable": true
              },
              "fixed_latitude": {
                "type": "number",
                "nullable": true
              },
              "fixed_longitude": {
                "type": "number",
                "nullable": true
              },
              "active": {
                "type": "integer",
                "nullable": true
              },
              "type_id": {
                "type": "object",
                "nullable": true
              },
              "images": {
                "type": "array",
                "items": {
                  "type": "object"
                }
              }
            }
          }
        }
      },
      "PlatformCollection": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "FeatureCollection"
            ]
          },
          "features": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Platform"
            }
          }
        }
      },
      "PlatformConfiguration": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Platform"
          },
          {
            "type": "object",
            "properties": {
              "properties": {
                "type": "object",
                "properties": {
                  "sensors": {
                    "type": "array",
                    "items": {
                      "allOf": [
                        {
                          "$ref": "#/components/schemas/Sensor"
                        },
                        {
                          "type": "object",
                          "properties": {
                            "display": {
                              "type": "boolean"
                            }
                          }
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        ]
      },
      "SourceConfiguration": {
        "type": "object",
        "properties": {
          "organizations": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "org_id": {
                  "type": "integer"
                },
                "short_name": {
                  "type": "string"
                },
                "long_name": {
                  "type": "string"
                },
                "platforms": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/SourcePlatform"
                  }
                }
              }
            }
          }
        }
      },
      "ObservationFeature": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "Feature"
            ]
          },
          "geometry": {
            "$ref": "#/components/schemas/Geometry"
          },
          "properties": {
            "type": "object",
            "properties": {
              "platform_handle": {
                "type": "string"
              },
              "start_date": {
                "type": "string"
              },
              "end_date": {
                "type": "string"
              },
              "timeseries": {
                "oneOf": [
                  {
                    "type": "object",
                    "description": "JSON timeseries document with header and data."
                  },
                  {
                    "type": "array",
                    "maxItems": 0
                  }
                ]
              }
            }
          }
        }
      },
      "ObservationMapping": {
        "type": "object",
        "properties": {
          "source_obs": {
            "type": "string",
            "nullable": true
          },
          "source_uom": {
            "type": "string",
            "nullable": true
          },
          "source_identifier": {
            "type": "string",
            "nullable": true
          },
          "target_obs": {
            "type": "string",
            "nullable": true
          },
          "target_uom": {
            "type": "string",
            "nullable": true
          },
          "source_active": {
            "type": "integer",
            "nullable": true
          },
          "target_active": {
            "type": "integer",
            "nullable": true
          },
          "sensor_id": {
            "type": "integer",
            "nullable": true
          },
          "m_type_id": {
            "type": "integer",
            "nullable": true
          },
          "s_order": {
            "type": "integer",
            "nullable": true
          }
        }
      },
      "SourcePlatform": {
        "type": "object",
        "properties": {
          "observations": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ObservationMapping"
            }
          },
          "active": {
            "type": "integer",
            "nullable": true
          },
          "platform_handle": {
            "type": "string",
            "nullable": true
          },
          "short_name": {
            "type": "string",
            "nullable": true
          },
          "external_identifier": {
            "type": "string",
            "nullable": true
          },
          "country_code": {
            "type": "string",
            "nullable": true
          },
          "neighborhood": {
            "type": "string",
            "nullable": true
          },
          "latitude": {
            "type": "number",
            "nullable": true
          },
          "longitude": {
            "type": "number",
            "nullable": true
          }
        }
      }
    }
  }
}