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

# Drive revenue with real-time diagnostics

> This guide explains how to use the Smartcar API to provide real-time vehicle diagnostics by leveraging data such as Diagnostic Trouble Codes (DTCs), overall system health, and odometer readings. These capabilities allow developers and service providers to proactively identify issues, schedule service visits, and reduce vehicle downtime.

## Prerequisites: Creating Your Application

Before implementing the Smartcar API for real-time vehicle diagnostics, ensure
you have:

* Created a Smartcar account and registered your application to obtain your
  `client_id` and `client_secret`.
* Set up the Smartcar Connect flow to authenticate and authorize users.

<Tip>
  For more details, refer to the [Getting Started Guide](https://smartcar.com/docs/getting-started/).
</Tip>

## Smartcar API Endpoints for Vehicle Diagnostics

Use the following Smartcar API endpoints (and optionally, webhooks) to pinpoint
issues, check vehicle health, and keep track of maintenance schedules based on
odometer data.

* [GET DTCs](/api-reference/get-dtcs)
* [GET System Status](/api-reference/get-system-status)
* [GET Odometer](/api-reference/get-odometer)

### 1. Retrieve Diagnostic Trouble Codes (DTCs)

Once a vehicle is authorized via Smartcar’s Connect flow, you can use the
vehicle’s access token to retrieve DTCs from the following endpoint:

```bash DTCs theme={null}
curl "https://api.smartcar.com/v2.0/vehicles/{vehicleId}/diagnostics/dtcs" \
   -H "Authorization: Bearer {token}" \
   -X "GET"
```

```json Example Response theme={null}
{
    "activeCodes": [
        {
            "code": "P302D",
            "timestamp": "2024-09-05T14:48:00.000Z"
        },
        {
            "code": "xxxxx",
            "timestamp": null
        },

        ... 
    ]
}
```

* **DTCs:** Provide specific error codes and descriptions of active faults for faster troubleshooting.
* **Service Scheduling:** Automate scheduling or send push notifications to alert customers of potential issues.

### 2. Monitor Vehicle Health

Stay informed of the overall vehicle condition by using the system status
endpoint to retrieve real-time data about critical components like engine
and battery.

```bash System Status theme={null}
curl "https://api.smartcar.com/v2.0/vehicles/{vehicleId}/system_status" \
    -H "Authorization: Bearer {token}" \
    -X "GET"
```

```json Example Response theme={null}
{
      "systems": [
          {
              // System ID from Smartcar unified system definition list
              "systemId": "SYSTEM_TPMS",
              "status": "ALERT",
              "description": "Left rear tire sensor battery low"
          },
          {
              "systemId": "SYSTEM_AIRBAG",
              "status": "OK",
              "description": null
          },
          {
              "systemId": "SYSTEM_MIL",
              "status": "OK",
              "description": null
          },
          ...
      ]
}
```

* **Engine Status:** Detect early signs of malfunction (e.g., overheating, low oil pressure).
* **Battery Health:** Monitor battery voltage, proactively suggesting replacements or checks.

### 3. Track Odometer Readings

Use the odometer endpoint to maintain timely service intervals (oil changes,
inspections, etc.) based on the actual mileage driven.

```bash Odometer theme={null}
curl "https://api.smartcar.com/v2.0/vehicles/{vehicleId}/odometer" \
    -H "Authorization: Bearer {token}" \
    -X "GET"
```

```json Example Response theme={null}
{
    "distance": 104.32
}
```

* **Maintenance Scheduling:** Automatically notify drivers or fleet managers when mileage thresholds are reached.
* **Fleet Management:** Consolidate odometer data across multiple vehicles to streamline service for an entire fleet.

## Webhooks (Optional)

To receive real-time notifications (e.g., when new DTCs appear), consider
setting up webhooks:

1. **Create a Webhook:** Configure a secure endpoint on your server to handle POST
   requests from Smartcar.
2. **Register the Webhook:** Specify which events (such as DTC) you want to
   subscribe to.
3. **Instant Alerts:** When an event triggers, Smartcar sends a payload to your endpoint, enabling immediate responses (like sending notifications or scheduling service).

<Tip>
  See the [Smartcar Webhooks Documentation](/getting-started/tutorials/webhooks-diagnostic) for more information.
</Tip>

## Putting It All Together

1. Retrieve DTCs: Quickly detect and diagnose specific issues.
2. Monitor Vehicle Health: Stay current on engine, battery, and other key
   systems.
3. Track Odometer: Automate maintenance scheduling based on real-time mileage.
4. Use Webhooks (Optional): Get instant notifications to further reduce
   downtime.
   By combining these capabilities, you can deliver proactive and data-driven services—leading to fewer unexpected breakdowns, optimized service operations, and higher customer satisfaction.

## FAQs

<AccordionGroup>
  <Accordion title="Does this use case require regular polling or scheduled polling?">
    You can set up periodic polling to check for new DTCs or system
    changes—alternatively, leverage webhooks for real-time alerts when new
    diagnostic codes appear or mileage passes certain thresholds
  </Accordion>

  <Accordion title="What additional data sources are needed besides the Smartcar API?">
    Core diagnostic data is available directly from Smartcar. For
    comprehensive service management, you may integrate a CRM or maintenance
    scheduling system. However, no extra vehicle hardware is needed.
  </Accordion>

  <Accordion title="Is the Smartcar API vehicle-make agnostic?">
    Yes, The Smartcar platform provides a unified interface to access vehicle data across
    multiple makes and models, allowing developers to build applications that
    work with a wide range of vehicles without needing to handle make-specific
    differences.
  </Accordion>
</AccordionGroup>
