What You’ll Achieve
- Set up database tables to store vehicles, users, and tokens
- Create backend endpoints to handle OAuth and webhooks
- Understand the data flow between Smartcar and your backend
1
Step 1: Plan Your Database Tables
You’ll need tables to track users, vehicles, and Smartcar tokens. Here’s a recommended schema:
| Table | Purpose | Key Fields |
|---|---|---|
users | You probably already have this table to store your app’s users | id, email, name, etc. |
smartcar_tokens | Stores Smartcar access and refresh tokens pairs with user and vehicle IDs | id, your_app_user_id, smartcar_vehicle_id, smartcar_access_token, smartcar_refresh_token, expires_at, created_at, updated_at |
vehicles | Stores connected vehicle information | id, smartcar_user_id, your_app_user_id, make, model, year, created_at, updated_at |
vehicle_data | Stores data about your vehicles (i.e. odometer readings, location, etc.) | id, smartcar_vehicle_id, created_at, data_type, data_value |
webhook_logs | Log incoming webhook events (optional) | id, smartcar_vehicle_id, event_type, payload, received_at |
Always encrypt tokens at rest and never expose them to the client.
2
Step 2: Implement OAuth Code Exchange Endpoint
Create a backend endpoint to handle the OAuth redirect from Smartcar and exchange the authorization code for tokens.Example:
/api/smartcar/callback- Receive the
codeandstatequery parameters from Smartcar. - Exchange the code for tokens using Smartcar’s token endpoint.
- Store the tokens in your
tokenstable, linked to the user and vehicle.
3
Step 3: Create a Webhook Receiver Endpoint
Set up an endpoint to receive webhook POST requests from Smartcar.Example:
/api/webhooks/smartcar- Validate the webhook signature (see Smartcar webhook docs).
- Parse the event payload and update your database as needed.
- Log the event in
webhook_logsfor auditing and debugging.
4
Step 4: Secure Your Endpoints
- Restrict access to OAuth and webhook endpoints.
- Use HTTPS for all traffic.
- Never expose access or refresh tokens to the frontend.

