{"openapi":"3.1.0","info":{"title":"Faktura API","version":"1.0.0","description":"REST API för fakturering. Alla belopp anges i ören (heltal) och alla datum som ÅÅÅÅ-MM-DD. Autentisera med `Authorization: Bearer <API-nyckel>`. Nycklar som börjar med `fk_test_` är sandlådenycklar: fakturor låses och numreras men inga mejl skickas."},"servers":[{"url":"/api/v1"}],"security":[{"bearer":[]}],"components":{"securitySchemes":{"bearer":{"type":"http","scheme":"bearer"}},"responses":{"Unauthorized":{"description":"Nyckel saknas eller är ogiltig","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"Validation":{"description":"Ogiltiga fält","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"RateLimited":{"description":"Högst 120 anrop per minut och nyckel","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"schemas":{"Error":{"type":"object","properties":{"error":{"type":"object","properties":{"code":{"type":"string","examples":["validation_failed"]},"message":{"type":"string"},"fields":{"type":"object","additionalProperties":{"type":"string"}}}}}},"Address":{"type":"object","properties":{"line1":{"type":"string"},"line2":{"type":"string"},"postal_code":{"type":"string"},"city":{"type":"string"},"country":{"type":"string","examples":["SE"]}}},"Customer":{"type":"object","properties":{"id":{"type":"string","format":"uuid","readOnly":true},"number":{"type":"integer","readOnly":true},"type":{"enum":["company","person"]},"name":{"type":"string"},"org_number":{"type":"string"},"vat_number":{"type":"string"},"email":{"type":"string","format":"email"},"cc_emails":{"type":"array","items":{"type":"string"}},"phone":{"type":"string"},"reference":{"type":"string"},"address":{"$ref":"#/components/schemas/Address"},"language":{"enum":["sv","en"]},"payment_terms_days":{"type":"integer"},"delivery_method":{"enum":["email","portal","peppol","kivra","letter"]},"tags":{"type":"array","items":{"type":"string"}}},"required":["name"]},"Product":{"type":"object","properties":{"id":{"type":"string","readOnly":true},"sku":{"type":"string"},"name":{"type":"string"},"description":{"type":"string"},"unit":{"type":"string","examples":["st","tim"]},"price_ore":{"type":"integer","description":"Pris exkl. moms i ören"},"vat_rate":{"enum":[25,12,6,0]},"type":{"enum":["goods","service"]},"active":{"type":"boolean"}},"required":["name","price_ore"]},"Line":{"type":"object","properties":{"type":{"enum":["item","text","heading"]},"product_id":{"type":"string"},"description":{"type":"string"},"details":{"type":"string"},"quantity":{"type":"number","examples":[1.5]},"unit":{"type":"string"},"unit_price_ore":{"type":"integer"},"discount_percent":{"type":"number"},"vat_rate":{"enum":[25,12,6,0]}},"required":["description","unit_price_ore"]},"InvoiceInput":{"type":"object","properties":{"customer_id":{"type":"string","format":"uuid"},"type":{"enum":["invoice","advance","partial","final","cash"]},"issue_date":{"type":"string","format":"date"},"payment_terms_days":{"type":"integer"},"your_reference":{"type":"string"},"our_reference":{"type":"string"},"notes":{"type":"string"},"reverse_charge":{"enum":["none","eu","construction","export"]},"language":{"enum":["sv","en"]},"lines":{"type":"array","items":{"$ref":"#/components/schemas/Line"}},"send":{"type":"boolean","description":"Skicka direkt efter att utkastet skapats"}},"required":["customer_id","lines"]},"Invoice":{"type":"object","properties":{"id":{"type":"string"},"number":{"type":["integer","null"]},"type":{"type":"string"},"status":{"enum":["draft","scheduled","sent","viewed","partially_paid","paid","overdue","reminded","collection","credited","void"]},"customer_id":{"type":"string"},"issue_date":{"type":"string"},"due_date":{"type":"string"},"ocr":{"type":["string","null"]},"subtotal_ore":{"type":"integer"},"vat_ore":{"type":"integer"},"rounding_ore":{"type":"integer"},"total_ore":{"type":"integer"},"amount_due_ore":{"type":"integer"},"paid_ore":{"type":"integer"},"vat":{"type":"array","items":{"type":"object"}},"public_url":{"type":["string","null"]},"lines":{"type":"array","items":{"$ref":"#/components/schemas/Line"}}}},"Payment":{"type":"object","properties":{"amount_ore":{"type":"integer"},"paid_on":{"type":"string","format":"date"},"method":{"type":"string"},"reference":{"type":"string"},"external_id":{"type":"string","description":"Din unika id. Samma id registreras bara en gång."}},"required":["amount_ore"]},"WebhookEvent":{"type":"object","description":"Skickas med POST. Verifiera med HMAC-SHA256: header X-Faktura-Signature = t=<tid>,v1=<hex av HMAC(secret, `${t}.${body}`)>.","properties":{"id":{"type":"string"},"type":{"enum":["invoice.created","invoice.sent","invoice.viewed","invoice.paid","invoice.overdue","invoice.credited","quote.accepted","customer.created"]},"created":{"type":"string","format":"date-time"},"data":{"type":"object"}}}}},"paths":{"/customers":{"get":{"summary":"Lista kunder","parameters":[{"name":"q","in":"query","schema":{"type":"string"}},{"name":"limit","in":"query","schema":{"type":"integer","maximum":200}},{"name":"offset","in":"query","schema":{"type":"integer"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Customer"}},"limit":{"type":"integer"},"offset":{"type":"integer"}}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"422":{"$ref":"#/components/responses/Validation"},"429":{"$ref":"#/components/responses/RateLimited"}}},"post":{"summary":"Skapa kund","parameters":[{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","maxLength":200},"description":"Samma nyckel och body ger samma svar utan att något skapas två gånger."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Customer"}}}},"responses":{"201":{"description":"Skapad","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Customer"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"422":{"$ref":"#/components/responses/Validation"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/customers/{id}":{"get":{"summary":"Hämta kund","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Customer"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"422":{"$ref":"#/components/responses/Validation"},"429":{"$ref":"#/components/responses/RateLimited"}}},"patch":{"summary":"Ändra kund","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Customer"}}}},"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Customer"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"422":{"$ref":"#/components/responses/Validation"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/products":{"get":{"summary":"Lista produkter","responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Product"}},"limit":{"type":"integer"},"offset":{"type":"integer"}}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"422":{"$ref":"#/components/responses/Validation"},"429":{"$ref":"#/components/responses/RateLimited"}}},"post":{"summary":"Skapa produkt","parameters":[{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","maxLength":200},"description":"Samma nyckel och body ger samma svar utan att något skapas två gånger."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Product"}}}},"responses":{"201":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Product"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"422":{"$ref":"#/components/responses/Validation"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/products/{id}":{"get":{"summary":"Hämta produkt","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Product"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"422":{"$ref":"#/components/responses/Validation"},"429":{"$ref":"#/components/responses/RateLimited"}}},"patch":{"summary":"Ändra produkt","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Product"}}}},"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Product"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"422":{"$ref":"#/components/responses/Validation"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/invoices":{"get":{"summary":"Lista fakturor","parameters":[{"name":"status","in":"query","schema":{"type":"string"}},{"name":"customer_id","in":"query","schema":{"type":"string"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Invoice"}},"limit":{"type":"integer"},"offset":{"type":"integer"}}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"422":{"$ref":"#/components/responses/Validation"},"429":{"$ref":"#/components/responses/RateLimited"}}},"post":{"summary":"Skapa faktura (utkast eller skicka direkt)","parameters":[{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","maxLength":200},"description":"Samma nyckel och body ger samma svar utan att något skapas två gånger."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/InvoiceInput"}}}},"responses":{"201":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Invoice"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"422":{"$ref":"#/components/responses/Validation"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/invoices/{id}":{"get":{"summary":"Hämta faktura med rader","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Invoice"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"422":{"$ref":"#/components/responses/Validation"},"429":{"$ref":"#/components/responses/RateLimited"}}},"patch":{"summary":"Ändra utkast (skickade fakturor kan inte ändras)","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/InvoiceInput"}}}},"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Invoice"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"409":{"description":"Fakturan är skickad"},"422":{"$ref":"#/components/responses/Validation"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/invoices/{id}/send":{"post":{"summary":"Skicka fakturan (låser nummer och OCR)","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","maxLength":200},"description":"Samma nyckel och body ger samma svar utan att något skapas två gånger."}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"recipients":{"type":"array","items":{"type":"string"}},"message":{"type":"string"},"mark_only":{"type":"boolean"}}}}}},"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Invoice"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"422":{"$ref":"#/components/responses/Validation"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/invoices/{id}/credit":{"post":{"summary":"Skapa kreditfaktura som hänvisar till originalet","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","maxLength":200},"description":"Samma nyckel och body ger samma svar utan att något skapas två gånger."}],"responses":{"201":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Invoice"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"422":{"$ref":"#/components/responses/Validation"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/invoices/{id}/payments":{"get":{"summary":"Lista betalningar","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object"}}}}}},"post":{"summary":"Registrera betalning","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}},{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","maxLength":200},"description":"Samma nyckel och body ger samma svar utan att något skapas två gånger."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/Payment"}}}},"responses":{"201":{"description":"OK","content":{"application/json":{"schema":{"type":"object"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"422":{"$ref":"#/components/responses/Validation"},"429":{"$ref":"#/components/responses/RateLimited"}}}},"/invoices/{id}/pdf":{"get":{"summary":"Hämta PDF","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"PDF","content":{"application/pdf":{}}}}}},"/quotes":{"get":{"summary":"Lista offerter","responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object"}}}}}},"post":{"summary":"Skapa offert","parameters":[{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","maxLength":200},"description":"Samma nyckel och body ger samma svar utan att något skapas två gånger."}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/InvoiceInput"}}}},"responses":{"201":{"description":"OK","content":{"application/json":{"schema":{"type":"object"}}}}}}},"/quotes/{id}/send":{"post":{"summary":"Skicka offert med länk för digitalt godkännande","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object"}}}}}}},"/quotes/{id}/convert":{"post":{"summary":"Gör om till order eller faktura","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"to":{"enum":["order","invoice"]}}}}}},"responses":{"201":{"description":"OK","content":{"application/json":{"schema":{"type":"object"}}}}}}},"/recurring":{"get":{"summary":"Lista återkommande fakturor","responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object"}}}}}},"post":{"summary":"Skapa återkommande faktura","parameters":[{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","maxLength":200},"description":"Samma nyckel och body ger samma svar utan att något skapas två gånger."}],"responses":{"201":{"description":"OK","content":{"application/json":{"schema":{"type":"object"}}}}}}},"/time-entries":{"get":{"summary":"Lista tid","responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object"}}}}}},"post":{"summary":"Registrera tid","parameters":[{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","maxLength":200},"description":"Samma nyckel och body ger samma svar utan att något skapas två gånger."}],"responses":{"201":{"description":"OK","content":{"application/json":{"schema":{"type":"object"}}}}}}},"/expenses":{"post":{"summary":"Registrera utlägg","parameters":[{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","maxLength":200},"description":"Samma nyckel och body ger samma svar utan att något skapas två gånger."}],"responses":{"201":{"description":"OK","content":{"application/json":{"schema":{"type":"object"}}}}}}},"/reports/summary":{"get":{"summary":"Obetalt, försenat och fakturerat denna månad","responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"object"}}}}}}}},"webhooks":{"invoiceEvent":{"post":{"summary":"Händelse","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/WebhookEvent"}}}},"responses":{"200":{"description":"Mottagen. Annat svar ger nya försök efter 1, 5, 30, 120 och 720 minuter."}}}}}}