Testing with Postman
In this guide we’ll go over how to use Vehicle Simulator to test out Smartcar using Postman.
What is Postman?
Postman is a collaboration platform for API development. Postman’s features simplify each step of building an API and streamline collaboration so you can create better APIs - faster. You’ll need a few things to start making API calls with Smartcar and Postman:
Configuring the Connect flow in Postman
- Install the latest Postman app and log in
- Import the Smartcar collection into your local Postman workspace. Hit Import.
- Click Link, paste in the link to the collection and hit Continue.
- On the next screen, hit Import.
Smartcar Application Configuration
If you haven’t already signed up for a Smartcar Developer account, you can do so from this signup link.
- Grab your Client ID and Client Secret from the Configuration page after you sign in, and copy them to someplace secure. You’ll need those tokens a little later in this setup.
- Under the Credentials tab for your application, you’ll need to add the following Redirect URIs. This will ensure that Smartcar Connect exits successfully with both Postman’s Native and Web clients.
Through the Connect flow, you’re able to get consent from vehicle owners to connect their vehicle to your application. Postman provides an easy way to manage oAuth 2.0 flows under the Authorization tab of a Collection. Set up the Configuration Options for either a live or simulated vehicle.
Live Vehicle
Parameter | Description |
---|---|
Auth URL | https://connect.smartcar.com/oauth/authorize?approval_prompt=force |
Access Token URL | https://auth.smartcar.com/oauth/token |
Client ID | client_id from your Dashboard |
Client Secret | client_secret from your Dashboard |
Scope | A space-separated list of permissions that your application is requesting access to |
Simulated Vehicle
Parameter | Description |
---|---|
Auth URL | https://connect.smartcar.com/oauth/authorize?approval_prompt=force&mode=simulated |
Access Token URL | https://auth.smartcar.com/oauth/token |
Client ID | client_id from your Dashboard |
Client Secret | client_secret from your Dashboard |
Scope | A space-separated list of permissions that your application is requesting access to |
Setting up a Simulated Vehicle
Under the Simulator tab on Dashboard, hit Add Vehicle. Note that you may already have a pre-created simulated vehicle available, if so skip to Connecting to a vehicle below.
Select a region and MMY for your vehicle, then hit Search by MMY
After selecting Use Vehicle, you’ll want to select a state for the vehicle. After that, you’ll get a set of credentials to use in the Connect flow.
Before proceeding to the next step, you’ll want to start the simulation in the Smartcar Dashboard.
Connecting to a vehicle
If configured correctly, when you click Get New Access Token in Postman, you should see the first screen of the Connect flow.
Before hitting Continue, make sure to select a country from the dropdown appropriate to the region you selected for your simulated vehicle.
Continue through the Connect flow, select the brand of your simulated vehicle and enter in the credentials you were issued for your simulated vehicle. After accepting the permissions you’ll be met with the following screen:
Hit Use Token. You should see Access Token under Current Token populate with the access_token from the popup. Using this access_token you can make API requests to Smartcar’s API.
Access tokens are only valid for two hours. If you want to make API requests after it has expired, you’ll need to generate a new one by stepping through the Connect Flow again, or through a token refresh.
Making an API request
Thanks to Postman, requests in the collection will inherit the access_token
from the OAuth 2.0 Authorization flow we went through in the steps above.
In order to make API requests, we’ll need to first get a Smartcar vehicle Id
. A vehicle Id
is a unique identifier for a vehicle on Smartcar’s platform.
This can be done with the All Vehicles
request. Making this request will assign the vehicle Id
to the {{vehicle_id}}
variable for other requests in the Collection.
Now that you’ve got a vehicle Id, you can make a request to other endpoints. Hitting Vehicle Info, we can see the MMY of the vehicle.
Checking EV Battery Level
, we can see the response matches the vehicle state on the simulator
Troubleshooting
Was this page helpful?