Access to Tesla fleet API is via the OAuth 2.0 authorization type. For ERPAG to be able to communicate with Tesla’s API, it is necessary to set up such access.

You will set this up in the Automatization/Customization menu, under option API Authorizations.

When you add a new type of authorization, the newly opened screen seems quite complicated. Luckily, we added a Wizard in ERPAG which fills in all required data based on two parameters.

Enter “Client ID” and “Client secret”.

You will get these data from the portal API service. In Tesla’s case, it’s https://developer.tesla.com.
Tesla developer
This Tesla link is general guidelines on how to give developer access to their API:
https://developer.tesla.com/docs
It is explained in detail there, to simplify, we will explain the process in detail.
The first thing you should have is a Tesla account (it needs to be two-factor verification). Next is the request for API access.

It’s a wizard-type data entry, where you enter data on each step.


Now it’s required to add a fixed URL, for safety reasons. This way you allow ERPAG the first-level access to Tesla Fleet API.

The data that you will enter are:
Allowed Origin URL
https://app.erpag.comand Allowed Redirect URL (this is the URL to which they will send access token after API authorization)
https://app.erpag.com/oauth2.aspxThe next step is “API Scopes”. Which means which data we can access through the API service.

After sending the request, it is necessary to wait some time for the request approval.
Note: From our experience, we can say that depending on the required scope, approval can take from a few minutes to 24 hours.
Once it’s approved, additionally you will see the “Active” status on the dashboard, i.e. “tiles” of our applications.
On details, we will see Client ID and Client Secret.

Working in ERPAG
Now we can copy/paste in ERPAG wizard Tesla type.

Now ERPAG wizard completed all necessary data.
In case of a scope deviation, it is necessary to also check the scope that ERPAG sends to the Tesla API when requesting access.

After entering, it is necessary to make a connection to the API. ie Get an Access Token.

By activating this option, the browser will load the Tesla page where you enter the Tesla login credentials.
If the authorization is successful, the status will be “Authorized”.

In fact, there is another test option. It’s a simple query request to API service.

In our example, we will enter the following URL:
https://fleet-api.prd.na.vn.cloud.tesla.com/api/1/dx/charging/historyNote: The URL for the Tesla fleet API is divided by region. If the above link doesn’t work, you have to select the appropriate one for your region. You can find more information on the Tesla developer site: https://developer.tesla.com/docs/fleet-api?shell#setup
By receiving a JSON in the response, it’s a confirmation that we are successfully connected to the API service.

Using in ERPAG
You can use the set API authorization in ERPAG Smart API through blocks in Blockly scripts (eg BOT script).

We simply select the name of our authorization in the API blocks.


Recent Comments