> For the complete documentation index, see [llms.txt](https://akiba-digital.gitbook.io/akiba-api-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://akiba-digital.gitbook.io/akiba-api-docs/api-documentation/risk-analysis/insights/spend-analysis.md).

# Spend analysis

### Spending analysis requires transaction data

For us to analyse spending patterns of your customer, we need transaction data from their bank account, wallet and or POS in the case of SMEs.

#### Example Transactions Object schema required:

```javascript
{
  "transactions": [
    {
      "external_transaction_id": "958d14298-91ee-405d-89da-248c30eaf0e81-pending",
      "type": "debit",
      "amount": -255,
      "currency": "ZAR",
      "status": "Approved",
      "account_name": "Capitec-bank",
      "account_number": "123-123-123",
      "balance": {
        "amount": 12105,
        "currency": "ZAR",
        "type": "ClosingAvailable"
      },
      "date_time": 1774672448
    },
    {
      "external_transaction_id": "958d14298-91ee-405d-89da-248c30eaf0e81-pending",
      "type": "debit",
      "amount": -100,
      "currency": "ZAR",
      "status": "Approved",
      "account_name": "Capitec-bank",
      "account_number": "123-123-123",
      "balance": {
        "amount": 12005,
        "currency": "ZAR",
        "type": "ClosingAvailable"
      },
      "date_time": 1574672448
    }
    ]
}
```

### Get Spending patterns&#x20;

## Shows spending trends of a customer

<mark style="color:green;">`POST`</mark> `https://api.akibadigital.com/v1/spending`

#### Headers

| Name                                           | Type   | Description       |
| ---------------------------------------------- | ------ | ----------------- |
| Token<mark style="color:red;">\*</mark>        | String | Access auth Token |
| Content-Type<mark style="color:red;">\*</mark> | String | application/json  |

#### Request Body

| Name                                                  | Type   | Description                                            |
| ----------------------------------------------------- | ------ | ------------------------------------------------------ |
| customer\_reference<mark style="color:red;">\*</mark> | String | your custom reference of the customer i.e phone number |
| transactions<mark style="color:red;">\*</mark>        | Object | transaction object similar to example provided above   |
| customer\_type<mark style="color:red;">\*</mark>      | String | `1` for individual and `2` for business                |
| currency                                              | String |                                                        |

{% tabs %}
{% tab title="200: OK Successfully calculated affordability" %}

```javascript
{
  "income": {
    "currency": "ZAR",
    "number_of_salaries": "2",
    "possible_financial_distress_indicator": false,
    "out_of_work_benefit_indicator": false,
    "new_employer_indicator": false,
    "expected_salary": [
      {
        "amount": "12502.60",
        "expected_pay_date": "1608418799",
        "pay_frequency": "monthly"
      }
    ],
    "categories": [
      {
        "name": "Salary",
        "monthly_amounts": [
          {
            "amount": "12502.60",
            "year": "2021",
            "month": "3"
          }
        ]
      },
      {
        "name": "Other",
        "monthly_amounts": [
          {
            "amount": "2002.60",
            "year": "2021",
            "month": "3"
          }
        ]
      }
    ]
  },
  "spending": {
    "currency": "ZAR",
    "monthly_amounts": [
      {
        "percentage": "93%",
        "amount": "11309.43",
        "month": "3"
      }
    ],
    
  "spending_patterns": {
    "currency": "ZAR",
    
    "by_category": [
      {
        "category": "Groceries & Supplies",
        "min": "1845.03",
        "mean": "2008.32",
        "max": "2150.11",
        "frequency": "15.5",
        "recency": "3"
      },
      {
        "category": "Groceries & Supplies",
        "min": "1845.03",
        "mean": "2008.32",
        "max": "2150.11",
        "frequency": "15.5",
        "recency": "3"
      },
      {
        "category": "Groceries & Supplies",
        "min": "1845.03",
        "mean": "2008.32",
        "max": "2150.11",
        "frequency": "15.5",
        "recency": "3"
      }
    ]
  },
  "financial_markers": {
    
    "new_debt_indicator": false,
    "credit_repayments": {
      "rate_of_change": "0.66",
      "pred_next_month": "1022.35",
      "ratio_to_income": "0.17"
    },
    "currency": "ZAR",
    
    "negative_balance_ratio": 0.5,
    "debt_management_indicator": false,
    "debit_bank_transfer": {
      "rate_of_change": "0.66",
      "pred_next_month": "122.35",
      "ratio_to_income": "0.07"
    },
    "summary_averages": {
      "average_fixed_exp": 0.5,
      "average_flexible_exp": 0.5,
      "average_income": 0.5
    },
    "utility_payments": {
      
    "debits": {
      "rate_of_change": "0.66",
      "pred_next_month": "122.35",
      "ratio_to_income": "0.07"
    },
    "cash_withdrawals": {
      "rate_of_change": "0.66",
      "pred_next_month": "122.35",
      "ratio_to_income": "0.07"
    }
  }
}
```

{% endtab %}

{% tab title="401: Unauthorized Invalid/ Expired Auth Token" %}

```javascript
{
    // Response
}
```

{% endtab %}
{% endtabs %}
