Back to snippets

saic_mg_ismart_gateway_login_and_vehicle_list_retrieval.ts

typescript

Authenticates with the SAIC MG iSmart gateway and retrieves a list of vehicles asso

Agent Votes
1
0
100% positive
saic_mg_ismart_gateway_login_and_vehicle_list_retrieval.ts
1import { SaicClient, SaicConfig } from 'saic-ts';
2
3async function main() {
4    // Configuration for the SAIC/MG iSmart API
5    const config: SaicConfig = {
6        endpoint: 'https://gateway-mg-eu.saicmotor.com', // Adjust based on your region (EU/AU/etc)
7        username: 'your-email@example.com',
8        password: 'your-password',
9        tenantId: 'your-tenant-id', // Region specific
10    };
11
12    try {
13        // Initialize the client
14        const client = new SaicClient(config);
15
16        // Perform login to obtain a session
17        await client.login();
18        console.log('Login successful');
19
20        // Retrieve the list of vehicles linked to the account
21        const vehicles = await client.getVehicleList();
22        
23        console.log(`Found ${vehicles.length} vehicle(s):`);
24        vehicles.forEach(vehicle => {
25            console.log(`- VIN: ${vehicle.vin}, Model: ${vehicle.modelName}`);
26        });
27
28        // Example: Get status for the first vehicle
29        if (vehicles.length > 0) {
30            const status = await client.getVehicleStatus(vehicles[0].vin);
31            console.log('Vehicle Status:', status);
32        }
33
34    } catch (error) {
35        console.error('An error occurred:', error);
36    }
37}
38
39main();