Case Status Retrieval Example
This example shows how to retrieve case status information using the GET /cases endpoint. You can retrieve status for a specific case or query for multiple cases based on their status, state, or closure information.
The case resource contains detailed status tracking including current state, status history, and closure information. This is useful for monitoring case progress and identifying cases that have been closed.
All API requests require a valid authentication token in the X-API-Key header. For details about the authentication process and token management, see the Authentication documentation.
In this guide, we will use the AuthTokenProvider class (documented in the authentication guide) to handle token management.
Get Specific Case Status
Retrieve status information for a specific case using the Case endpoint:
const token = await auth.getValidToken()
const caseId = '6867da7788b9226bb78d716c'
const projection = encodeURIComponent(
JSON.stringify({
_id: 1,
state: 1,
status: 1,
closed: 1,
state_history: 1,
status_history: 1,
'debt.invoice_number': 1,
})
)
const response = await axios.get(
`https://api-sandbox.amili.se/cases/${caseId}?projection=${projection}`,
{
headers: {
'X-API-Key': token,
},
}
)import json
token = auth.get_valid_token()
case_id = '6867da7788b9226bb78d716c'
projection = json.dumps({
'_id': 1,
'state': 1,
'status': 1,
'closed': 1,
'state_history': 1,
'status_history': 1,
'debt.invoice_number': 1,
})
response = requests.get(
f'https://api-sandbox.amili.se/cases/{case_id}',
params={'projection': projection},
headers={'X-API-Key': token}
)
response.raise_for_status()
result = response.json()The response will include the current state and status, along with historical changes:
{
"_id": "6867da7788b9226bb78d716c",
"debt": {
"invoice_number": "INV-2025-003"
},
"state": "debt_collection",
"status": "debt_collection_active",
"state_history": [
{
"state": "invoice",
"state_date": "Mon, 07 Jul 2025 00:00:00 GMT"
},
{
"state": "reminder",
"state_date": "Mon, 11 Aug 2025 00:00:00 GMT"
},
{
"state": "debt_collection",
"state_date": "Mon, 25 Aug 2025 00:00:00 GMT"
}
],
"status_history": [
{
"status": "invoice_sent",
"status_date": "Mon, 07 Jul 2025 00:00:00 GMT"
},
{
"status": "reminder_sent",
"status_date": "Mon, 11 Aug 2025 00:00:00 GMT"
},
{
"status": "debt_collection_active",
"status_date": "Mon, 25 Aug 2025 00:00:00 GMT"
}
]
}Common Case States
The state field indicates the current stage of the case:
invoice- Invoice stagereminder- Reminder sent, awaiting paymentdebt_collection- In debt collectionenforcement- At enforcement authoritydebt_surveillance- Long-term monitoringamortization- Payment plan activeclosed- Case is closed
Get Closed Cases
Retrieve all closed cases using the Pagination and Queries functionality:
const token = await auth.getValidToken()
const where = encodeURIComponent(JSON.stringify({ closed: { $exists: true } }))
const projection = encodeURIComponent(
JSON.stringify({
_id: 1,
closed: 1,
'debt.invoice_number': 1,
total_remaining_capital_amount: 1,
})
)
const response = await axios.get(
`https://api-sandbox.amili.se/cases?where=${where}&projection=${projection}&sort=-closed.close_date&max_results=50`,
{
headers: {
'X-API-Key': token,
},
}
)import json
token = auth.get_valid_token()
where = json.dumps({'closed': {'$exists': True}})
projection = json.dumps({
'_id': 1,
'closed': 1,
'debt.invoice_number': 1,
'total_remaining_capital_amount': 1,
})
response = requests.get(
'https://api-sandbox.amili.se/cases',
params={
'where': where,
'projection': projection,
'sort': '-closed.close_date',
'max_results': 50,
},
headers={'X-API-Key': token}
)
response.raise_for_status()
result = response.json()The response will include all closed cases with their closure information:
{
"_items": [
{
"_id": "507f1f77bcf86cd799439011",
"debt": {
"invoice_number": "INV-2025-020"
},
"closed": {
"close_date": "Wed, 03 Sep 2025 11:18:59 GMT",
"reason": "fully_paid"
},
"total_remaining_capital_amount": 0
},
{
"_id": "507f1f77bcf86cd799439012",
"debt": {
"invoice_number": "INV-2025-019"
},
"closed": {
"close_date": "Tue, 02 Sep 2025 14:22:15 GMT",
"reason": "recalled"
},
"total_remaining_capital_amount": 1500.5
},
{
"_id": "507f1f77bcf86cd799439013",
"debt": {
"invoice_number": "INV-2025-018"
},
"closed": {
"close_date": "Mon, 01 Sep 2025 09:45:30 GMT",
"reason": "bankruptcy"
},
"total_remaining_capital_amount": 2500.0
}
],
"_meta": {
"page": 1,
"max_results": 50,
"total": 142
}
}Common Close Reasons
The closed.reason field indicates why the case was closed:
fully_paid- Fully paid by debtorfully_paid_depreciation- Fully paid with depreciationfully_paid_before_reminder- Paid before reminder stagefully_paid_before_debt_collection- Paid before debt collection stagerecalled- Recalled by creditorcredit- Credited by creditordeceased- Debtor deceasedbankruptcy- Debtor bankruptcywritten_off- Written offdebt_restructuring- Debt restructuring arrangementcapital_paid_to_creditor- Capital paid to creditordispute- Dispute resolutioncancellation- Cancelled
Get Cases Closed After Specific Date
Retrieve cases that were closed after a specific date using MongoDB query operators:
const token = await auth.getValidToken()
const where = encodeURIComponent(
JSON.stringify({
closed: { $exists: true },
'closed.close_date': { $gt: 'Mon, 13 Jan 2026 00:00:00 GMT' },
})
)
const projection = encodeURIComponent(
JSON.stringify({
_id: 1,
closed: 1,
'debt.invoice_number': 1,
total_remaining_capital_amount: 1,
})
)
const response = await axios.get(
`https://api-sandbox.amili.se/cases?where=${where}&projection=${projection}&sort=-closed.close_date`,
{
headers: {
'X-API-Key': token,
},
}
)import json
token = auth.get_valid_token()
where = json.dumps({
'closed': {'$exists': True},
'closed.close_date': {'$gt': 'Mon, 13 Jan 2026 00:00:00 GMT'},
})
projection = json.dumps({
'_id': 1,
'closed': 1,
'debt.invoice_number': 1,
'total_remaining_capital_amount': 1,
})
response = requests.get(
'https://api-sandbox.amili.se/cases',
params={
'where': where,
'projection': projection,
'sort': '-closed.close_date',
},
headers={'X-API-Key': token}
)
response.raise_for_status()
result = response.json()This query uses the MongoDB $gt (greater than) operator to filter cases closed after the specified date. This is useful for incremental exports where you only want to retrieve cases closed since your last query.
Get Cases by Close Reason
Filter closed cases by specific close reason:
const token = await auth.getValidToken()
const where = encodeURIComponent(
JSON.stringify({
'closed.reason': 'fully_paid',
})
)
const projection = encodeURIComponent(
JSON.stringify({
_id: 1,
closed: 1,
'debt.invoice_number': 1,
total_remaining_capital_amount: 1,
})
)
const response = await axios.get(
`https://api-sandbox.amili.se/cases?where=${where}&projection=${projection}`,
{
headers: {
'X-API-Key': token,
},
}
)import json
token = auth.get_valid_token()
where = json.dumps({
'closed.reason': 'fully_paid',
})
projection = json.dumps({
'_id': 1,
'closed': 1,
'debt.invoice_number': 1,
'total_remaining_capital_amount': 1,
})
response = requests.get(
'https://api-sandbox.amili.se/cases',
params={
'where': where,
'projection': projection,
},
headers={'X-API-Key': token}
)
response.raise_for_status()
result = response.json()Related Documentation
- Case Endpoint Reference - Complete field descriptions and case properties
- Pagination and Queries - Advanced filtering, sorting, and pagination
- Authentication - Token management and authentication
- Finance Payout Specification Example - Track case outcomes and payouts
