{
  "info": {
    "_postman_id": "a7c3e2f1-4b8d-4e9a-9c1f-trackerpro-extapi",
    "name": "TrackerPro External API",
    "description": "Read-only CRM API (OAuth2 client credentials).\n\n1. Set collection variables: baseUrl, client_id, client_secret.\n2. Run OAuth > Get Access Token (saves access_token and refresh_token).\n3. Call /v1 endpoints.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "auth": {
    "type": "bearer",
    "bearer": [
      {
        "key": "token",
        "value": "{{access_token}}",
        "type": "string"
      }
    ]
  },
  "variable": [
    { "key": "baseUrl", "value": "https://externalapi.trackerpro.co.uk" },
    { "key": "client_id", "value": "" },
    { "key": "client_secret", "value": "" },
    { "key": "access_token", "value": "" },
    { "key": "refresh_token", "value": "" },
    { "key": "account", "value": "" },
    { "key": "installationId", "value": "1" },
    { "key": "jobId", "value": "1" },
    { "key": "quoteId", "value": "1" },
    { "key": "callId", "value": "1" },
    { "key": "page", "value": "1" },
    { "key": "pageSize", "value": "25" },
    { "key": "q", "value": "acme" },
    { "key": "status", "value": "Open" }
  ],
  "item": [
    {
      "name": "OAuth",
      "item": [
        {
          "name": "Get Access Token (client_credentials)",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (pm.response.code === 200) {",
                  "  var json = pm.response.json();",
                  "  if (json.access_token) pm.collectionVariables.set('access_token', json.access_token);",
                  "  if (json.refresh_token) pm.collectionVariables.set('refresh_token', json.refresh_token);",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "auth": { "type": "noauth" },
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/x-www-form-urlencoded" }
            ],
            "body": {
              "mode": "urlencoded",
              "urlencoded": [
                { "key": "grant_type", "value": "client_credentials" },
                { "key": "client_id", "value": "{{client_id}}" },
                { "key": "client_secret", "value": "{{client_secret}}" }
              ]
            },
            "url": "{{baseUrl}}/oauth/token",
            "description": "Exchange client_id + client_secret for access_token and refresh_token. Saves tokens into collection variables."
          }
        },
        {
          "name": "Refresh Access Token",
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "if (pm.response.code === 200) {",
                  "  var json = pm.response.json();",
                  "  if (json.access_token) pm.collectionVariables.set('access_token', json.access_token);",
                  "  if (json.refresh_token) pm.collectionVariables.set('refresh_token', json.refresh_token);",
                  "}"
                ]
              }
            }
          ],
          "request": {
            "auth": { "type": "noauth" },
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/x-www-form-urlencoded" }
            ],
            "body": {
              "mode": "urlencoded",
              "urlencoded": [
                { "key": "grant_type", "value": "refresh_token" },
                { "key": "client_id", "value": "{{client_id}}" },
                { "key": "client_secret", "value": "{{client_secret}}" },
                { "key": "refresh_token", "value": "{{refresh_token}}" }
              ]
            },
            "url": "{{baseUrl}}/oauth/token",
            "description": "Rotate refresh_token and get a new access_token."
          }
        }
      ]
    },
    {
      "name": "Me",
      "item": [
        {
          "name": "GET /v1/me",
          "request": {
            "method": "GET",
            "header": [],
            "url": "{{baseUrl}}/v1/me",
            "description": "Current OAuth client identity (no database secrets)."
          }
        }
      ]
    },
    {
      "name": "Customers",
      "item": [
        {
          "name": "List customers",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/v1/customers?q={{q}}&page={{page}}&pageSize={{pageSize}}",
              "host": ["{{baseUrl}}"],
              "path": ["v1", "customers"],
              "query": [
                { "key": "q", "value": "{{q}}", "description": "Free-text contains: account reference, customer name, address 5" },
                { "key": "page", "value": "{{page}}" },
                { "key": "pageSize", "value": "{{pageSize}}" }
              ]
            },
            "description": "q searches account reference, customer name, and address 5 (postcode area). Example: q=acme"
          }
        },
        {
          "name": "Get customer",
          "request": {
            "method": "GET",
            "header": [],
            "url": "{{baseUrl}}/v1/customers/{{account}}"
          }
        }
      ]
    },
    {
      "name": "Installations",
      "item": [
        {
          "name": "List installations",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/v1/installations?account={{account}}&q={{q}}&page={{page}}&pageSize={{pageSize}}",
              "host": ["{{baseUrl}}"],
              "path": ["v1", "installations"],
              "query": [
                { "key": "account", "value": "{{account}}", "description": "Exact account reference (optional)" },
                { "key": "q", "value": "{{q}}", "description": "Free-text contains: property name, address 5, account ref" },
                { "key": "page", "value": "{{page}}" },
                { "key": "pageSize", "value": "{{pageSize}}" }
              ]
            },
            "description": "q searches property name, address 5, and account ref. account filters to one customer. Example: q=High Street"
          }
        },
        {
          "name": "Get installation",
          "request": {
            "method": "GET",
            "header": [],
            "url": "{{baseUrl}}/v1/installations/{{installationId}}"
          }
        }
      ]
    },
    {
      "name": "Jobs",
      "item": [
        {
          "name": "List jobs",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/v1/jobs?account={{account}}&installationId={{installationId}}&status={{status}}&page={{page}}&pageSize={{pageSize}}",
              "host": ["{{baseUrl}}"],
              "path": ["v1", "jobs"],
              "query": [
                { "key": "account", "value": "{{account}}" },
                { "key": "installationId", "value": "{{installationId}}" },
                { "key": "status", "value": "{{status}}" },
                { "key": "page", "value": "{{page}}" },
                { "key": "pageSize", "value": "{{pageSize}}" }
              ]
            }
          }
        },
        {
          "name": "Get job",
          "request": {
            "method": "GET",
            "header": [],
            "url": "{{baseUrl}}/v1/jobs/{{jobId}}"
          }
        }
      ]
    },
    {
      "name": "Quotes",
      "item": [
        {
          "name": "List quotes",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/v1/quotes?account={{account}}&installationId={{installationId}}&status={{status}}&page={{page}}&pageSize={{pageSize}}",
              "host": ["{{baseUrl}}"],
              "path": ["v1", "quotes"],
              "query": [
                { "key": "account", "value": "{{account}}" },
                { "key": "installationId", "value": "{{installationId}}" },
                { "key": "status", "value": "{{status}}" },
                { "key": "page", "value": "{{page}}" },
                { "key": "pageSize", "value": "{{pageSize}}" }
              ]
            }
          }
        },
        {
          "name": "Get quote",
          "request": {
            "method": "GET",
            "header": [],
            "url": "{{baseUrl}}/v1/quotes/{{quoteId}}"
          }
        }
      ]
    },
    {
      "name": "Calls",
      "item": [
        {
          "name": "List calls",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/v1/calls?account={{account}}&installationId={{installationId}}&status={{status}}&page={{page}}&pageSize={{pageSize}}",
              "host": ["{{baseUrl}}"],
              "path": ["v1", "calls"],
              "query": [
                { "key": "account", "value": "{{account}}" },
                { "key": "installationId", "value": "{{installationId}}" },
                { "key": "status", "value": "{{status}}" },
                { "key": "page", "value": "{{page}}" },
                { "key": "pageSize", "value": "{{pageSize}}" }
              ]
            }
          }
        },
        {
          "name": "Get call",
          "request": {
            "method": "GET",
            "header": [],
            "url": "{{baseUrl}}/v1/calls/{{callId}}"
          }
        }
      ]
    }
  ]
}
