{"openapi":"3.1.0","info":{"title":"SpectaGIS External API v1","version":"0.0.11","summary":"Prevented Planting (PP) Claims Submission, TALV Results & Webhook Gateway","description":"Production REST API for Approved Insurance Providers (AIPs) submitting agricultural Prevented Planting (PP) insurance claims to the SpectaGIS TALV analysis platform.\n\n### Authentication & Environments\n- Authenticate every `/v1/*` call with `Authorization: Bearer <API_KEY>`.\n- **Production keys** (`sg_live_...`) operate on live AIP data and bill account credits.\n- **Sandbox keys** (`sg_test_...`) operate on isolated `sandbox_*` collections without deducting credits. Local dev pre-seeds `sg_test_demo`.\n\n### Deterministic Sandbox Policy Fixtures (`sg_test_...`)\n- `POL-TEST-PASS`: Simulates fast completion (~1.5s) with `PASS_P21_ELIGIBLE` (100% eligible acres).\n- `POL-TEST-PARTIAL`: Simulates partial eligibility (~45% eligible acres, `PASS_P21_PARTIAL`).\n- `POL-TEST-FAIL`: Simulates deterministic async job failure (`status: \"failed\"`) and `claim.analysis.failed` webhook.\n\n### GeoJSON & Validation Rules\n- `POST /v1/claims/pp` **always** requires top-level `\"type\": \"FeatureCollection\"`, even for a single field (`1..200` features).\n- Polygons are validated in WGS 84 (`[-180..180, -90..90]`) for zero self-intersections and geodesic area `> 0` and `<= 2,000` acres.\n- `adjuster_photos` accepts public or pre-signed `https://` URLs only (Base64 `data` payloads are rejected with `422`).\n- All error responses conform to **RFC 9457** (`application/problem+json`).","contact":{"name":"SpectaGIS API Engineering","email":"ori@spectagis.com"}},"servers":[{"url":"/v1","description":"Current Host (Local / Preview)"},{"url":"https://sandbox.api.spectagis.com/v1","description":"Sandbox Environment (sg_test_...)"},{"url":"https://api.spectagis.com/v1","description":"Production Environment (sg_live_...)"}],"security":[{"BearerAuth":[]}],"tags":[{"name":"Claims","description":"Submit Prevented Planting claims and retrieve TALV determinations & PDF dossiers"},{"name":"Second Crop","description":"Enqueue Second Crop / haying & grazing verification"},{"name":"Webhooks","description":"Manage HMAC-signed webhook subscriptions"}],"paths":{"/claims/pp":{"post":{"tags":["Claims"],"summary":"Submit Prevented Planting claim (GeoJSON FeatureCollection)","description":"Submits an insured Prevented Planting (PP) claim as a GeoJSON FeatureCollection for satellite TALV verification. Synchronously validates polygon topology, geodesic acreage, RMA FCIC-25370 enums, and photo URLs, persists the claim in Firestore, and enqueues an asynchronous analysis job returning 202 Accepted.","parameters":[{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","maxLength":128},"description":"Idempotency token (up to 128 chars, 24h TTL) to safely retry failed network requests. Identical payloads replay the cached 202 response; different payloads return 409 Conflict."}],"requestBody":{"required":true,"content":{"application/geo+json":{"schema":{"$ref":"#/components/schemas/PreventedPlantingFeatureCollection"},"example":{"type":"FeatureCollection","properties":{"policyholder_name":"Heartland Grain Farms LLC","policy_number":"POL-TEST-PASS","primary_cause_of_loss":"Excess Moisture","loss_event_date":"2026-05-18","client_reference_id":"aip-batch-2026-0042","claim_year":2026},"features":[{"type":"Feature","id":"field-ia-story-01","geometry":{"type":"Polygon","coordinates":[[[-93.62,42.02],[-93.615,42.02],[-93.615,42.0235],[-93.62,42.0235],[-93.62,42.02]]]},"properties":{"crop_type":"Corn","intended_planting_date":"2026-05-10","state":"Iowa","county":"Story","farm_number":"1042","tract_number":"218","field_number":"4A","prevented_acres":40,"adjuster_photos":[{"url":"https://cdn.example-aip.org/claims/2026/photo-standing-water.jpg","filename":"photo-standing-water.jpg","caption":"North headland standing water after May rainfall event","timestamp":"2026-05-19T14:30:00Z"}]}}]}},"application/json":{"schema":{"$ref":"#/components/schemas/PreventedPlantingFeatureCollection"},"example":{"type":"FeatureCollection","properties":{"policyholder_name":"Heartland Grain Farms LLC","policy_number":"POL-TEST-PASS","primary_cause_of_loss":"Excess Moisture","loss_event_date":"2026-05-18","client_reference_id":"aip-batch-2026-0042","claim_year":2026},"features":[{"type":"Feature","id":"field-ia-story-01","geometry":{"type":"Polygon","coordinates":[[[-93.62,42.02],[-93.615,42.02],[-93.615,42.0235],[-93.62,42.0235],[-93.62,42.02]]]},"properties":{"crop_type":"Corn","intended_planting_date":"2026-05-10","state":"Iowa","county":"Story","farm_number":"1042","tract_number":"218","field_number":"4A","prevented_acres":40,"adjuster_photos":[{"url":"https://cdn.example-aip.org/claims/2026/photo-standing-water.jpg","filename":"photo-standing-water.jpg","caption":"North headland standing water after May rainfall event","timestamp":"2026-05-19T14:30:00Z"}]}}]}}}},"responses":{"202":{"description":"Claim accepted and queued for TALV satellite & weather analysis.","headers":{"X-SpectaGIS-Credit-Balance":{"schema":{"type":"string"},"description":"Remaining account credit pool balance."},"X-SpectaGIS-Credit-Warning":{"schema":{"type":"string"},"description":"Credit threshold status or sandbox indicator."}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ClaimAcceptedResponse"}}}},"401":{"$ref":"#/components/responses/ProblemUnauthorized"},"403":{"$ref":"#/components/responses/ProblemForbidden"},"409":{"$ref":"#/components/responses/ProblemConflict"},"422":{"$ref":"#/components/responses/ProblemValidation"},"429":{"$ref":"#/components/responses/ProblemRateLimited"}}}},"/claims":{"get":{"tags":["Claims"],"summary":"List Prevented Planting claims","description":"Retrieves a cursor-paginated list of Prevented Planting claims belonging to the authenticated AIP account. Supports filtering by policy number, lifecycle status, client reference ID, and update timestamp.","parameters":[{"name":"policy_number","in":"query","required":false,"schema":{"type":"string"},"description":"Filters results to claims matching an exact AIP policy number."},{"name":"status","in":"query","required":false,"schema":{"$ref":"#/components/schemas/ClaimStatus"},"description":"Filters claims by analysis status: queued, processing, completed, or failed."},{"name":"client_reference_id","in":"query","required":false,"schema":{"type":"string"},"description":"Filters results by the caller-supplied client_reference_id provided on submission."},{"name":"updated_since","in":"query","required":false,"schema":{"type":"string","format":"date-time"},"description":"ISO-8601 UTC timestamp returning only claims updated at or after this time."},{"name":"cursor","in":"query","required":false,"schema":{"type":"string"},"description":"Opaque pagination cursor returned in next_cursor from the previous page."},{"name":"limit","in":"query","required":false,"schema":{"type":"integer","minimum":1,"maximum":100,"default":25},"description":"Maximum number of claims to return per page (1 to 100, defaults to 25)."}],"responses":{"200":{"description":"Paginated claim list","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ClaimListResponse"}}}},"401":{"$ref":"#/components/responses/ProblemUnauthorized"},"403":{"$ref":"#/components/responses/ProblemForbidden"}}}},"/claims/{claim_id}":{"get":{"tags":["Claims"],"summary":"Get claim status and TALV determination (JSON Result Endpoint 1)","description":"Fetches full processing status, 9-stage progress (1/9–9/9), field-level TALV compliance determinations, eligible/ineligible acreage breakdown, and the PASS P-21 eligibility flag for a single claim.","parameters":[{"name":"claim_id","in":"path","required":true,"schema":{"type":"string"},"description":"Unique SpectaGIS claim identifier (e.g., clm_...) returned by POST /claims/pp."}],"responses":{"200":{"description":"Claim status, stage progress (1/9-9/9), TALV determination, PASS P-21 flag, and field eligibility.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ClaimDetailResponse"}}}},"401":{"$ref":"#/components/responses/ProblemUnauthorized"},"403":{"$ref":"#/components/responses/ProblemForbidden"},"404":{"$ref":"#/components/responses/ProblemNotFound"}}}},"/claims/{claim_id}/dossier.pdf":{"get":{"tags":["Claims"],"summary":"Download claim TALV dossier PDF (Result Endpoint 2)","description":"Streams the compiled FCIC-25370 TALV audit dossier PDF from Cloud Storage (or redirects to a short-lived signed URL) once the claim reaches completed status. Returns 409 Conflict if analysis is still in progress.","parameters":[{"name":"claim_id","in":"path","required":true,"schema":{"type":"string"},"description":"Unique SpectaGIS claim identifier whose completed audit dossier PDF should be downloaded."}],"responses":{"200":{"description":"PDF dossier stream","content":{"application/pdf":{"schema":{"type":"string","format":"binary"}}}},"302":{"description":"Short-lived signed GCS download redirect"},"401":{"$ref":"#/components/responses/ProblemUnauthorized"},"404":{"$ref":"#/components/responses/ProblemNotFound"},"409":{"$ref":"#/components/responses/ProblemConflict"}}}},"/claims/{claim_id}/second-crop":{"post":{"tags":["Second Crop"],"summary":"Enqueue Second Crop verification","description":"Queues an asynchronous Second Crop and haying/grazing verification check against an existing Prevented Planting claim to detect post-loss planting or harvest activity.","parameters":[{"name":"claim_id","in":"path","required":true,"schema":{"type":"string"},"description":"Unique SpectaGIS claim identifier to evaluate for second-crop or haying/grazing activity."},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","maxLength":128},"description":"Idempotency token (24h TTL) preventing duplicate second-crop verification jobs on retries."}],"requestBody":{"required":false,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SecondCropRequest"}}}},"responses":{"202":{"description":"Second crop verification enqueued.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ClaimAcceptedResponse"}}}},"401":{"$ref":"#/components/responses/ProblemUnauthorized"},"404":{"$ref":"#/components/responses/ProblemNotFound"},"409":{"$ref":"#/components/responses/ProblemConflict"},"422":{"$ref":"#/components/responses/ProblemValidation"},"429":{"$ref":"#/components/responses/ProblemRateLimited"}}}},"/webhooks":{"post":{"tags":["Webhooks"],"summary":"Register an HTTPS webhook subscription","description":"Creates an HTTPS webhook subscription for asynchronous claim lifecycle events. Returns a one-time HMAC-SHA256 signing secret (whsec_...) used to verify X-SpectaGIS-Signature headers on incoming deliveries.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateWebhookRequest"},"example":{"url":"https://webhooks.example-aip.org/spectagis","events":["claim.analysis.completed","claim.analysis.failed"]}}}},"responses":{"201":{"description":"Webhook created with one-time HMAC signing secret.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateWebhookResponse"}}}},"401":{"$ref":"#/components/responses/ProblemUnauthorized"},"403":{"$ref":"#/components/responses/ProblemForbidden"},"422":{"$ref":"#/components/responses/ProblemValidation"}}},"get":{"tags":["Webhooks"],"summary":"List active webhook subscriptions","description":"Lists all webhook subscriptions configured for the authenticated AIP account and environment, including destination URLs, subscribed events, and active status.","responses":{"200":{"description":"Registered webhooks for this account","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WebhookListResponse"}}}},"401":{"$ref":"#/components/responses/ProblemUnauthorized"},"403":{"$ref":"#/components/responses/ProblemForbidden"}}}},"/webhooks/{webhook_id}":{"delete":{"tags":["Webhooks"],"summary":"Delete a webhook subscription","description":"Permanently deletes an existing webhook subscription owned by the authenticated AIP account so no further event notifications are sent to that URL.","parameters":[{"name":"webhook_id","in":"path","required":true,"schema":{"type":"string"},"description":"Unique webhook identifier (e.g., wh_...) returned by POST /webhooks or GET /webhooks."}],"responses":{"200":{"description":"Webhook deleted.","content":{"application/json":{"schema":{"type":"object","properties":{"deleted":{"type":"boolean"},"webhook_id":{"type":"string"}}}}}},"401":{"$ref":"#/components/responses/ProblemUnauthorized"},"404":{"$ref":"#/components/responses/ProblemNotFound"}}}}},"components":{"securitySchemes":{"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"SpectaGIS API Key (sg_live_... or sg_test_...)"}},"schemas":{"PrimaryCauseOfLoss":{"type":"string","enum":["Excess Moisture","Flood","Drought","Failure of Irrigation Water Supply","Failure/Breakdown of Irrigation Equipment or Facilities","Inability to Prepare Land for Irrigation","Cold/Wet Weather","Other Insured Weather Event"],"description":"Strict RMA FCIC-25370 Prevented Planting cause of loss."},"CropType":{"type":"string","enum":["Corn","Soybeans","Spring Wheat","Cotton","Grain Sorghum","Canola"],"description":"Strict supported Prevented Planting crop type."},"USState":{"type":"string","enum":["AL","AK","AZ","AR","CA","CO","CT","DE","FL","GA","HI","ID","IL","IN","IA","KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VT","VA","WA","WV","WI","WY","Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","Florida","Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Carolina","North Dakota","Ohio","Oklahoma","Oregon","Pennsylvania","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia","Washington","West Virginia","Wisconsin","Wyoming"],"description":"US State full name or 2-letter postal code (all 50 US states)."},"ClaimStatus":{"type":"string","enum":["queued","processing","completed","failed"]},"WebhookEvent":{"type":"string","enum":["claim.analysis.started","claim.analysis.completed","claim.analysis.failed","claim.second_crop.completed"]},"AdjusterPhoto":{"type":"object","required":["url","filename"],"additionalProperties":false,"properties":{"url":{"type":"string","format":"uri","pattern":"^https://","description":"Public or pre-signed HTTPS URL (no Base64 or private hosts)."},"filename":{"type":"string","minLength":1,"description":"Original image filename for dossier audit referencing."},"caption":{"type":"string","description":"Adjuster field observation note attached to the photo."},"timestamp":{"type":"string","format":"date-time","description":"ISO-8601 capture timestamp with timezone (e.g. 2026-05-19T14:30:00Z)."}}},"GeoJsonPolygon":{"type":"object","required":["type","coordinates"],"properties":{"type":{"type":"string","enum":["Polygon","MultiPolygon"],"description":"GeoJSON polygon geometry type (Polygon or MultiPolygon)."},"coordinates":{"description":"Closed WGS 84 [longitude, latitude] coordinate rings with zero self-intersections.","type":"array"}}},"ClaimFieldFeature":{"type":"object","required":["type","geometry","properties"],"properties":{"type":{"type":"string","enum":["Feature"],"description":"GeoJSON object type for each field parcel; must equal \"Feature\"."},"id":{"type":["string","number"],"description":"Optional caller identifier for this field feature."},"geometry":{"$ref":"#/components/schemas/GeoJsonPolygon","description":"Closed WGS 84 Polygon or MultiPolygon boundary (<= 2,000 geodesic acres)."},"properties":{"type":"object","required":["crop_type","intended_planting_date","state","county","farm_number","tract_number","field_number","prevented_acres"],"properties":{"crop_type":{"$ref":"#/components/schemas/CropType","description":"Insured crop prevented from planting (e.g., Corn, Soybeans, Wheat)."},"intended_planting_date":{"type":"string","format":"date","description":"Planned planting date (YYYY-MM-DD) used to align satellite weather windows."},"state":{"$ref":"#/components/schemas/USState","description":"U.S. state name or 2-letter postal code where the parcel is located."},"county":{"type":"string","minLength":1,"description":"County or parish name where the field parcel is located."},"farm_number":{"type":"string","minLength":1,"description":"FSA Farm Serial Number (FSN) component of the FTF identifier."},"tract_number":{"type":"string","minLength":1,"description":"FSA Tract number component of the FTF identifier."},"field_number":{"type":"string","minLength":1,"description":"FSA Field / CLU number component of the FTF identifier."},"prevented_acres":{"type":"number","exclusiveMinimum":0,"maximum":2000,"description":"Claimed prevented planting acreage for this parcel (> 0 and <= 2,000 acres)."},"adjuster_photos":{"type":"array","maxItems":20,"items":{"$ref":"#/components/schemas/AdjusterPhoto"},"description":"Up to 20 adjuster photos referencing public or pre-signed https:// URLs."}}}}},"PreventedPlantingFeatureCollection":{"type":"object","required":["type","properties","features"],"properties":{"type":{"type":"string","enum":["FeatureCollection"],"description":"Always required at the top level, even when submitting a single field."},"properties":{"type":"object","required":["policyholder_name","policy_number","primary_cause_of_loss","loss_event_date"],"properties":{"policyholder_name":{"type":"string","minLength":1,"description":"Full legal name of the insured producer or farm entity."},"policy_number":{"type":"string","minLength":1,"description":"AIP policy number (POL-TEST-PASS, POL-TEST-PARTIAL, or POL-TEST-FAIL in sandbox)."},"primary_cause_of_loss":{"$ref":"#/components/schemas/PrimaryCauseOfLoss","description":"RMA FCIC-25370 approved Prevented Planting cause of loss."},"loss_event_date":{"type":"string","format":"date","description":"ISO date (YYYY-MM-DD) when the qualifying peril or weather event occurred."},"client_reference_id":{"type":"string","maxLength":128,"description":"Optional AIP internal batch or claim reference ID echoed back in responses."},"claim_year":{"type":"integer","minimum":2000,"maximum":2100,"description":"4-digit crop insurance year (defaults to the year of loss_event_date)."}}},"features":{"type":"array","minItems":1,"maxItems":200,"items":{"$ref":"#/components/schemas/ClaimFieldFeature"},"description":"Array of 1 to 200 GeoJSON Feature objects representing prevented field parcels."}}},"ClaimAcceptedResponse":{"type":"object","properties":{"claim_id":{"type":"string"},"job_id":{"type":"string"},"policy_number":{"type":"string"},"status":{"type":"string","enum":["queued"]},"field_count":{"type":"integer"},"credits_estimated":{"type":"number"},"status_url":{"type":"string"},"dossier_pdf_url":{"type":"string"}}},"ClaimListResponse":{"type":"object","properties":{"claims":{"type":"array","items":{"type":"object"}},"next_cursor":{"type":["string","null"]},"count":{"type":"integer"}}},"ClaimDetailResponse":{"type":"object","properties":{"claim_id":{"type":"string"},"job_id":{"type":"string"},"status":{"$ref":"#/components/schemas/ClaimStatus"},"stage_progress":{"type":"string"},"pass_p21_flag":{"type":["string","null"]},"talv_determination":{"type":["object","null"]},"fields":{"type":"array","items":{"type":"object"}},"warnings":{"type":"array","items":{"type":"string"}},"dossier_pdf_url":{"type":"string"}}},"SecondCropRequest":{"type":"object","properties":{"field_ids":{"type":"array","minItems":1,"maxItems":200,"items":{"type":"string"},"description":"Specific field_id values to check for second-crop activity; omit or send {} to check all fields."}}},"CreateWebhookRequest":{"type":"object","required":["url","events"],"properties":{"url":{"type":"string","format":"uri","pattern":"^https://","description":"Public https:// destination URL where SpectaGIS delivers signed webhook events."},"events":{"type":"array","minItems":1,"items":{"$ref":"#/components/schemas/WebhookEvent"},"description":"One or more claim lifecycle events to trigger webhook notifications."}}},"CreateWebhookResponse":{"type":"object","properties":{"webhook_id":{"type":"string"},"url":{"type":"string"},"events":{"type":"array","items":{"$ref":"#/components/schemas/WebhookEvent"}},"secret":{"type":"string"},"active":{"type":"boolean"},"created_at":{"type":"string","format":"date-time"}}},"WebhookListResponse":{"type":"object","properties":{"webhooks":{"type":"array","items":{"type":"object"}},"count":{"type":"integer"}}},"ProblemDetails":{"type":"object","required":["type","title","status","detail","instance","request_id"],"properties":{"type":{"type":"string","format":"uri"},"title":{"type":"string"},"status":{"type":"integer"},"detail":{"type":"string"},"instance":{"type":"string"},"request_id":{"type":"string"},"errors":{"type":"array","items":{"type":"object","properties":{"field":{"type":"string"},"code":{"type":"string"},"message":{"type":"string"},"allowed_values":{"type":"array","items":{"type":"string"}}}}}}}},"responses":{"ProblemUnauthorized":{"description":"Unauthorized (RFC 9457 Problem JSON)","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/ProblemDetails"}}}},"ProblemForbidden":{"description":"Forbidden (RFC 9457 Problem JSON)","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/ProblemDetails"}}}},"ProblemNotFound":{"description":"Not Found (RFC 9457 Problem JSON)","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/ProblemDetails"}}}},"ProblemConflict":{"description":"Conflict (RFC 9457 Problem JSON)","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/ProblemDetails"}}}},"ProblemValidation":{"description":"Validation failed (RFC 9457 Problem JSON with allowed_values)","content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/ProblemDetails"}}}},"ProblemRateLimited":{"description":"Too Many Requests — tenant active queue backlog limit reached","headers":{"Retry-After":{"schema":{"type":"string"}}},"content":{"application/problem+json":{"schema":{"$ref":"#/components/schemas/ProblemDetails"}}}}}}}