> ## 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.

# Update Loan Offer

> Allows customers to accept or withdraw from a loan offer that has been sent to them.

Customers can use this endpoint to respond to a loan offer. If the offer is accepted, the application status changes to `ACCEPTED`. If withdrawn, the status changes to `WITHDRAWN`.

<Note>
  This endpoint can only be used when the loan application status is `OFFER_SENT`. Attempting to use it with any other status will result in an error.
</Note>

<RequestExample>
  ```bash cURL PUT theme={null}
  [https://finlend.fincode.software/api/v1/services/user/update-application/{loan-application-id}?status=true](https://finlend.fincode.software/api/v1/services/user/update-application/{loan-application-id}?status=true)
  ```
</RequestExample>

## 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="loan-application-id" type="string" required>
  The unique identifier (UUID) of the loan application to update.
</ParamField>

## Query Parameters

<ParamField query="status" type="boolean" required>
  * `true`: Accept the loan offer (status changes to `ACCEPTED`)
  * `false`: Withdraw from the loan offer (status changes to `WITHDRAWN`)
</ParamField>

## Response

Returns the updated loan application details.

<ResponseField name="status" type="string" default="SUCCESS">
  Overall status of the API request.
</ResponseField>

<ResponseField name="data" type="object">
  Updated loan application details.

  <Expandable title="data object">
    <ResponseField name="applicationId" type="string">
      Unique identifier of the loan application.
    </ResponseField>

    <ResponseField name="loanProductId" type="string">
      Identifier of the loan product.
    </ResponseField>

    <ResponseField name="userName" type="string">
      Name of the customer.
    </ResponseField>

    <ResponseField name="productName" type="string">
      Name of the loan product.
    </ResponseField>

    <ResponseField name="currencyCode" type="string">
      Currency code.
    </ResponseField>

    <ResponseField name="employmentStatus" type="string">
      Employment status of the customer.
    </ResponseField>

    <ResponseField name="loanApplicationcreatedDate" type="string">
      Date when the loan application was created.
    </ResponseField>

    <ResponseField name="userId" type="string">
      Unique identifier of the user.
    </ResponseField>

    <ResponseField name="durationCounterUnitEnum" type="string">
      Duration counter unit (e.g., `MONTH`, `WEEK`, `DAY`).
    </ResponseField>

    <ResponseField name="requestedLoanAmount" type="number">
      Requested loan amount.
    </ResponseField>

    <ResponseField name="loanStatus" type="string">
      Updated loan application status (`ACCEPTED` or `WITHDRAWN`).
    </ResponseField>

    <ResponseField name="monthlyIncome" type="number">
      Customer's monthly income.
    </ResponseField>

    <ResponseField name="dateOfBirth" type="string">
      Customer's date of birth.
    </ResponseField>

    <ResponseField name="loanDuration" type="number">
      Loan duration.
    </ResponseField>
  </Expandable>
</ResponseField>

## Code Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl --location --request PUT 'https://finlend.fincode.software/api/v1/services/user/update-application/123e4567-e89b-12d3-a456-426614174000?status=true' \
  --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 updateLoanApplicationOffer(accessToken, loanApplicationId, acceptOffer) {
    try {
      const response = await axios.put(
        `${BASE_URL}/update-application/${loanApplicationId}`,
        null,
        {
          params: {
            status: acceptOffer,
          },
          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()}`,
          },
        }
      );

      console.log('Loan offer updated:', response.data.data);
      return response.data.data;
    } catch (error) {
      console.error(
        'Failed to update loan offer:',
        error.response?.data || error.message
      );
      throw error;
    }
  }

  // Usage Example - Accept offer
  const accessToken = 'YOUR_JWT_ACCESS_TOKEN';
  const loanApplicationId = '123e4567-e89b-12d3-a456-426614174000';
  updateLoanApplicationOffer(accessToken, loanApplicationId, true);

  // Usage Example - Withdraw from offer
  updateLoanApplicationOffer(accessToken, loanApplicationId, false);
  ```
</CodeGroup>
