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

# Pre-Approval

> Learn about how Pre-Approvals work with Drivly APIs.

## Overview

The Pre-Approval API is designed to revolutionize the vehicle financing process by enabling quick, efficient, and customer-friendly pre-approval for auto loans.

This API provides a seamless way to perform soft pulls on credit scores, offering customers and businesses a fast path to understanding financing options with no Social Securtity Number (SSN) requirements and no impact to credit scores.

***

## Making a Request

Submit a pre-approval to `https://commerce.driv.ly/api/preApprovals` with a `POST` request.

Below is a breakdown of the required and optional data fields, supplemented with example requests for your applications.

### Required Fields

Required fields must be provided with every request:

| Field           | Type   | Description                 | Format Example         |
| --------------- | ------ | --------------------------- | ---------------------- |
| `firstName`     | String | Customer's first name       | `John`                 |
| `middleInitial` | String | Customer's middle initial   | `A`                    |
| `lastName`      | String | Customer's last name        | `Doe`                  |
| `address`       | String | Customer's physical address | `123 Elm St`           |
| `city`          | String | City of the address         | `Springfield`          |
| `state`         | String | State of the address        | `IL`                   |
| `zip`           | String | Zip code of the address     | `62704`                |
| `phone`         | String | Customer's phone number     | `555-1234`             |
| `email`         | String | Customer's email address    | `john.doe@example.com` |

### Optional Fields

Optional fields can be included based on specific requirements:

| Field       | Type   | Description                                   | Format Example |
| ----------- | ------ | --------------------------------------------- | -------------- |
| `income`    | String | Customer's income monthly income              | `$15,000`      |
| `ipAddress` | String | IP address of the customer making the request | `192.168.1.1`  |
| `userAgent` | String | User agent of the customer’s browser          | `Mozilla/5.0`  |
| `isp`       | String | Internet Service Provider of the customer     | `Comcast`      |

### Fetch API Example

<CodeGroup>
  ```javascript Async/Await theme={null}
  export async function createPreApproval() {
    try {
      const response = await fetch('https://commerce.driv.ly/api/preApprovals', {
        method: 'POST',
        headers: {
          Authorization: '<api-key>',
          'Content-Type': 'application/json',
        },
        body: JSON.stringify({
          firstName: 'Danny',
          middleInitial: '',
          lastName: 'Turner',
          suffix: null,
          address: '241 Main St',
          city: 'Juno Beach',
          state: 'FL',
          zip: '33408',
          phone: '(561) 555-1234',
          email: 'dannyt@gmail.com',
          income: '$15,000',
        }),
      })

      if (!response.ok) {
        throw new Error(`HTTP error! status: ${response.status}`)
      }

      const responseData = await response.json()
      console.log('Pre-Approval Response:', responseData)
    } catch (error) {
      console.error('Error during the API request:', error)
    }
  }
  ```

  ```javascript Promises theme={null}
  fetch('https://commerce.driv.ly/api/preApprovals', {
    method: 'POST',
    headers: {
      Authorization: '<api-key>',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      firstName: 'Danny',
      middleInitial: '',
      lastName: 'Turner',
      suffix: null,
      address: '241 Main St',
      city: 'Juno Beach',
      state: 'FL',
      zip: '33408',
      phone: '(561) 555-1234',
      email: 'dannyt@gmail.com',
      income: '$15,000',
    }),
  })
    .then((response) => response.json())
    .then((data) => console.log(data))
    .catch((error) => console.error('Error:', error))
  ```
</CodeGroup>

This function `createPreApproval` sends the pre-approval data to the API endpoint using fetch with a
POST method.

It waits for the response asynchronously, converts the response to JSON, and logs it
to the console. If an error occurs during the request or while handling the response, it catches
the error and logs it, which is crucial for debugging and user feedback in real applications.

<Note>To execute the function, simply call `createPreApproval()` from your JavaScript code.</Note>

This example is meant to be a basic demonstration. In production, you might want to handle errors
more gracefully and provide user feedback based on the result of the API call.

***

## Successful Response

Upon successful submission, the API returns a response containing the following generated values:

| Field                   | Type   | Description                                                   | Example                |
| ----------------------- | ------ | ------------------------------------------------------------- | ---------------------- |
| `id`                    | String | Unique identifier for the pre-approval                        | `12345`                |
| `customer`              | String | Customer’s unique identifier                                  | `67890`                |
| `segmentationBand`      | String | Credit score band                                             | `Excellent (750-900)`  |
| `lead`                  | String | Unique identifier for the lead generated                      | `abc123`               |
| `status`                | Enum   | Current status of the pre-approval                            | `Processing`           |
| `estimatedInterestRate` | String | Estimated interest rate for the loan (percentage)             | `3.5%`                 |
| `estimatedLoanTerm`     | String | Estimated term for the loan (months)                          | `60 mo`                |
| `updatedAt`             | String | Timestamp of the last update (ISO 8601 format)                | `2022-01-01T12:00:00Z` |
| `createdAt`             | String | Timestamp when the pre-approval was created (ISO 8601 format) | `2022-01-01T00:00:00Z` |

The response will contain the same values as the request, along with the generated values. The
response will also include the status of the pre-approval, which can be used to track the progress
of the request.

The status will be one of the following: `Processing`, `Error`, `Processed`, `Needs Info`.

```json Example Response theme={null}
{
  "id": "12034631b86bb45g202071a1",
  "title": "Danny Turner (dannyt@gmail.com)",
  "firstName": "Danny",
  "middleInitial": "",
  "lastName": "Turner",
  "suffix": null,
  "address": "241 Main St",
  "city": "Juno Beach",
  "state": "FL",
  "zip": "33408",
  "phone": "+15615551234",
  "email": "dannyt@gmail.com",
  "sessionId": "",
  "createdAt": "2024-03-26T22:03:29.685Z",
  "updatedAt": "2024-03-26T22:04:01.175Z",
  "status": "Processed",
  "income": "$15,000",
  "AppId": 154422063,
  "customer": "12ab3d1241567b12d2ga12c1",
  "segmentationBand": "Good (700-749)"
}
```

***

## Next Steps

Now that you have a better understanding of how the Pre-Approval API works, you can start integrating it into your application.

<CardGroup cols={2}>
  <Card title="Pre-Approval Guide" icon="landmark" href="/services/guides/pre-approval">
    Getting Started with Pre-Approvals
  </Card>

  <Card icon="book" href="/services/reference/pre-approval" title="Pre-Approval API Reference">
    Explore the Pre-Approval API
  </Card>
</CardGroup>
