{"openapi":"3.0.3","info":{"title":"APP-ARE API v1","version":"1.0.0","description":"API machine per gestionali (accesso anticipato). Canale documenti (hash-only) e sessioni campo. Autenticazione: Authorization: Bearer appare_sk_live_…. Le API key si creano e si revocano da https://app-are-web.com/integrazioni (account con email verificata). Rate limit: 60 richieste/minuto per API key (endpoint autenticati); 120 richieste/minuto per indirizzo IP sugli endpoint pubblici (GET /, /openapi.json, /health). Oltre soglia: HTTP 429 con error \"resource-exhausted\". Il conteggio è applicativo e best-effort (per istanza del servizio): non è uno SLA. Webhook outbound: vedi PUT /webhooks e il callback \"certificate.ready\". AVVERTENZE LEGALI (accesso anticipato). APP-ARE non è un sistema di protocollo informatico e non è un collegamento al MePA: queste API non sostituiscono protocollazione, conservazione a norma né acquisti P.A. Canale documenti hash-only: certifica l’impronta SHA-256 (integrità / esistenza dei byte), non il contenuto della scena né autore o luogo. Marca temporale QTSP: data/ora e integrità dell’oggetto marcato, non veridicità del contenuto; il peso probatorio lo valuta l’autorità competente. Rate limit e webhook sono best-effort (non SLA). Chi detiene la API key agisce per conto del titolare. Guida completa: docs/api-v1.md nel repository / assistenza comunicazioni@app-are-web.com. Termini e Privacy: https://app-are-web.com/legal/termini e https://app-are-web.com/legal/privacy.","contact":{"email":"comunicazioni@app-are-web.com"}},"servers":[{"url":"https://app-are-web.com/api/v1"}],"tags":[{"name":"Meta","description":"Specifica e stato del servizio (pubblici)."},{"name":"Documenti","description":"Canale documenti, hash-only."},{"name":"Sessioni","description":"Canale campo: deep link / QR verso l’app."},{"name":"Webhook","description":"Eventi in uscita verso il tuo gestionale."}],"components":{"securitySchemes":{"ApiKeyBearer":{"type":"http","scheme":"bearer","bearerFormat":"appare_sk_live_","description":"API key tenant emessa dall’account APP-ARE (https://app-are-web.com/integrazioni). La secret completa è mostrata una sola volta alla creazione. Limite: 60 richieste/minuto per key."}},"responses":{"BadRequest":{"description":"Richiesta non valida (error: invalid-argument).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"Unauthorized":{"description":"API key assente, malformata o non riconosciuta (error: unauthenticated).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"Forbidden":{"description":"API key revocata o risorsa di un altro titolare (error: permission-denied).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"NotFound":{"description":"Risorsa o route non trovata (error: not-found / not_found).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"TooManyRequests":{"description":"Rate limit superato (error: resource-exhausted). 60/min per API key sugli endpoint autenticati; 120/min per IP sui GET pubblici. Riprova dopo circa un minuto.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"},"example":{"ok":false,"error":"resource-exhausted","message":"Limite richieste API key raggiunto (60/min). Riprova tra poco."}}}},"InternalError":{"description":"Errore interno (error: internal) o servizio non disponibile (unavailable).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"schemas":{"Error":{"type":"object","required":["ok","error","message"],"properties":{"ok":{"type":"boolean","enum":[false]},"error":{"type":"string","description":"Codice errore. Corrispondenza HTTP: invalid-argument=400, unauthenticated=401, permission-denied=403, not-found=404 (route inesistente: not_found), already-exists=409, failed-precondition=412, resource-exhausted=429, unavailable=503, internal=500.","example":"unauthenticated"},"message":{"type":"string","example":"API key non riconosciuta."}}},"HealthResponse":{"type":"object","properties":{"ok":{"type":"boolean","enum":[true]},"service":{"type":"string","example":"api-v1"}}},"CertifyRequest":{"type":"object","required":["title","createdAtIso","files","manifestSha256"],"properties":{"title":{"type":"string","maxLength":140},"description":{"type":"string","maxLength":2000},"createdAtIso":{"type":"string","format":"date-time"},"channel":{"type":"string","description":"upload | documents"},"deviceLines":{"type":"array","items":{"type":"string"}},"locationLines":{"type":"array","items":{"type":"string"}},"files":{"type":"array","description":"Metadati hash-only: i byte del file non transitano sul server.","items":{"type":"object","required":["sha256","byteLength","mime"],"properties":{"sha256":{"type":"string","pattern":"^[a-fA-F0-9]{64}$"},"byteLength":{"type":"integer","minimum":1},"mime":{"type":"string"},"fileName":{"type":"string"}}}},"manifestSha256":{"type":"string","description":"SHA-256 del manifest canonico dei file."}}},"CertifyResponse":{"type":"object","properties":{"ok":{"type":"boolean"},"reportId":{"type":"string"},"pdfSha256":{"type":"string"},"manifestSha256":{"type":"string"},"verifyUrl":{"type":"string"}}},"SessionRequest":{"type":"object","properties":{"title":{"type":"string"},"metadata":{"type":"object","additionalProperties":{"type":"string"},"description":"Es. orderId, plate, siteCode"},"expiresInSeconds":{"type":"integer","minimum":300,"maximum":604800}}},"SessionResponse":{"type":"object","properties":{"ok":{"type":"boolean"},"sessionId":{"type":"string"},"token":{"type":"string"},"deepLink":{"type":"string"},"httpsLink":{"type":"string"},"expiresAt":{"type":"string","format":"date-time"}}},"WebhookConfig":{"type":"object","required":["webhookUrl"],"properties":{"webhookUrl":{"type":"string","nullable":true,"description":"URL https destinazione eventi (max 500 caratteri). null per rimuovere il webhook."}}},"WebhookConfigResponse":{"type":"object","properties":{"ok":{"type":"boolean","enum":[true]},"webhookUrl":{"type":"string","nullable":true},"webhookSecret":{"type":"string","nullable":true,"description":"Segreto di firma completo (whsec_…), restituito una sola volta quando si imposta un webhookUrl."},"webhookSecretHint":{"type":"string","nullable":true,"description":"Indizio (primi caratteri) del segreto di firma."}}},"CertificateReadyEvent":{"type":"object","description":"Corpo JSON del webhook `certificate.ready`, inviato quando un certificato del canale documenti è emesso. Il corpo grezzo (stringa esatta ricevuta) è quello su cui si calcola la firma.","required":["type","reportId","deliveredAt"],"properties":{"type":{"type":"string","enum":["certificate.ready"]},"reportId":{"type":"string","description":"Id del certificato; usabile in GET /certificates/{id}."},"kind":{"type":"string","example":"upload","description":"Tipo certificato (oggi: upload)."},"pdfSha256":{"type":"string","description":"SHA-256 del PDF certificato (esadecimale)."},"manifestSha256":{"type":"string","description":"SHA-256 del manifest dei file certificati."},"title":{"type":"string"},"verifyUrl":{"type":"string","description":"Link pubblico di verifica del certificato."},"deliveredAt":{"type":"string","format":"date-time","description":"Istante di invio (ISO 8601, UTC). Identico nei retry dello stesso evento."}}}}},"security":[{"ApiKeyBearer":[]}],"paths":{"/openapi.json":{"get":{"tags":["Meta"],"security":[],"summary":"Questa specifica OpenAPI","description":"Pubblico. Limite: 120 richieste/minuto per IP.","responses":{"200":{"description":"OpenAPI 3 JSON"},"429":{"$ref":"#/components/responses/TooManyRequests"}}}},"/health":{"get":{"tags":["Meta"],"security":[],"summary":"Stato del servizio","description":"Pubblico, senza API key. Risponde 200 se il router API è raggiungibile; non verifica dipendenze esterne. Limite: 120 richieste/minuto per IP.","responses":{"200":{"description":"Servizio raggiungibile","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HealthResponse"},"example":{"ok":true,"service":"api-v1"}}}},"429":{"$ref":"#/components/responses/TooManyRequests"}}}},"/documents/certify":{"post":{"tags":["Documenti"],"summary":"Certifica impronte file (canale documenti)","description":"Avvia la pipeline upload-act: marca temporale QTSP + ancoraggio. Solo hash/metadati — i byte restano sul client. Certifica l’impronta, non il significato del contenuto (vedi avvertenze legali in info). Se hai configurato un webhook, a emissione avvenuta parte `certificate.ready`. Limite: 60 richieste/minuto per API key.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CertifyRequest"}}}},"responses":{"200":{"description":"Certificato emesso","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CertifyResponse"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"429":{"$ref":"#/components/responses/TooManyRequests"},"500":{"$ref":"#/components/responses/InternalError"}}}},"/certificates/{id}":{"get":{"tags":["Documenti"],"summary":"Stato certificato (reportId o pdfSha256)","description":"Solo certificati del titolare della API key. Limite: 60 richieste/minuto per API key.","parameters":[{"name":"id","in":"path","required":true,"description":"reportId oppure SHA-256 del PDF certificato.","schema":{"type":"string"}}],"responses":{"200":{"description":"Metadati certificato del titolare"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"},"429":{"$ref":"#/components/responses/TooManyRequests"}}}},"/sessions":{"post":{"tags":["Sessioni"],"summary":"Crea sessione campo (deep link / QR)","description":"Limite: 60 richieste/minuto per API key.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/SessionRequest"}}}},"responses":{"200":{"description":"Sessione aperta","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SessionResponse"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"429":{"$ref":"#/components/responses/TooManyRequests"}}}},"/sessions/{sessionId}":{"get":{"tags":["Sessioni"],"summary":"Leggi sessione campo","description":"Limite: 60 richieste/minuto per API key.","parameters":[{"name":"sessionId","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Sessione"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"},"429":{"$ref":"#/components/responses/TooManyRequests"}}}},"/webhooks":{"put":{"tags":["Webhook"],"summary":"Configura webhook outbound sulla API key corrente","description":"Imposta (o rimuove con null) l’URL https che riceve gli eventi della API key usata nella chiamata. Ogni chiave ha un segreto di firma (whsec_…); questa risposta ne restituisce solo un indizio, mai il valore completo. \n\nCONSEGNA. Metodo POST, Content-Type application/json, User-Agent APP-ARE-Webhooks/1.0. Header: X-APP-ARE-Signature (hex minuscolo), X-APP-ARE-Timestamp (secondi Unix), X-APP-ARE-Key-Id (id della API key, es. ak_…). \n\nFIRMA. signature = HMAC_SHA256(secret, `${timestamp}.${rawBody}`) in esadecimale, dove rawBody è il corpo ricevuto byte per byte, prima di qualsiasi parsing JSON. Confronta in tempo costante e scarta timestamp troppo vecchi (consigliato: oltre 5 minuti). \n\nRETRY. Successo = qualsiasi risposta HTTP 2xx entro 8 secondi. Altrimenti fino a 3 tentativi totali con attesa di 500 ms e poi 2 s tra un tentativo e l’altro. Il corpo e il timestamp sono identici nei tentativi: deduplica su type + reportId. \n\nCONSEGNE FALLITE. Dopo il 3° tentativo l’evento non viene rinviato. L’esito è registrato lato server (collezione apiWebhookDeliveries) ma non è ancora leggibile dal tenant: per questo, in caso di dubbi, interroga GET /certificates/{id}. \n\nEVENTI. Oggi: certificate.ready (vedi callback). Limite: 60 richieste/minuto per API key.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/WebhookConfig"}}}},"responses":{"200":{"description":"Webhook aggiornato","content":{"application/json":{"schema":{"$ref":"#/components/schemas/WebhookConfigResponse"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/NotFound"},"412":{"description":"API key revocata (error: failed-precondition).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"$ref":"#/components/responses/TooManyRequests"}},"callbacks":{"certificate.ready":{"{$request.body#/webhookUrl}":{"post":{"summary":"Evento certificate.ready (da APP-ARE al tuo endpoint)","description":"Inviato quando un certificato del canale documenti è emesso. Header: X-APP-ARE-Signature, X-APP-ARE-Timestamp, X-APP-ARE-Key-Id. Firma = HMAC_SHA256(secret, `${X-APP-ARE-Timestamp}.${rawBody}`) esadecimale. Rispondi 2xx entro 8 secondi; fino a 3 tentativi (500 ms, 2 s).","parameters":[{"name":"X-APP-ARE-Signature","in":"header","required":true,"schema":{"type":"string"},"description":"HMAC-SHA256 esadecimale di `${timestamp}.${rawBody}` con il segreto whsec_…."},{"name":"X-APP-ARE-Timestamp","in":"header","required":true,"schema":{"type":"string"},"description":"Secondi Unix al momento dell’invio."},{"name":"X-APP-ARE-Key-Id","in":"header","required":true,"schema":{"type":"string"},"description":"Id della API key a cui è associato il webhook."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CertificateReadyEvent"},"example":{"type":"certificate.ready","reportId":"abc123","kind":"upload","pdfSha256":"0000000000000000000000000000000000000000000000000000000000000000","manifestSha256":"1111111111111111111111111111111111111111111111111111111111111111","title":"Consegna lotto 42","verifyUrl":"https://app-are-web.com/v/0000000000000000000000000000000000000000000000000000000000000000","deliveredAt":"2026-11-30T18:00:00.000Z"}}}},"responses":{"2XX":{"description":"Evento accettato."}}}}}}}}}}