{
  "info": {
    "name": "Askme Sign — Quickstart",
    "_postman_id": "askme-sign-quickstart-v1",
    "description": "Collection di base per iniziare a usare le API di Askme Sign. Segui i passaggi in ordine per inviare la tua prima pratica di firma.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    {
      "key": "base_url",
      "value": "https://sign.askme.it/api/v2",
      "type": "string"
    },
    {
      "key": "sign_token",
      "value": "INSERISCI_IL_TUO_TOKEN",
      "type": "string"
    },
    {
      "key": "sign_user",
      "value": "INSERISCI_IL_TUO_USERNAME",
      "type": "string"
    },
    {
      "key": "id_file",
      "value": "",
      "type": "string",
      "description": "Viene popolato automaticamente dopo aver creato la pratica (Step 3)"
    }
  ],
  "item": [
    {
      "name": "Step 1 — Verifica le credenziali",
      "request": {
        "method": "GET",
        "header": [
          { "key": "X-SignToken", "value": "{{sign_token}}" },
          { "key": "X-SignUser", "value": "{{sign_user}}" }
        ],
        "url": {
          "raw": "{{base_url}}/account",
          "host": ["{{base_url}}"],
          "path": ["account"]
        },
        "description": "Verifica che le credenziali siano valide. Dovresti ricevere i dati del tuo account (nome, email, permessi). Se ricevi un errore 401, verifica i valori di sign_token e sign_user nelle variabili della collection."
      }
    },
    {
      "name": "Step 2 — Crea la pratica",
      "event": [
        {
          "listen": "test",
          "script": {
            "exec": [
              "const json = pm.response.json();",
              "if (json.idFile) {",
              "    pm.collectionVariables.set('id_file', json.idFile);",
              "    console.log('id_file salvato:', json.idFile);",
              "}"
            ],
            "type": "text/javascript"
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          { "key": "X-SignToken", "value": "{{sign_token}}" },
          { "key": "X-SignUser", "value": "{{sign_user}}" },
          { "key": "Content-Type", "value": "application/json" }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"documents\": [\n    {\n      \"filename\": \"contratto.pdf\",\n      \"base64content\": \"INSERISCI_IL_PDF_IN_BASE64\"\n    }\n  ],\n  \"name\": \"Test Quickstart\",\n  \"sendNotifications\": true,\n  \"expirationDateDays\": 7,\n  \"signers\": [\n    {\n      \"firstName\": \"Mario\",\n      \"lastName\": \"Rossi\",\n      \"email\": \"mario.rossi@example.com\",\n      \"action\": \"S\",\n      \"signatureCoordinates\": [\n        {\n          \"document\": 0,\n          \"page\": 1,\n          \"signatureType\": \"S\",\n          \"positionX\": 0.6,\n          \"positionY\": 0.8,\n          \"width\": 0.2,\n          \"height\": 0.08\n        }\n      ]\n    }\n  ]\n}",
          "options": {
            "raw": { "language": "json" }
          }
        },
        "url": {
          "raw": "{{base_url}}/files/send",
          "host": ["{{base_url}}"],
          "path": ["files", "send"]
        },
        "description": "Crea una nuova pratica di firma con un firmatario. Sostituisci INSERISCI_IL_PDF_IN_BASE64 con il contenuto del tuo PDF codificato in Base64.\n\nDopo l'invio, l'id_file viene salvato automaticamente nelle variabili della collection per i passi successivi."
      }
    },
    {
      "name": "Step 3 — Controlla lo stato",
      "request": {
        "method": "GET",
        "header": [
          { "key": "X-SignToken", "value": "{{sign_token}}" },
          { "key": "X-SignUser", "value": "{{sign_user}}" }
        ],
        "url": {
          "raw": "{{base_url}}/files/{{id_file}}",
          "host": ["{{base_url}}"],
          "path": ["files", "{{id_file}}"]
        },
        "description": "Controlla lo stato della pratica. I valori possibili sono:\n- L: In lavorazione (in attesa di firma)\n- F: Firmato (tutte le firme completate)\n- R: Rifiutato\n- E: Scaduto\n\nL'id_file viene preso automaticamente dalla variabile salvata nel passo precedente."
      }
    },
    {
      "name": "Step 4 — Scarica il documento firmato",
      "request": {
        "method": "GET",
        "header": [
          { "key": "X-SignToken", "value": "{{sign_token}}" },
          { "key": "X-SignUser", "value": "{{sign_user}}" }
        ],
        "url": {
          "raw": "{{base_url}}/files/download/{{id_file}}",
          "host": ["{{base_url}}"],
          "path": ["files", "download", "{{id_file}}"]
        },
        "description": "Scarica il documento firmato in formato PDF. Disponibile solo quando lo stato della pratica è F (Firmato).\n\nIn Postman, salva la risposta come file: Send → Save Response → Save to a file."
      }
    }
  ]
}
