{
  "info": {
    "_postman_id": "af-public-api-v1",
    "name": "Appraiser Flow Public API v1",
    "description": "Fee + turnaround only. Use af_test_ keys on staging. Never put keys in browser JS.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    { "key": "baseUrl", "value": "https://staging-api.appraiserflow.ai" },
    { "key": "apiKey", "value": "af_test_REPLACE_ME" },
    { "key": "quoteId", "value": "" },
    { "key": "externalReference", "value": "WEB-DEMO-1" }
  ],
  "auth": {
    "type": "bearer",
    "bearer": [{ "key": "token", "value": "{{apiKey}}", "type": "string" }]
  },
  "item": [
    {
      "name": "Health",
      "request": {
        "auth": { "type": "noauth" },
        "method": "GET",
        "header": [],
        "url": "{{baseUrl}}/public/v1/health"
      }
    },
    {
      "name": "Me",
      "request": {
        "method": "GET",
        "header": [],
        "url": "{{baseUrl}}/public/v1/me"
      }
    },
    {
      "name": "List Products",
      "request": {
        "method": "GET",
        "header": [],
        "url": "{{baseUrl}}/public/v1/products"
      }
    },
    {
      "name": "Coverage Check",
      "request": {
        "method": "POST",
        "header": [{ "key": "Content-Type", "value": "application/json" }],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"state\": \"TN\",\n  \"county\": \"Davidson\",\n  \"product_code\": \"1004\"\n}"
        },
        "url": "{{baseUrl}}/public/v1/coverage/check"
      }
    },
    {
      "name": "Fee Preview",
      "request": {
        "method": "POST",
        "header": [{ "key": "Content-Type", "value": "application/json" }],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"product_code\": \"1004\",\n  \"subject\": {\n    \"line1\": \"123 Main St\",\n    \"city\": \"Nashville\",\n    \"state\": \"TN\",\n    \"postal_code\": \"37203\",\n    \"county\": \"Davidson\"\n  }\n}"
        },
        "url": "{{baseUrl}}/public/v1/fees/preview"
      }
    },
    {
      "name": "Create Quote",
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "exec": [
              "pm.request.headers.upsert({ key: 'Idempotency-Key', value: pm.variables.replaceIn('{{$guid}}') });"
            ]
          }
        },
        {
          "listen": "test",
          "script": {
            "exec": [
              "if (pm.response.code === 201) {",
              "  const j = pm.response.json();",
              "  if (j.id) pm.collectionVariables.set('quoteId', j.id);",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          { "key": "Content-Type", "value": "application/json" },
          { "key": "Idempotency-Key", "value": "{{$guid}}" }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"schema_version\": 1,\n  \"external_reference\": \"{{externalReference}}\",\n  \"product_code\": \"1004\",\n  \"subject\": {\n    \"line1\": \"123 Main St\",\n    \"city\": \"Nashville\",\n    \"state\": \"TN\",\n    \"postal_code\": \"37203\",\n    \"county\": \"Davidson\"\n  },\n  \"client\": {\n    \"name\": \"Acme Mortgage\",\n    \"email\": \"orders@acme.example\",\n    \"phone\": \"(615) 555-0100\"\n  },\n  \"source\": \"api\"\n}"
        },
        "url": "{{baseUrl}}/public/v1/quotes"
      }
    },
    {
      "name": "Get Quote by Id",
      "request": {
        "method": "GET",
        "header": [],
        "url": "{{baseUrl}}/public/v1/quotes/{{quoteId}}"
      }
    },
    {
      "name": "Get Quote by External Reference",
      "request": {
        "method": "GET",
        "header": [],
        "url": {
          "raw": "{{baseUrl}}/public/v1/quotes?external_reference={{externalReference}}",
          "host": ["{{baseUrl}}"],
          "path": ["public", "v1", "quotes"],
          "query": [
            { "key": "external_reference", "value": "{{externalReference}}" }
          ]
        }
      }
    }
  ]
}
