{
  "info": {
    "_postman_id": "31df4e98-b6c7-4d7a-bdc3-73538748667c",
    "name": "Fukamo API",
    "description": "Plný audit stránky cez Fukamo API — ten istý, aký dostane návštevník webu. Audit je asynchrónny: „Spustiť audit“ ho zaradí do fronty a uloží `auditId`, „Stav auditu“ posielaj, kým `status` nie je `complete` (zvyčajne 1–4 minúty), potom si stiahni „Report (PDF)“.\n\nKľúč vydáva prevádzkovateľ — vlož ho do premennej `apiKey` v prostredí, nikdy nie do kolekcie. Odpovede API sú po anglicky.\n\nDokumentácia: https://fukamo.com/sk/api",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "auth": {
    "type": "bearer",
    "bearer": [
      {
        "key": "token",
        "value": "{{apiKey}}",
        "type": "string"
      }
    ]
  },
  "variable": [
    {
      "key": "url",
      "value": "https://www.zrnko.sk"
    },
    {
      "key": "query",
      "value": "",
      "description": "Voliteľná hľadaná fráza (najviac 32 slov). Prázdna = prvý návrh kľúčového slova, aký ponúkne web."
    },
    {
      "key": "auditId",
      "value": "",
      "description": "Vyplní ho test požiadavky „Spustiť audit“."
    }
  ],
  "item": [
    {
      "name": "Audit stránky",
      "item": [
        {
          "name": "Spustiť audit",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"urls\": [\"{{url}}\"],\n  \"query\": \"{{query}}\"\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/api/v1/audits",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "audits"]
            },
            "description": "Spustí plný audit jednej stránky a hneď vráti `202` s `id` a `statusUrl`. Stojí 5 auditov z kvóty kľúča (predvolene 60 za hodinu, teda 12 plných auditov); naraz môžu na kľúč čakať najviac 10 stránok. Prázdne `query` znamená prvý návrh kľúčového slova z webu."
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('202 a id auditu', () => {",
                  "  pm.response.to.have.status(202);",
                  "  const body = pm.response.json();",
                  "  pm.expect(body.status).to.eql('queued');",
                  "  pm.expect(body.id).to.be.a('string');",
                  "  pm.collectionVariables.set('auditId', body.id);",
                  "});"
                ]
              }
            }
          ]
        },
        {
          "name": "Stav auditu",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/v1/audits/{{auditId}}",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "audits", "{{auditId}}"]
            },
            "description": "Stav auditu `queued` → `running` → `complete`. Posielaj napríklad každých 5 sekúnd; hotová stránka v `pages` nesie `result` so skóre, súhrnom a nálezmi od najvážnejších. Dotazy na stav sú mimo kvóty (120 za minútu). V Collection Runneri sa táto požiadavka opakuje, kým audit nie je hotový."
          },
          "event": [
            {
              "listen": "prerequest",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "// In the Collection Runner this request repeats until the audit is complete: wait between polls.",
                  "if (pm.collectionVariables.get('polled')) setTimeout(() => {}, 5000);"
                ]
              }
            },
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('200 a verzovaný tvar', () => {",
                  "  pm.response.to.have.status(200);",
                  "  pm.expect(pm.response.json().version).to.eql(1);",
                  "});",
                  "// Collection Runner: ask again until the audit is complete, so „Report (PDF)“ never meets 409.",
                  "const status = pm.response.code === 200 ? pm.response.json().status : 'complete';",
                  "if (status !== 'complete') {",
                  "  pm.collectionVariables.set('polled', '1');",
                  "  pm.execution.setNextRequest(pm.info.requestName);",
                  "} else pm.collectionVariables.unset('polled');"
                ]
              }
            }
          ]
        },
        {
          "name": "Report (PDF)",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{baseUrl}}/api/v1/audits/{{auditId}}?format=pdf",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "audits", "{{auditId}}"],
              "query": [
                {
                  "key": "format",
                  "value": "pdf"
                }
              ]
            },
            "description": "Hotový audit ako PDF report, aký si stiahne návštevník. Kým audit nie je `complete`, vráti `409 not_ready`. V Postmane zvoľ Send and Download. Limit 15 za hodinu."
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('200 a PDF', () => {",
                  "  pm.response.to.have.status(200);",
                  "  pm.expect(pm.response.headers.get('Content-Type')).to.include('application/pdf');",
                  "});"
                ]
              }
            }
          ]
        }
      ]
    },
    {
      "name": "Chyby — ako API odmieta",
      "item": [
        {
          "name": "Bez kľúča → 401",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"urls\": [\"{{url}}\"]\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/api/v1/audits",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "audits"]
            },
            "description": "Bez hlavičky Authorization vráti 401 `unauthorized` a nič nespustí.",
            "auth": {
              "type": "noauth"
            }
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('401 unauthorized', () => {",
                  "  pm.response.to.have.status(401);",
                  "  pm.expect(pm.response.json().code).to.eql('unauthorized');",
                  "});"
                ]
              }
            }
          ]
        },
        {
          "name": "Zlá fráza → 400",
          "request": {
            "method": "POST",
            "header": [
              {
                "key": "Content-Type",
                "value": "application/json"
              }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"urls\": [\"{{url}}\"],\n  \"query\": 42\n}",
              "options": {
                "raw": {
                  "language": "json"
                }
              }
            },
            "url": {
              "raw": "{{baseUrl}}/api/v1/audits",
              "host": ["{{baseUrl}}"],
              "path": ["api", "v1", "audits"]
            },
            "description": "`query` musí byť text s najviac 32 slovami; inak 400 `invalid_query`. Odmietne sa skôr, než sa niečo stiahne alebo minie z kvóty."
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "type": "text/javascript",
                "exec": [
                  "pm.test('400 invalid_query', () => {",
                  "  pm.response.to.have.status(400);",
                  "  pm.expect(pm.response.json().code).to.eql('invalid_query');",
                  "});"
                ]
              }
            }
          ]
        }
      ]
    }
  ]
}
