{
  "openapi": "3.0.1",
  "info": {
    "title": "CA Food Facility Inspections - San Francisco Restaurant History",
    "description": "SF restaurant / food-facility inspection history (public data, 2016-present, ~126k records): pass / conditional / closure, violation codes + text, scores, risk. Compliance & closure diligence for franchise / restaurant buyers.",
    "version": "0.0",
    "x-build-id": "mzbVykYagpSqlWmNB"
  },
  "servers": [
    {
      "url": "https://api.apify.com/v2"
    }
  ],
  "paths": {
    "/acts/j0401~ca-food-safety/run-sync-get-dataset-items": {
      "post": {
        "operationId": "run-sync-get-dataset-items-j0401-ca-food-safety",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/acts/j0401~ca-food-safety/runs": {
      "post": {
        "operationId": "runs-sync-j0401-ca-food-safety",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor and returns information about the initiated run in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/runsResponseSchema"
                }
              }
            }
          }
        }
      }
    },
    "/acts/j0401~ca-food-safety/run-sync": {
      "post": {
        "operationId": "run-sync-j0401-ca-food-safety",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "inputSchema": {
        "type": "object",
        "properties": {
          "generation": {
            "title": "Generation",
            "enum": [
              "current",
              "y2020_2023",
              "y2016_2019",
              "all"
            ],
            "type": "string",
            "description": "current = 2024-present (~22k, per-inspection, rating + violation codes, permit number). y2020_2023 = 2020-2023 (~50k per-violation rows). y2016_2019 = 2016-2019 (~54k per-violation rows, score + risk). all = full SF history matched on business name.",
            "default": "current"
          },
          "business": {
            "title": "Business name",
            "type": "string",
            "description": "Business name filter (substring). Use together with generation=all to trace a name across eras; the current era adds permit_number for an exact match."
          },
          "permit": {
            "title": "Permit number (current era)",
            "type": "string",
            "description": "Exact SF permit number - the stable per-business key in the 2024-present generation (e.g. 06762361). Not available in the older two eras."
          },
          "dateFrom": {
            "title": "From date (YYYY-MM-DD)",
            "type": "string",
            "description": "Only inspections on/after this date."
          },
          "dateTo": {
            "title": "To date (YYYY-MM-DD)",
            "type": "string",
            "description": "Only inspections on/before this date."
          },
          "rating": {
            "title": "Result",
            "enum": [
              "",
              "pass",
              "conditional",
              "closure"
            ],
            "type": "string",
            "description": "Filter to a result. current era reads facility_rating_status; 2020-2023 reads facility_status. closure = facility closed after this inspection."
          },
          "keyword": {
            "title": "Violation keyword",
            "type": "string",
            "description": "Substring match against the violation text (codes + code text in current era, the single description in 2020-2023, the violation description in 2016-2019)."
          },
          "risk": {
            "title": "Risk category (2016-2019)",
            "enum": [
              "",
              "low",
              "moderate",
              "high"
            ],
            "type": "string",
            "description": "2016-2019 era only: filter to a risk category (High / Moderate / Low)."
          },
          "severity": {
            "title": "Violation severity (2020-2023)",
            "type": "string",
            "description": "2020-2023 era only: violation_observed text filter (e.g. 'Minor', 'Major', 'OUT (Not in Compliance)')."
          },
          "minScore": {
            "title": "Minimum score (2016-2019)",
            "type": "integer",
            "description": "2016-2019 era only: only inspections with a score >= this value."
          },
          "aggregate": {
            "title": "Aggregate instead of records",
            "type": "boolean",
            "description": "When on, returns one summary row per group with a count. Requires a single generation (not 'all').",
            "default": false
          },
          "groupBy": {
            "title": "Aggregate by",
            "enum": [
              "rating",
              "neighborhood",
              "inspectionType",
              "severity",
              "risk"
            ],
            "type": "string",
            "description": "rating = result (current/2020-2023). neighborhood = SF analysis neighborhood (current). inspectionType = current / 2020-2023 / 2016-2019. severity = 2020-2023. risk = 2016-2019. Choosing a dimension the generation lacks errors.",
            "default": "rating"
          },
          "maxResults": {
            "title": "Max records",
            "minimum": 0,
            "type": "integer",
            "description": "Cap records pushed (0 = a reasonable ceiling). Default = the ~50 most recent SF inspections.",
            "default": 50
          }
        }
      },
      "runsResponseSchema": {
        "type": "object",
        "properties": {
          "data": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "actId": {
                "type": "string"
              },
              "userId": {
                "type": "string"
              },
              "startedAt": {
                "type": "string",
                "format": "date-time",
                "example": "2025-01-08T00:00:00.000Z"
              },
              "finishedAt": {
                "type": "string",
                "format": "date-time",
                "example": "2025-01-08T00:00:00.000Z"
              },
              "status": {
                "type": "string",
                "example": "READY"
              },
              "meta": {
                "type": "object",
                "properties": {
                  "origin": {
                    "type": "string",
                    "example": "API"
                  },
                  "userAgent": {
                    "type": "string"
                  }
                }
              },
              "stats": {
                "type": "object",
                "properties": {
                  "inputBodyLen": {
                    "type": "integer",
                    "example": 2000
                  },
                  "rebootCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "restartCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "resurrectCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "computeUnits": {
                    "type": "integer",
                    "example": 0
                  }
                }
              },
              "options": {
                "type": "object",
                "properties": {
                  "build": {
                    "type": "string",
                    "example": "latest"
                  },
                  "timeoutSecs": {
                    "type": "integer",
                    "example": 300
                  },
                  "memoryMbytes": {
                    "type": "integer",
                    "example": 1024
                  },
                  "diskMbytes": {
                    "type": "integer",
                    "example": 2048
                  }
                }
              },
              "buildId": {
                "type": "string"
              },
              "defaultKeyValueStoreId": {
                "type": "string"
              },
              "defaultDatasetId": {
                "type": "string"
              },
              "defaultRequestQueueId": {
                "type": "string"
              },
              "buildNumber": {
                "type": "string",
                "example": "1.0.0"
              },
              "containerUrl": {
                "type": "string"
              },
              "usage": {
                "type": "object",
                "properties": {
                  "ACTOR_COMPUTE_UNITS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_WRITES": {
                    "type": "integer",
                    "example": 1
                  },
                  "KEY_VALUE_STORE_LISTS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_INTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_EXTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_SERPS": {
                    "type": "integer",
                    "example": 0
                  }
                }
              },
              "usageTotalUsd": {
                "type": "number",
                "example": 0.00005
              },
              "usageUsd": {
                "type": "object",
                "properties": {
                  "ACTOR_COMPUTE_UNITS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_WRITES": {
                    "type": "number",
                    "example": 0.00005
                  },
                  "KEY_VALUE_STORE_LISTS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_INTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_EXTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_SERPS": {
                    "type": "integer",
                    "example": 0
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}