Tesla-API SDK
npm install tesla-api-sdkUnofficial OpenAPI specification for Tesla Fleet Management Charging endpoints.
Run the following command from your project directory to install the package from npm:
``bash`
npm install tesla-api-sdk@1.0.4
For additional package details, see the Npm page for the tesla-api-sdk@1.0.4 npm.
_Note:_ Documentation for the client can be found here.
The following parameters are configurable for the API Client:
| Parameter | Type | Description |
| --- | --- | --- |
| environment | Environment | The API environment. Environment.Production
Default: |number
| timeout | | Timeout for API calls.0
Default: |Partial
| httpClientOptions | | Stable configurable http client options. |any
| unstableHttpClientOptions | | Unstable configurable http client options. |PartialLoggingOptions
| logging | | Logging Configuration to enable logging |BearerAuthCredentials
| bearerAuthCredentials | | The credential object for bearerAuth |ThirdpartytokenCredentials
| thirdpartytokenCredentials | | The credential object for thirdpartytoken |
The API client can be initialized as follows:
`ts
import {
Client,
Environment,
LogLevel,
OAuthScopeThirdpartytoken,
} from 'tesla-api-sdk';
const client = new Client({
bearerAuthCredentials: {
accessToken: 'AccessToken'
},
thirdpartytokenCredentials: {
oAuthClientId: 'OAuthClientId',
oAuthClientSecret: 'OAuthClientSecret',
oAuthRedirectUri: 'OAuthRedirectUri',
oAuthScopes: [
OAuthScopeThirdpartytoken.Openid,
OAuthScopeThirdpartytoken.OfflineAccess
]
},
timeout: 0,
environment: Environment.Production,
logging: {
logLevel: LogLevel.Info,
logRequest: {
logBody: true
},
logResponse: {
logHeaders: true
}
},
});
`
`ts
import * as path from 'path';
import * as fs from 'fs';
import { Client } from 'tesla-api-sdk';
// Provide absolute path for the configuration file
const absolutePath = path.resolve('./config.json');
// Read the configuration file content
const fileContent = fs.readFileSync(absolutePath, 'utf-8');
// Initialize client from JSON configuration content
const client = Client.fromJsonConfig(fileContent);
`
See the Configuration-Based Client Initialization section for details.
`ts
import * as dotenv from 'dotenv';
import * as path from 'path';
import * as fs from 'fs';
import { Client } from 'tesla-api-sdk';
// Optional - Provide absolute path for the .env file
const absolutePath = path.resolve('./.env');
if (fs.existsSync(absolutePath)) {
// Load environment variables from .env file
dotenv.config({ path: absolutePath, override: true });
}
// Initialize client using environment variables
const client = Client.fromEnvironment(process.env);
`
See the Environment-Based Client Initialization section for details.
This API uses the following authentication schemes.
* bearerAuth (OAuth 2 Bearer token)
* thirdpartytoken (OAuth 2 Authorization Code Grant)`
* Vehicle Commands
* Charging
* Energy
* Partner
* User
* Vehicles
* HttpClientOptions
* RetryConfiguration
* ProxySettings
* Configuration-Based Client Initialization
* Environment-Based Client Initialization
* PartialLoggingOptions
* PartialRequestLoggingOptions
* PartialResponseLoggingOptions
* LoggerInterface