> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fincode.technology/llms.txt
> Use this file to discover all available pages before exploring further.

# Loan History

> Retrieves a paginated history of all loans for a customer, including active, completed, and cancelled loans.

Fetches a comprehensive, paginated history of all loans associated with a customer, providing detailed information about each loan's status, amounts, and timeline.

## Request Headers

<ParamField header="X-Auth-Token" type="string" required>
  The **JWT Access Token** obtained from the `/login` or `/refresh-token` endpoint.
</ParamField>

<ParamField header="x-idempotency-key" type="string" required>
  Unique idempotency key for the request to prevent duplicate processing.
</ParamField>

<ParamField header="x-fapi-auth-date" type="string" required>
  The date and time at which the request was initiated (ISO 8601 format).
</ParamField>

<ParamField header="x-fapi-customer-ip-address" type="string" required>
  The IP address of the customer making the request.
</ParamField>

<ParamField header="x-fapi-interaction-id" type="string" required>
  Unique identifier for the interaction/session.
</ParamField>

## Path Parameters

<ParamField path="customerId" type="string" required>
  The unique identifier (UUID) of the customer whose loan history to retrieve.
</ParamField>

## Query Parameters

<ParamField query="page" type="number" default="1">
  Page number for pagination (starts from 1).
</ParamField>

<ParamField query="size" type="number" default="10">
  Number of items per page (maximum recommended: 50).
</ParamField>

## Code Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl --location 'https://finlend.fincode.software/api/v1/services/user/loan-history/123e4567-e89b-12d3-a456-426614174000?page=1&size=10' \
  --header 'X-Auth-Token: YOUR_JWT_ACCESS_TOKEN' \
  --header 'x-idempotency-key: unique-key-12345' \
  --header 'x-fapi-auth-date: 2024-01-15T10:30:00Z' \
  --header 'x-fapi-customer-ip-address: 192.168.1.1' \
  --header 'x-fapi-interaction-id: interaction-12345'
  ```

  ```javascript Node.js theme={null}
  const axios = require('axios');

  const BASE_URL = 'https://finlend.fincode.software/api/v1/services/user';

  async function getCustomerLoanHistory(accessToken, customerId, page = 1, size = 10) {
    try {
      const response = await axios.get(
        `${BASE_URL}/loan-history/${customerId}`,
        {
          params: {
            page,
            size,
          },
          headers: {
            'X-Auth-Token': accessToken,
            'x-idempotency-key': `key-${Date.now()}`,
            'x-fapi-auth-date': new Date().toISOString(),
            'x-fapi-customer-ip-address': '192.168.1.1',
            'x-fapi-interaction-id': `interaction-${Date.now()}`,
          },
        }
      );

      loans.forEach((loan) => {
        console.log(
          `- ${loan.loanApplicationId}: ${loan.loanProductName} - ` +
          `${loan.loanAmount} (Status: ${loan.status})`
        );
      });

      return history;
    } catch (error) {
      console.error(
        'Failed to fetch customer loan history:',
        error.response?.data || error.message
      );
      throw error;
    }
  }

  ```
</CodeGroup>


## OpenAPI

````yaml GET /user/get-loan-history/{customerId}
openapi: 3.0.0
info:
  title: FinCode API
  version: v6
servers:
  - url: https://{tenant}.fincode.software/api/v6/services
    description: API v6
    variables:
      tenant:
        default: remitjunction
        description: Enter your tenant subdomain
  - url: https://{tenant}.fincode.software/api/v1/services
    description: API v1
    variables:
      tenant:
        default: finlend
        description: Enter your tenant subdomain
  - url: https://api.stag.songhaiexchange.io
    description: Songhai Exchange API
security: []
paths:
  /user/get-loan-history/{customerId}:
    get:
      tags:
        - Lending
      summary: Loan History
      description: Retrieves a paginated history of all loans for a customer.
      parameters:
        - name: customerId
          in: path
          required: true
          schema:
            type: string
        - name: page
          in: query
          schema:
            type: integer
            default: 1
        - name: size
          in: query
          schema:
            type: integer
            default: 10
      responses:
        '200':
          description: Loan history retrieved successfully
      servers:
        - url: https://{tenant}.fincode.software/api/v1/services
          variables:
            tenant:
              default: finlend

````