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

# Preventive maintenance scheduling

> This guide explains how to use the Smartcar API to proactively automate preventive maintenance scheduling. By leveraging data such as odometer readings, engine oil life, Diagnostic Trouble Codes (DTCs), and system status, you can reduce vehicle downtime, improve reliability, and enhance customer satisfaction.

## Prerequisites: Creating Your Application

Before implementing preventive maintenance capabilities 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 Preventive Maintenance

Use the following endpoints to build your preventive maintenance solution:

### 1. Track Odometer Readings

Retrieve odometer data to schedule maintenance services such as tire rotations or oil changes based on mileage.

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

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

**Use Case**
Send a notification when a vehicle’s odometer reading reaches maintenance intervals, such as every 5,000 miles.<br />

### 2. Monitor Engine Oil Life

Retrieve oil life data to prompt users when an oil change is due.

```bash Engine Oil Life theme={null}
curl "https://api.smartcar.com/v2.0/vehicles/{id}/engine/oil" \
    -H "Authorization: Bearer {token}" \
    -X "GET"
```

```json Example Response theme={null}
{
  "lifeRemaining": 0.35
}
```

**Use Case**
Trigger a service reminder when oil life falls below 20% to prevent engine damage.<br />

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

DTCs help you identify and diagnose specific vehicle issues, allowing for quick and accurate repairs.

```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"
      }
    ]
}
```

**Use Case**
Notify a driver immediately if a new trouble code is detected, enabling faster
response times.<br />

### 4. Monitor Vehicle System Status

Retrieve a snapshot of key systems like the engine and battery to assess health
and detect anomalies.

```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": [
          {
              "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
          },
      ]
}
```

**Use Case**
Notify users or fleet operators if the engine status changes to warning or the battery health declines.

## Webhooks for Preventive Maintenance

Webhooks enable real-time notifications for certain vehicle events, reducing the
need for polling. Examples include:

* **DTC Updates**: Receive a webhook when a new trouble code is logged.
* **System Changes**: Get updates for changes in engine or battery status.

### Setting Up Webhooks

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>

### Example Workflow

1. **Authorization**: The user logs in via Smartcar Connect to grant access to
   vehicle data.
2. **Monitoring**: Your backend polls GET endpoints (e.g., odometer, oil, system
   status) or listens for webhook events.
3. **Threshold Detection**: Evaluate data (e.g., oil life \< 20%, mileage > 5,000
   miles) and identify DTCs or system warnings.
4. **Notifications**: Send push notifications, emails, or SMS to users with
   maintenance reminders or alerts.
5. **Ongoing Updates**: Combine periodic polling and webhooks to ensure vehicles stay road-ready.

## FAQs

<AccordionGroup>
  <Accordion title="Do all vehicles support these endpoints">
    No. Data availability depends on the OEM, model, and year. Check the
    [Compatible Vehicles](https://smartcar.com/product/compatible-vehicles)
    page for details.
  </Accordion>

  <Accordion title="Can I use webhooks for real-time updates?">
    Yes, webhooks can be used for supported events such as DTC updates or
    system status changes.
  </Accordion>
</AccordionGroup>
