{
  "openapi": "3.0.3",
  "info": {
    "title": "MotorsDynamic Partner Data Issues API",
    "version": "1.1.0",
    "description": "Report incomplete or wrong MotorsDynamic vehicle data. MD stores the report, re-checks the vehicle (database and dealer page), queues a re-crawl when that can fix it, and reports the outcome: poll GET /api/v1/partner/data-issues/{id}, or receive a signed webhook at callback_url when the issue reaches fixed, wont_fix or needs_info.\n\nLifecycle: received -> triaged -> in_progress -> fixed | wont_fix | needs_info. A changed re-report (same partner_issue_id, different body) reopens an issue to received.\n\nWebhook: POST to callback_url with headers X-MD-Event (data_issue.<status>), X-MD-Delivery (unique id), X-MD-Timestamp (unix seconds) and X-MD-Signature: sha256=<hex HMAC-SHA256 of \"<X-MD-Timestamp>.<raw body>\" with your webhook secret>. Reject a delivery whose timestamp is more than 5 minutes old. Answer 2xx; anything else is retried at 1, 5, 30, 120 and 360 minutes.\n\nDealer-level reports (1.1, 2026-10-30): with \"scope\": \"dealer\" one request reports a whole dealer site instead of one car. kind undercount: you got fewer cars than the dealer site shows (expected_count vs received_count); MD compares its live active count, re-crawls the site when it is short, and closes the issue fixed (MD has them: refresh your copy) or triaged for an MD engineer. kind rejected_vehicles: cars arrived but you could not save them (reason, count, optional vins); MD counts the active cars at the dealer that lack the field, re-crawls, and closes fixed or triaged for a parser fix. One dealer report is one request against the 600 per hour limit. GET /api/v1/partner/dealers/{domain}/quality shows MD's current counts for a dealer."
  },
  "servers": [{ "url": "https://api.motorsdynamic.com" }],
  "security": [{ "ApiKey": [] }],
  "paths": {
    "/api/v1/partner/data-issues": {
      "post": {
        "summary": "Report a data issue (create, or update on a changed re-report)",
        "description": "Idempotent on (partner, partner_issue_id): the same body again returns 200 with outcome unchanged; a changed body updates the issue (outcome updated). The partner is taken from your API key. Limited to 600 reports per hour per partner (429 with Retry-After beyond that).",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/DataIssueInput" },
          "examples": {
            "vehicle": { "summary": "One car with missing fields", "value": { "partner_issue_id": "ov-2026-10-27-000123", "kind": "incomplete_fields", "severity": "high", "vehicle": { "md_id": 9230047, "vin": "KL4AMBSL5SB000000", "dealer_id": 2 }, "fields": [{ "name": "price", "expected": 27990, "got": null }] } },
            "dealer_undercount": { "summary": "Slack button: fewer cars than expected, MD should re-parse the site", "value": { "partner_issue_id": "slack-C07MDQ-1761830412.000100", "scope": "dealer", "kind": "undercount", "severity": "high", "dealer": { "domain": "cochrankia.com" }, "expected_count": 420, "received_count": 300, "observed_at": "2026-10-30T14:00:00Z", "callback_url": "https://YOUR-HOST/md/data-issues/webhook" } },
            "dealer_rejected_vehicles": { "summary": "Slack button: cars arrived but could not be saved (no make)", "value": { "partner_issue_id": "slack-C07MDQ-1761830555.000200", "scope": "dealer", "kind": "rejected_vehicles", "dealer": { "domain": "cochrankia.com", "dealer_id": 2 }, "reason": "missing_make", "count": 37, "vins": ["KNDPU3AF0R7123456", "KNDPU3AF0R7123457", "5XYP3DHC9NG000001"], "note": "make empty, model present" } }
          } } } },
        "responses": {
          "201": { "description": "Created", "headers": { "Location": { "schema": { "type": "string" } } }, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PostResult" } } } },
          "200": { "description": "Already known (outcome unchanged) or updated (outcome updated)", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PostResult" } } } },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/ValidationError" },
          "429": { "$ref": "#/components/responses/Error" }
        }
      },
      "get": {
        "summary": "List your data issues, newest update first",
        "parameters": [
          { "name": "status", "in": "query", "description": "Comma-separated statuses", "schema": { "type": "string", "example": "fixed,wont_fix,needs_info" } },
          { "name": "since", "in": "query", "description": "Only issues updated at or after this time", "schema": { "type": "string", "format": "date-time" } },
          { "name": "partner_issue_id", "in": "query", "schema": { "type": "string" } },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 200, "default": 50 } },
          { "name": "cursor", "in": "query", "description": "next_cursor from the previous page", "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "A page of issues", "content": { "application/json": { "schema": { "type": "object", "properties": { "data": { "type": "array", "items": { "$ref": "#/components/schemas/DataIssue" } }, "next_cursor": { "type": "string", "nullable": true } } } } } },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/ValidationError" }
        }
      }
    },
    "/api/v1/partner/dealers/{domain}/quality": {
      "get": {
        "summary": "A dealer as MD has it now: active cars, missing-field counts, your open issues",
        "description": "Read-only. {domain} is the dealer's host (scheme and www are ignored, e.g. cochrankia.com) or the MD dealer id. Missing counts are among active vehicles; price and year at 0 count as missing; photos means neither a photo count nor an image list. Also at /api/partner/dealers/{domain}/quality.",
        "parameters": [{ "name": "domain", "in": "path", "required": true, "schema": { "type": "string", "example": "cochrankia.com" } }],
        "responses": {
          "200": { "description": "The dealer", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/DealerQuality" } } } },
          "401": { "$ref": "#/components/responses/Error" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "description": "MotorsDynamic does not track this dealer", "content": { "application/json": { "schema": { "type": "object", "properties": { "error": { "type": "string", "example": "MotorsDynamic does not track unknown-dealer.com" } } } } } },
          "422": { "$ref": "#/components/responses/ValidationError" }
        }
      }
    },
    "/api/v1/partner/data-issues/{id}": {
      "get": {
        "summary": "One data issue: status, resolution, triage and history",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "integer" } }],
        "responses": {
          "200": { "description": "The issue", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/DataIssue" } } } },
          "401": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": { "ApiKey": { "type": "apiKey", "in": "header", "name": "X-API-Key", "description": "Your MD API key. It needs data-issues access (scope partner:data-issues:<partner>); ask MD to enable it." } },
    "responses": {
      "Error": { "description": "Error", "content": { "application/json": { "schema": { "type": "object", "properties": { "error": { "type": "string" } } } } } },
      "ValidationError": { "description": "Every problem with the request at once", "content": { "application/json": { "schema": { "type": "object", "properties": { "error": { "type": "string" }, "details": { "type": "array", "items": { "type": "string" } } } } } } }
    },
    "schemas": {
      "Kind": { "type": "string", "enum": ["incomplete_fields", "stale_listing", "wrong_identity", "duplicate", "gone_but_active", "parse_error", "undercount", "rejected_vehicles"], "description": "undercount and rejected_vehicles need scope dealer; the others are scope vehicle" },
      "Scope": { "type": "string", "enum": ["vehicle", "dealer"], "default": "vehicle", "description": "vehicle: one car (body has vehicle). dealer: a whole dealer site (body has dealer; kind undercount or rejected_vehicles)" },
      "Reason": { "type": "string", "enum": ["missing_make", "missing_model", "missing_year", "missing_price", "missing_vin", "missing_photos", "missing_mileage", "bad_value", "other"], "description": "rejected_vehicles: why you could not save the cars. For bad_value and other, name the fields in fields." },
      "Dealer": {
        "type": "object", "description": "At least one of domain or dealer_id",
        "properties": {
          "domain": { "type": "string", "example": "cochrankia.com", "description": "The dealer site; stored as a bare lowercase host (scheme, www, port and path dropped)" },
          "dealer_id": { "type": "integer", "description": "MD dealer (domain) id, as in /api/domains/id/{id}" }
        }
      },
      "DealerQuality": {
        "type": "object",
        "properties": {
          "domain": { "type": "string", "example": "cochrankia.com" },
          "dealer_id": { "type": "integer" },
          "platform": { "type": "string", "nullable": true, "description": "The site platform MD detected (cms_type)" },
          "tracked": { "type": "boolean", "description": "false when MD has stopped crawling the dealer" },
          "last_scraped_at": { "type": "string", "format": "date-time", "nullable": true },
          "last_error": { "type": "string", "nullable": true, "description": "The last crawl error, if any" },
          "active_vehicles": { "type": "integer" },
          "missing": { "type": "object", "description": "Active vehicles lacking each field", "properties": { "make": { "type": "integer" }, "model": { "type": "integer" }, "year": { "type": "integer" }, "price": { "type": "integer" }, "vin": { "type": "integer" }, "mileage": { "type": "integer" }, "photos": { "type": "integer" } } },
          "open_issues": { "type": "integer", "description": "Your issues for this dealer (either scope) in received, triaged or in_progress" }
        }
      },
      "Status": { "type": "string", "enum": ["received", "triaged", "in_progress", "fixed", "wont_fix", "needs_info"] },
      "Field": {
        "type": "object", "required": ["name"],
        "properties": {
          "name": { "type": "string", "maxLength": 100, "description": "MD field name: price, sale_price, msrp, mileage, year, make, model, trim, vin, stock_number, exterior_color, interior_color, engine, transmission, drivetrain, fuel_type, body_type, condition, url, photo_count (or images), is_active. Common aliases (odometer, stock, color, photos) are accepted." },
          "expected": { "description": "What the value should be, if you know it (any JSON, at most 2000 bytes)" },
          "got": { "description": "What MD gave you (any JSON, at most 2000 bytes)" }
        }
      },
      "DataIssueInput": {
        "type": "object", "required": ["partner_issue_id", "kind"],
        "description": "scope vehicle (default) needs vehicle; scope dealer needs dealer, plus expected_count and received_count (undercount) or reason and count (rejected_vehicles).",
        "properties": {
          "partner_issue_id": { "type": "string", "maxLength": 200, "description": "Your id for this issue; repeat it to update the same issue" },
          "partner": { "type": "string", "description": "Optional; must match your API key's partner" },
          "scope": { "$ref": "#/components/schemas/Scope" },
          "kind": { "$ref": "#/components/schemas/Kind" },
          "severity": { "type": "string", "enum": ["low", "medium", "high", "critical"], "default": "medium" },
          "dealer": { "$ref": "#/components/schemas/Dealer" },
          "expected_count": { "type": "integer", "minimum": 1, "description": "undercount: how many cars you expected (e.g. from the dealer site)" },
          "received_count": { "type": "integer", "minimum": 0, "description": "undercount: how many cars MD gave you" },
          "reason": { "$ref": "#/components/schemas/Reason" },
          "count": { "type": "integer", "minimum": 1, "description": "rejected_vehicles: how many cars you could not save" },
          "vins": { "type": "array", "maxItems": 500, "items": { "type": "string" }, "description": "rejected_vehicles: VINs of the rejected cars (optional, up to 500; stored deduplicated and uppercase)" },
          "note": { "type": "string", "maxLength": 2000, "description": "rejected_vehicles: anything else MD should know" },
          "vehicle": {
            "type": "object", "description": "scope vehicle: at least one of md_id, vin or source_url",
            "properties": {
              "md_id": { "type": "integer", "description": "The vehicle id in MD's vehicles API (best)" },
              "vin": { "type": "string" },
              "dealer_id": { "type": "integer", "description": "MD dealer (domain) id, as in /api/domains/id/{id}" },
              "source_url": { "type": "string", "format": "uri", "description": "The dealer page the vehicle came from" }
            }
          },
          "fields": { "type": "array", "maxItems": 50, "items": { "$ref": "#/components/schemas/Field" } },
          "observed_at": { "type": "string", "format": "date-time" },
          "evidence": { "description": "Anything that helps (any JSON, at most 32 KB)" },
          "callback_url": { "type": "string", "format": "uri", "description": "https URL for the signed status webhook" }
        }
      },
      "DataIssue": {
        "type": "object",
        "properties": {
          "id": { "type": "integer" },
          "partner": { "type": "string" },
          "partner_issue_id": { "type": "string" },
          "scope": { "$ref": "#/components/schemas/Scope" },
          "kind": { "$ref": "#/components/schemas/Kind" },
          "severity": { "type": "string" },
          "status": { "$ref": "#/components/schemas/Status" },
          "resolution": { "type": "string", "nullable": true, "description": "What MD found or did, in one or two sentences" },
          "vehicle": { "type": "object", "nullable": true, "description": "null for scope dealer", "properties": { "md_id": { "type": "integer", "nullable": true }, "vin": { "type": "string", "nullable": true }, "dealer_id": { "type": "integer", "nullable": true }, "source_url": { "type": "string", "nullable": true }, "matched_md_id": { "type": "integer", "nullable": true }, "matched_dealer_id": { "type": "integer", "nullable": true } } },
          "fields": { "type": "array", "items": { "$ref": "#/components/schemas/Field" } },
          "observed_at": { "type": "string", "format": "date-time", "nullable": true },
          "dealer": { "type": "object", "description": "scope dealer only", "properties": { "domain": { "type": "string", "nullable": true }, "dealer_id": { "type": "integer", "nullable": true }, "matched_dealer_id": { "type": "integer", "nullable": true } } },
          "expected_count": { "type": "integer", "nullable": true, "description": "scope dealer only" },
          "received_count": { "type": "integer", "nullable": true, "description": "scope dealer only" },
          "reason": { "type": "string", "nullable": true, "description": "scope dealer only" },
          "count": { "type": "integer", "nullable": true, "description": "scope dealer only: rejected_vehicles count" },
          "vins_count": { "type": "integer", "description": "scope dealer only: how many distinct VINs you sent (the list is not returned)" },
          "note": { "type": "string", "nullable": true, "description": "scope dealer only" },
          "fingerprint": { "type": "string", "description": "sha256 of kind + vehicle + field names (scope dealer: kind + dealer host + reason + field names); equal for reports of the same problem" },
          "report_count": { "type": "integer" },
          "triage": {
            "type": "object", "nullable": true,
            "properties": {
              "action": { "type": "string", "description": "resolved | recrawl_queued | recheck_scheduled | needs_person | needs_info" },
              "summary": { "type": "string" },
              "fields": { "type": "array", "items": { "type": "object", "properties": { "name": { "type": "string" }, "verdict": { "type": "string", "enum": ["ok_now", "present_now", "missing", "still_wrong", "differs", "unknown_field"] }, "md_value": {} } } },
              "page": { "type": "object", "nullable": true },
              "dealer": { "type": "object", "nullable": true, "description": "scope dealer: the MD dealer triage matched (id, domain, platform, is_active, vehicle_count, last_scraped_at, last_error)" },
              "md_active_count_before": { "type": "integer", "nullable": true, "description": "scope dealer: MD's active cars at the first look" },
              "md_active_count_after": { "type": "integer", "nullable": true, "description": "scope dealer: MD's active cars after the re-crawl" },
              "missing_count_before": { "type": "integer", "nullable": true, "description": "rejected_vehicles: active cars lacking the field at the first look" },
              "missing_count_after": { "type": "integer", "nullable": true, "description": "rejected_vehicles: the same after the re-crawl" },
              "columns": { "type": "array", "nullable": true, "items": { "type": "string" }, "description": "rejected_vehicles: the MD fields checked" },
              "example_vins": { "type": "array", "nullable": true, "items": { "type": "string" }, "description": "rejected_vehicles: up to 10 active cars still lacking the field" },
              "vins_found": { "type": "integer", "nullable": true, "description": "rejected_vehicles: of your vins, how many are active at the dealer in MD" },
              "vins_missing": { "type": "integer", "nullable": true, "description": "rejected_vehicles: of those, how many still lack the field" }
            }
          },
          "webhook": { "type": "object", "nullable": true, "properties": { "status": { "type": "string", "nullable": true, "enum": ["pending", "delivered", "failed", null] } } },
          "created_at": { "type": "string", "format": "date-time" },
          "updated_at": { "type": "string", "format": "date-time" },
          "resolved_at": { "type": "string", "format": "date-time", "nullable": true },
          "links": { "type": "object", "properties": { "self": { "type": "string" } } },
          "history": { "type": "array", "description": "GET by id only", "items": { "type": "object", "properties": { "at": { "type": "string", "format": "date-time" }, "event": { "type": "string" }, "from": { "type": "string", "nullable": true }, "to": { "type": "string", "nullable": true }, "note": { "type": "string", "nullable": true } } } }
        }
      },
      "PostResult": { "type": "object", "properties": { "outcome": { "type": "string", "enum": ["created", "updated", "unchanged"] }, "issue": { "$ref": "#/components/schemas/DataIssue" } } }
    }
  }
}
