Skip to content

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:

typescript
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,
    },
  }
)
python
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:

json
{
  "_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 stage
  • reminder - Reminder sent, awaiting payment
  • debt_collection - In debt collection
  • enforcement - At enforcement authority
  • debt_surveillance - Long-term monitoring
  • amortization - Payment plan active
  • closed - Case is closed

Get Closed Cases

Retrieve all closed cases using the Pagination and Queries functionality:

typescript
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,
    },
  }
)
python
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:

json
{
  "_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 debtor
  • fully_paid_depreciation - Fully paid with depreciation
  • fully_paid_before_reminder - Paid before reminder stage
  • fully_paid_before_debt_collection - Paid before debt collection stage
  • recalled - Recalled by creditor
  • credit - Credited by creditor
  • deceased - Debtor deceased
  • bankruptcy - Debtor bankruptcy
  • written_off - Written off
  • debt_restructuring - Debt restructuring arrangement
  • capital_paid_to_creditor - Capital paid to creditor
  • dispute - Dispute resolution
  • cancellation - Cancelled

Get Cases Closed After Specific Date

Retrieve cases that were closed after a specific date using MongoDB query operators:

typescript
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,
    },
  }
)
python
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:

typescript
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,
    },
  }
)
python
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()