{
 "info": {
  "name": "Hub Multicanale — API Software House (collaudo)",
  "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
  "description": "Raccolta di prova per il collaudo. Genera l'asserzione con «node esempio.mjs asserzione» e incollala nella variabile client_assertion."
 },
 "item": [
  {
   "name": "1. Lasciapassare",
   "request": {
    "method": "POST",
    "header": [
     {
      "key": "Content-Type",
      "value": "application/x-www-form-urlencoded"
     }
    ],
    "body": {
     "mode": "urlencoded",
     "urlencoded": [
      {
       "key": "grant_type",
       "value": "client_credentials"
      },
      {
       "key": "client_assertion_type",
       "value": "urn:ietf:params:oauth:client-assertion-type:jwt-bearer"
      },
      {
       "key": "client_assertion",
       "value": "{{client_assertion}}"
      }
     ]
    },
    "url": {
     "raw": "{{base}}/api-token",
     "host": [
      "{{base}}"
     ],
     "path": [
      "api-token"
     ]
    }
   },
   "event": [
    {
     "listen": "test",
     "script": {
      "type": "text/javascript",
      "exec": [
       "const j = pm.response.json();",
       "if (j.access_token) pm.environment.set('access_token', j.access_token);"
      ]
     }
    }
   ]
  },
  {
   "name": "2. Enti e scenari",
   "request": {
    "method": "GET",
    "header": [
     {
      "key": "Authorization",
      "value": "Bearer {{access_token}}"
     }
    ],
    "url": {
     "raw": "{{base}}/api-sh/enti",
     "host": [
      "{{base}}"
     ],
     "path": [
      "api-sh",
      "enti"
     ]
    }
   }
  },
  {
   "name": "3. Crea lotto",
   "request": {
    "method": "POST",
    "header": [
     {
      "key": "Authorization",
      "value": "Bearer {{access_token}}"
     },
     {
      "key": "Content-Type",
      "value": "application/json"
     }
    ],
    "url": {
     "raw": "{{base}}/api-sh/enti/{{cf_ente}}/lotti",
     "host": [
      "{{base}}"
     ],
     "path": [
      "api-sh",
      "enti",
      "{{cf_ente}}",
      "lotti"
     ]
    },
    "body": {
     "mode": "raw",
     "raw": "{\n  \"scenario\": \"posta\",\n  \"id_lotto_esterno\": \"{{id_lotto}}\",\n  \"titolo\": \"Lotto Postman\",\n  \"opzioni\": {\n    \"prodotto\": \"ordinaria\",\n    \"stampa\": {\n      \"colore\": false,\n      \"fronte_retro\": true\n    }\n  }\n}"
    }
   },
   "event": [
    {
     "listen": "test",
     "script": {
      "type": "text/javascript",
      "exec": [
       "const j = pm.response.json();",
       "if (j.codice_lotto) pm.environment.set('codice_lotto', j.codice_lotto);"
      ]
     }
    }
   ]
  },
  {
   "name": "4. Aggiungi posizioni",
   "request": {
    "method": "POST",
    "header": [
     {
      "key": "Authorization",
      "value": "Bearer {{access_token}}"
     },
     {
      "key": "Content-Type",
      "value": "application/json"
     }
    ],
    "url": {
     "raw": "{{base}}/api-sh/enti/{{cf_ente}}/lotti/{{codice_lotto}}/posizioni",
     "host": [
      "{{base}}"
     ],
     "path": [
      "api-sh",
      "enti",
      "{{cf_ente}}",
      "lotti",
      "{{codice_lotto}}",
      "posizioni"
     ]
    },
    "body": {
     "mode": "raw",
     "raw": "{\n  \"posizioni\": [\n    {\n      \"protocollo_pa\": \"{{protocollo}}\",\n      \"causale\": \"Comunicazione di prova\",\n      \"destinatario\": {\n        \"cf_piva\": \"RSSMRA85T10A562S\",\n        \"tipo_persona\": \"fisica\",\n        \"denominazione\": \"Mario Rossi (prova)\"\n      },\n      \"indirizzo\": {\n        \"indirizzo\": \"Via Roma 1\",\n        \"cap\": \"00187\",\n        \"comune\": \"Roma\",\n        \"provincia\": \"RM\",\n        \"stato\": \"IT\"\n      },\n      \"documenti\": [\n        {\n          \"tipo\": \"atto\",\n          \"nome\": \"atto.pdf\"\n        }\n      ]\n    }\n  ]\n}"
    }
   }
  },
  {
   "name": "5. Carica il PDF",
   "request": {
    "method": "PUT",
    "header": [
     {
      "key": "Authorization",
      "value": "Bearer {{access_token}}"
     },
     {
      "key": "Content-Type",
      "value": "application/pdf"
     },
     {
      "key": "X-Content-SHA256",
      "value": "{{sha256_pdf}}"
     }
    ],
    "body": {
     "mode": "file",
     "file": {
      "src": ""
     }
    },
    "url": {
     "raw": "{{base}}/api-sh/enti/{{cf_ente}}/lotti/{{codice_lotto}}/posizioni/{{protocollo}}/documenti/atto.pdf",
     "host": [
      "{{base}}"
     ],
     "path": [
      "api-sh",
      "enti",
      "{{cf_ente}}",
      "lotti",
      "{{codice_lotto}}",
      "posizioni",
      "{{protocollo}}",
      "documenti",
      "atto.pdf"
     ]
    },
    "description": "Scegli il file nel corpo (binario) e metti in sha256_pdf l'impronta SHA-256 esadecimale del file (es. sha256sum atto.pdf)."
   }
  },
  {
   "name": "6. Conferma",
   "request": {
    "method": "POST",
    "header": [
     {
      "key": "Authorization",
      "value": "Bearer {{access_token}}"
     }
    ],
    "url": {
     "raw": "{{base}}/api-sh/enti/{{cf_ente}}/lotti/{{codice_lotto}}/conferma",
     "host": [
      "{{base}}"
     ],
     "path": [
      "api-sh",
      "enti",
      "{{cf_ente}}",
      "lotti",
      "{{codice_lotto}}",
      "conferma"
     ]
    }
   }
  },
  {
   "name": "7. Stato del lotto",
   "request": {
    "method": "GET",
    "header": [
     {
      "key": "Authorization",
      "value": "Bearer {{access_token}}"
     }
    ],
    "url": {
     "raw": "{{base}}/api-sh/enti/{{cf_ente}}/lotti/{{codice_lotto}}",
     "host": [
      "{{base}}"
     ],
     "path": [
      "api-sh",
      "enti",
      "{{cf_ente}}",
      "lotti",
      "{{codice_lotto}}"
     ]
    }
   }
  },
  {
   "name": "8. Cosa è cambiato",
   "request": {
    "method": "GET",
    "header": [
     {
      "key": "Authorization",
      "value": "Bearer {{access_token}}"
     }
    ],
    "url": {
     "raw": "{{base}}/api-sh/enti/{{cf_ente}}/cambiamenti",
     "host": [
      "{{base}}"
     ],
     "path": [
      "api-sh",
      "enti",
      "{{cf_ente}}",
      "cambiamenti"
     ]
    }
   },
   "event": [
    {
     "listen": "test",
     "script": {
      "type": "text/javascript",
      "exec": [
       "const j = pm.response.json();",
       "if (j.segnalibro) pm.environment.set('segnalibro', j.segnalibro);"
      ]
     }
    }
   ]
  },
  {
   "name": "9. Pacchetto della posizione",
   "request": {
    "method": "GET",
    "header": [
     {
      "key": "Authorization",
      "value": "Bearer {{access_token}}"
     }
    ],
    "url": {
     "raw": "{{base}}/api-sh/enti/{{cf_ente}}/lotti/{{codice_lotto}}/posizioni/{{protocollo}}",
     "host": [
      "{{base}}"
     ],
     "path": [
      "api-sh",
      "enti",
      "{{cf_ente}}",
      "lotti",
      "{{codice_lotto}}",
      "posizioni",
      "{{protocollo}}"
     ]
    }
   }
  },
  {
   "name": "10. Pacchetto di chiusura",
   "request": {
    "method": "GET",
    "header": [
     {
      "key": "Authorization",
      "value": "Bearer {{access_token}}"
     }
    ],
    "url": {
     "raw": "{{base}}/api-sh/enti/{{cf_ente}}/lotti/{{codice_lotto}}/pacchetto-chiusura",
     "host": [
      "{{base}}"
     ],
     "path": [
      "api-sh",
      "enti",
      "{{cf_ente}}",
      "lotti",
      "{{codice_lotto}}",
      "pacchetto-chiusura"
     ]
    }
   }
  }
 ]
}