lsiddiquee / bmw-connected-drive

15 stars 4 forks source link

API changed #14

Closed evilworm closed 1 year ago

evilworm commented 1 year ago

Seems like bmw api has changed and the library does not work anymore (throws 404 resource not found). Did a quick glance at python lib and found that vehicle status url changed from /eadrax-vcs/v2/vehicles to /eadrax-vcs/v4/vehicles. Also for VIN status query you now need to call /eadrax-vcs/v4/vehicles/status and pass "bmw-vin" header.

This is a quick hack with "npx patch-package bmw-connected-drive" and should get "getVehicles" and "getVehicleStatus" working...

index 7cdeaad..fe20694 100644
--- a/node_modules/bmw-connected-drive/dist/ConnectedDrive.js
+++ b/node_modules/bmw-connected-drive/dist/ConnectedDrive.js
@@ -10,7 +10,7 @@ const uuid_1 = require("uuid");
 class ConnectedDrive {
     constructor(username, password, region, tokenStore, logger) {
         this.serviceExecutionStatusCheckInterval = 5000;
-        this.account = new Account_1.Account(username, password, region, tokenStore);
+        this.account = new Account_1.Account(username, password, region, tokenStore, logger);
         this.logger = logger;
     }
     async getVehicles() {
@@ -24,8 +24,8 @@ class ConnectedDrive {
         var _a;
         (_a = this.logger) === null || _a === void 0 ? void 0 : _a.LogInformation("Getting vehicle status.");
         const params = `apptimezone=${120}&appDateTime=${Date.now()}&tireGuardMode=ENABLED`;
-        const url = `https://${Constants_1.Constants.ServerEndpoints[this.account.region]}${Constants_1.Constants.getVehicles}/${vin}/state?${params}`;
-        return (await this.request(url)).state;
+        const url = `https://${Constants_1.Constants.ServerEndpoints[this.account.region]}${Constants_1.Constants.getVehiclesState}?${params}`;
+        return (await this.request(url, undefined, undefined, vin)).state;
     }
     async getVehicleCapabilities(vin) {
         var _a;
@@ -89,7 +89,7 @@ class ConnectedDrive {
         const requestBody = { "vins": [vin], "message": message, "subject": subject };
         return ((_a = (await this.request(url, true, requestBody))) === null || _a === void 0 ? void 0 : _a.status) === "OK";
     }
-    async request(url, isPost = false, requestBody) {
+    async request(url, isPost = false, requestBody, vin) {
         var _a, _b;
         const correlationId = (0, uuid_1.v4)();
         const httpMethod = isPost ? "POST" : "GET";
@@ -106,6 +106,11 @@ class ConnectedDrive {
             "x-correlation-id": correlationId,
             "bmw-correlation-id": correlationId
         };
+        if(vin) {
+            Object.assign(headers, {
+                "bmw-vin": vin
+            });
+        }
         if (requestBodyContent) {
             headers.Accept = "application/json;charset=utf-8";
         }
diff --git a/node_modules/bmw-connected-drive/dist/Constants.js b/node_modules/bmw-connected-drive/dist/Constants.js
index a1682a6..6f3fdb5 100644
--- a/node_modules/bmw-connected-drive/dist/Constants.js
+++ b/node_modules/bmw-connected-drive/dist/Constants.js
@@ -14,14 +14,15 @@ Constants.OAuthAuthorizationKey = {
     RestOfWorld: "4f1c85a3-758f-a37d-bbb6-f8704494acfa",
     China: "blF2NkNxdHhKdVhXUDc0eGYzQ0p3VUVQOjF6REh4NnVuNGNEanliTEVOTjNreWZ1bVgya0VZaWdXUGNRcGR2RFJwSUJrN3JPSg=="
 };
-Constants.User_Agent = "Dart/2.14 (dart:io)";
+Constants.User_Agent = "Dart/2.18 (dart:io)";
 Constants.X_User_Agent = {
     NorthAmerica: "android(SP1A.210812.016.C1);bmw;2.5.2(14945);na",
-    RestOfWorld: "android(SP1A.210812.016.C1);bmw;2.5.2(14945);row",
+    RestOfWorld: "android(TQ2A.230405.003.B2);bmw;3.3.1(22418);row",
     China: "android(SP1A.210812.016.C1);bmw;2.3.0(13603);cn"
 };
-Constants.getVehicles = "/eadrax-vcs/v2/vehicles";
-Constants.remoteServicesBaseUrl = "/eadrax-vrccs/v2/presentation/remote-commands";
+Constants.getVehicles = "/eadrax-vcs/v4/vehicles";
+Constants.getVehiclesState = "/eadrax-vcs/v4/vehicles/state";
+Constants.remoteServicesBaseUrl = "/eadrax-vrccs/v3/presentation/remote-commands";
 Constants.executeRemoteServices = Constants.remoteServicesBaseUrl + "/{vehicleVin}/{serviceType}";
 Constants.statusRemoteServices = Constants.remoteServicesBaseUrl + "/eventStatus?eventId={eventId}";
 Constants.statusRemoteServicePostion = Constants.remoteServicesBaseUrl + "/eventPosition?eventId={eventId}";
lsiddiquee commented 1 year ago

@evilworm Thanks for reporting this. For some reason i was not getting any notification on from github. I was as well a but busy with our new born. I will hopefully push a fix this week or next week latest.

lsiddiquee commented 1 year ago

PR has been merged new version has been pushed to NPM