Invoice Flow Example
Diagrammet nedan visar den grundläggande sekvensen av API-anrop för att hantera en faktura, med varje steg beskrivet i följande sektioner.
En faktura registreras med all nödvändig gäldenär- och fakturainformation som behövs för att starta fakturaprocessen. Efter denna punkt kan du när som helst få den nuvarande statusen för fakturan, inklusive detaljerad information om dess tillstånd i processen. Två valfria vägar beskrivs sedan: först, där en del av fakturabeloppet krediteras av borgenären, och för det andra, där fakturan avbokas helt.
Steg-för-steg-guide
Alla API-requests kräver en giltig autentiseringstoken i X-API-Key header. För detaljer om autentiseringsprocessen och tokenhantering, se Authentication documentation.
I denna guide kommer vi att använda AuthTokenProvider-klassen (dokumenterad i autentiseringsguiden) för att hantera tokenhantering.
1. Registrera en faktura
Registrera en ny faktura med Invoice Registration endpoint:
const invoiceData = {
account: '674dbeaf08847b9501cc9132',
creditor: '674dbeb208847b9501cc9138',
invoice_number: 'INV-2025-015',
invoice_date: new Date().toISOString(),
invoice_due_date: '2025-10-17T00:00:00Z',
currency: 'SEK',
invoice_type: 'invoice',
invoice_headline: 'Consulting Services',
invoice_body_text: 'Thank you for your business',
customer: {
name: 'Jane Smith',
id_number: '556789-1234',
is_person: true,
address: {
address_line_1: 'Business Street 456',
zip_code: '54321',
city: 'Gothenburg',
},
mobile_number: '+46709876543',
email: 'jane.smith@domain.se',
},
matrix: [
{
article_description: 'Consulting hours',
unit_price: 500.0,
total_price_excluding_vat: 500.0,
unit_vat_percent: '0%',
},
],
}
const token = await auth.getValidToken()
const response = await axios.post(
'https://api-sandbox.amili.se/invoice-registration',
invoiceData,
{
headers: {
'X-API-Key': token,
'Content-Type': 'application/json',
},
}
)invoice_data = {
"account": "674dbeaf08847b9501cc9132",
"creditor": "674dbeb208847b9501cc9138",
"invoice_number": "INV-2025-015",
"invoice_date": datetime.utcnow().isoformat() + "Z",
"invoice_due_date": "2025-10-17T00:00:00Z",
"currency": "SEK",
"invoice_type": "invoice",
"invoice_headline": "Consulting Services",
"invoice_body_text": "Thank you for your business",
"customer": {
"name": "Jane Smith",
"id_number": "556789-1234",
"is_person": True,
"address": {
"address_line_1": "Business Street 456",
"zip_code": "54321",
"city": "Gothenburg"
},
"mobile_number": "+46709876543",
"email": "jane.smith@domain.se"
},
"matrix": [{
"article_description": "Consulting hours",
"unit_price": 500.0,
"total_price_excluding_vat": 500.0,
"unit_vat_percent": "0%"
}]
}
token = auth.get_valid_token()
response = requests.post(
'https://api-sandbox.amili.se/invoice-registration',
json=invoice_data,
headers={
'X-API-Key': token,
'Content-Type': 'application/json'
}
)
response.raise_for_status()
result = response.json()Svaret kommer att vara:
{
"_updated": "Tue, 07 Oct 2025 07:41:01 GMT",
"_created": "Tue, 07 Oct 2025 07:41:01 GMT",
"_etag": "8bfdf8614dc48aa763568c6e6a914e3f0503e18e",
"_id": "68e4c40d7fcb697a78cb1a32",
"_status": "OK",
"_invoice": "68e4c40d7fcb697a78cb1a32",
"_case": "68e4c40d93ee14723d28fa95",
"_ocr_number": "68e4c40e7fcb697a78cb1a36",
"ocr_number_ocr": "20252806663259506081"
}2. Hämta Case-status
Hitta ditt Case baserat på Creditor fakturanummer och få den nuvarande statusen med Case endpoint med Query parameter för att hitta fakturan med borgenärens fakturanummer:
const token = await auth.getValidToken()
const query = encodeURIComponent(
JSON.stringify({ debt.invoice_number: 'INV-2025-015' })
)
const response = await axios.get(
`https://api-sandbox.amili.se/cases?where=${query}`,
{
headers: {
'X-API-Key': token,
},
}
)import json
token = auth.get_valid_token()
query = json.dumps({'debt.invoice_number': 'INV-2025-015'})
response = requests.get(
'https://api-sandbox.amili.se/cases',
params={'where': query},
headers={'X-API-Key': token}
)
response.raise_for_status()
result = response.json()Svaret kommer att vara:
{
"_items": [
{
"_id": "68e4c40d93ee14723d28fa95",
"invoice": "68e4c40d7fcb697a78cb1a32",
"_created": "Tue, 07 Oct 2025 07:41:01 GMT",
"_etag": "808c0829161342bc8566b14cf4547dfb",
"_updated": "Tue, 07 Oct 2025 07:41:01 GMT",
"account": "674dbeaf08847b9501cc9132",
"agreement_version": "6790c2ec38ebf4814061f0b5",
"case_settings": {
"interest_rate": {
"reference_rate": true
}
},
"creditor": "674dbeb208847b9501cc9138",
"creditor_name": "Amili Integration Team",
"currency": "SEK",
"customer": "68678ed98d8dc95ece127941",
"customer_id_number": "556789-1234",
"customer_name": "Jane Smith",
"customer_number": "12345",
"customer_status": "initialized",
"debt": {
"invoice_number": "INV-2025-015",
"invoice_date": "Tue, 07 Oct 2025 10:11:22 GMT",
"invoice_due_days_after_invoice_date": 8,
"interest_days_after_invoice_date": 8,
"initial_capital": 500,
"capital_to_claim": 500,
"debt_description": "Professional consulting services",
"payout_reference": "INV-2025-015"
},
"invoice_registration": "68e4c40d7fcb697a78cb1a32",
"latest_state_date": "Tue, 07 Oct 2025 07:41:01 GMT",
"local_added_capital_amount": 500,
"local_added_costs_amount": 0,
"local_added_interest_amount": 0,
"local_added_transaction_amount": 500,
"local_remaining_capital_amount": 500,
"local_remaining_costs_amount": 0,
"local_remaining_interest_amount": 0,
"local_remaining_transaction_amount": 500,
"state": "initializing",
"state_history": [
{
"state": "initializing",
"state_date": "Tue, 07 Oct 2025 07:41:01 GMT"
}
],
"status": "initializing",
"status_history": [
{
"status": "initializing",
"status_date": "Tue, 07 Oct 2025 07:41:01 GMT"
}
],
"total_added_capital_amount": 500,
"total_added_costs_amount": 0,
"total_added_interest_amount": 0,
"total_added_transaction_amount": 500,
"total_remaining_capital_amount": 500,
"total_remaining_costs_amount": 0,
"total_remaining_interest_amount": 0,
"total_remaining_transaction_amount": 500,
"transactions": [
{
"bank_transaction_date": "Tue, 07 Oct 2025 00:00:00 GMT",
"registration_date": "Tue, 07 Oct 2025 00:27:01 GMT",
"origin": "creditor_system",
"type": "capital",
"description_locale_tag": "api.transaction.case_registration",
"amount": 500
}
],
"reference_number": "49477"
}
],
"_meta": {
"page": 1,
"max_results": 25,
"total": 1
}
}3. Kreditera del av faktura
Kreditera en del av fakturabeloppet med Creditor Crediting endpoint:
const creditData = {
account: '674dbeaf08847b9501cc9132',
creditor: '674dbeb208847b9501cc9138',
case: '68e4c40d93ee14723d28fa95',
currency: 'SEK',
amount: 100.0,
origin: 'creditor_system',
}
const token = await auth.getValidToken()
const response = await axios.post(
'https://api-sandbox.amili.se/creditor-crediting',
creditData,
{
headers: {
'X-API-Key': token,
'Content-Type': 'application/json',
},
}
)credit_data = {
"account": "674dbeaf08847b9501cc9132",
"creditor": "674dbeb208847b9501cc9138",
"case": "68e4c40d93ee14723d28fa95",
"currency": "SEK",
"amount": 100.0,
"origin": "creditor_system"
}
token = auth.get_valid_token()
response = requests.post(
'https://api-sandbox.amili.se/creditor-crediting',
json=credit_data,
headers={
'X-API-Key': token,
'Content-Type': 'application/json'
}
)
response.raise_for_status()
result = response.json()Svaret kommer att vara:
{
"_updated": "Tue, 07 Oct 2025 07:51:56 GMT",
"_created": "Tue, 07 Oct 2025 07:51:56 GMT",
"_etag": "820ce3cd3b676e48d1ec0cc0b5cb46811ea2763e",
"_id": "68e4c69c0da90297b3be0dfd",
"_status": "OK",
"_crediting_status": "completed"
}4. Avboka en faktura
Avboka fakturan med Creditor Cancellation endpoint:
const cancellationData = {
creditor: '674dbeb208847b9501cc9138',
case: '68e4c40d93ee14723d28fa95',
origin: 'creditor_system',
}
const token = await auth.getValidToken()
const response = await axios.post(
'https://api-sandbox.amili.se/creditor-cancellation',
cancellationData,
{
headers: {
'X-API-Key': token,
'Content-Type': 'application/json',
},
}
)cancellation_data = {
"creditor": "674dbeb208847b9501cc9138",
"case": "68e4c40d93ee14723d28fa95",
"origin": "creditor_system"
}
token = auth.get_valid_token()
response = requests.post(
'https://api-sandbox.amili.se/creditor-cancellation',
json=cancellation_data,
headers={
'X-API-Key': token,
'Content-Type': 'application/json'
}
)
response.raise_for_status()
result = response.json()Svaret kommer att vara:
{
"_updated": "Tue, 07 Oct 2025 07:53:04 GMT",
"_created": "Tue, 07 Oct 2025 07:53:04 GMT",
"_etag": "d708022fbf6594c332235d07e952423b41dbdbcc",
"_id": "68e4c6e07fcb697a78cb1a37",
"_status": "OK",
"_cancellation_status": "completed"
}