G-Two / homeassistant-subaru

Subaru STARLINK custom component for Home Assistant.
Apache License 2.0
54 stars 6 forks source link

ERROR: Unable to communicate with Subaru API #95

Closed JPorter-02 closed 10 months ago

JPorter-02 commented 10 months ago

It appears the HACS integration is having trouble connecting to the Subaru API. I will include the error below. Only thing the HA UI says is "Failed to connect". I have tried both the main branch and the pre-commit with no change in behavior. Let me know if any additional info is needed

This error originated from a custom integration.

Logger: custom_components.subaru.config_flow Source: custom_components/subaru/config_flow.py:63 Integration: Subaru (documentation, issues) First occurred: 1:19:30 PM (4 occurrences) Last logged: 1:35:19 PM

Unable to communicate with Subaru API: HTTP 500: {"httpCode":500,"errorCode":"error","errorMessage":"java.lang.ArrayIndexOutOfBoundsException - null"} RequestInfo(url=URL('https://mobileapi.prod.subarucs.com/g2v27/twoStepAuthContacts.json'), method='POST', headers=<CIMultiDictProxy('Host': 'mobileapi.prod.subarucs.com', 'User-Agent': 'HomeAssistant/2023.8.2 aiohttp/3.8.5 Python/3.11', 'Accept': '/', 'Accept-Encoding': 'gzip, deflate', 'Cookie': 'JSESSIONID=60E7EBE11273660D2955D8A914AB2141; X-Oracle-BMC-LBS-Route=4f65eea550dddceedeb77fa2e2997443fe398a63659292929fc9ab849d024abac24349a63cc2b1fe', 'Content-Length': '0', 'Content-Type': 'application/octet-stream')>, real_url=URL('https://mobileapi.prod.subarucs.com/g2v27/twoStepAuthContacts.json'))

I have a custom shortcut on my iPhone that seems to communicate with a different URL using HTTP headers. Info included below

Shortcut using URL: https://www.mysubaru.com/service/g2/requesttype/execute.json where requesttype is action to call. Example: "unlock" to unlock doors, "engineStart" to start the car, etc.. Link to Reddit post: https://www.reddit.com/r/shortcuts/comments/iu9eib/successfully_created_shortcut_for_subaru_starlink/ There is more info in the comments of the post which you may be interested in for more

G-Two commented 10 months ago

Do you have any 2FA contact methods configured for your MySubaru account (e.g. SMS, email, etc)? The error seems like it might be due to an empty array in the Subaru API backend.

Thanks for the reddit link. That's really interesting!

G-Two commented 10 months ago

Does 2FA with the official MySubaru mobile app work?

JPorter-02 commented 10 months ago

I just checked on my account online and in the app and didnt see 2FA options anywhere in the account. I did however update all my contact info incase this is where the 2FA grabs its info from, but the HA integration still fails. Oddly enough, the mobile app didnt ask for 2FA or maybe its using old cookie info from a while back

G-Two commented 10 months ago

I just looked at my account and also could not find any 2FA option. It probably just uses whatever mobile number and email address you already have associated with your account.

Using commit 6d9e055, I deleted my device in HA, restarted HA, then added the Subaru integration, but I was not able to replicate the error you are receiving (2FA prompt worked and the integration completed configuration).

The HACS integration uses the same API as the mobile app. So it will be helpful to verify that works properly. You can force your mobile app to reauth via 2FA if you delete the device from your account via the website.

Go to: https://www.mysubaru.com/profile/authorizedDevices.html Delete the device associated with your mobile device. Restart your mobile app, and it should prompt you for 2FA via email or text.

image
G-Two commented 10 months ago

If the integration continues to fail, then we'll need a full debug trace of both the integration and the underlying subarulink package to nail down this issue. Please be sure to check carefully and redact any personal information from the trace (address, phone, VIN, longitude/latitude, license plate, etc.)

# configuration.yaml
logger:
  default: warning
  logs:
    custom_components.subaru: debug
    subarulink: debug
JPorter-02 commented 10 months ago

Ok, i deleted all devices including my mobile phone in my Subaru account, installed the commit you mentioned previously and restarted home assistant. On my mobile device, the mysubaru app gives me an error on launch and fails to load (Error: Something went wrong. Please try again later") i am using iOS 16.6, iPhone 11 pro max. The HA integration still fails to connect with the same error in the logs. Not sure what could be the issue here, maybe my account? If all else fails i can reach out to Subaru customer service and have them check their end

G-Two commented 10 months ago

If the mobile app isn't working, then the HACS integration likely won't work either. Since it is a 500 error, it sounds like it is an issue on Subaru's side. Calling Starlink support might be your best bet, especially since the app won't even let you login.

JPorter-02 commented 10 months ago

I opened a case with Subaru so they can look over my account. In the meantime, here is the debug output from home assistant logs incase there is anything here that may help. Ill update once Subaru gets back to me with info

2023-08-12 17:18:36.120 DEBUG (MainThread) [custom_components.subaru.config_flow] Setting up first time connection to Subaru API. 2023-08-12 17:18:36.120 DEBUG (MainThread) [subarulink.controller] subarulink 0.7.7 2023-08-12 17:18:36.120 DEBUG (MainThread) [subarulink.controller] Connecting controller to Subaru Remote Services 2023-08-12 17:18:36.121 DEBUG (MainThread) [subarulink.connection] POST: https://mobileapi.prod.subarucs.com/g2v27/login.json, params=None, json_data=None 2023-08-12 17:18:36.432 DEBUG (MainThread) [subarulink.connection] Client authentication successful 2023-08-12 17:18:36.434 DEBUG (MainThread) [subarulink.connection] {'data': {'account': {'accountKey': *, 'createdDate': 1568073716000, 'firstName': 'Justin', 'lastLoginDate': 1691874665000, 'lastName': '****', 'marketId': 1, 'zipCode': '*', 'zipCode5': '*'}, 'currentVehicleIndex': 0, 'deviceId': '6591878816', 'deviceRegistered': False, 'digitalGlobeConnectId': '0572e32b-2fcf-4bc8-abe0-1e3da8767132', 'digitalGlobeImageTileService': 'https://earthwatch.digitalglobe.com/earthservice/tmsaccess/tms/1.0.0/DigitalGlobe:ImageryTileService@EPSG:3857@png/{z}/{x}/{y}.png?connectId=0572e32b-2fcf-4bc8-abe0-1e3da8767132', 'digitalGlobeTransparentTileService': 'https://earthwatch.digitalglobe.com/earthservice/tmsaccess/tms/1.0.0/Digitalglobe:OSMTransparentTMSTileService@EPSG:3857@png/{z}/{x}/{-y}.png/?connectId=0572e32b-2fcf-4bc8-abe0-1e3da8767132', 'enableXtime': True, 'handoffToken': '$2a$08$sMYAtJIiYBCS0PKQzO9hxO4g1zSgty1BtBxNwVFOG5qtPybXhKI2q$16541878716370', 'passwordToken': None, 'registeredDevicePermanent': False, 'resetPassword': False, 'rightToRepairEnabled': True, 'rightToRepairStartYear': 2022, 'rightToRepairStates': 'MA', 'satelliteViewEnabled': True, 'sessionChanged': False, 'sessionId': '84608D5111A22F5C6E906E54CEB6443F', 'termsAndConditionsAccepted': True, 'tomtomKey': 'DHH9SwEQ4MW55Hj2TfqMeldbsDjTdeAs', 'vehicleInactivated': False, 'vehicles': [{'accessLevel': -1, 'active': True, 'authorizedVehicle': False, 'cachedStateCode': '', 'crmRightToRepair': False, 'customer': {'email': None, 'firstName': None, 'lastName': None, 'oemCustId': None, 'phone': None, 'sessionCustomer': None, 'zip': None}, 'email': None, 'engineSize': None, 'extDescrip': None, 'features': None, 'firstName': None, 'intDescrip': None, 'lastName': None, 'licensePlate': '', 'licensePlateState': '', 'modelCode': None, 'modelName': None, 'modelYear': None, 'needEmergencyContactPrompt': False, 'needMileagePrompt': False, 'nickname': '2021 Forester Premium', 'oemCustId': 'CRM-3-FNQD4HWH', 'phev': None, 'phone': None, 'preferredDealer': None, 'provisioned': True, 'remoteServicePinExist': True, 'show3gSunsetBanner': False, 'stolenVehicle': False, 'subscriptionFeatures': None, 'subscriptionPlans': [], 'subscriptionStatus': None, 'sunsetUpgraded': True, 'timeZone': 'America/Chicago', 'transCode': None, 'userOemCustId': 'CRM-3-FNQD4HWH', 'vehicleGeoPosition': None, 'vehicleKey': ***, 'vehicleMileage': None, 'vehicleName': '2021 Forester Premium', 'vin': '**', 'zip': None}]}, 'dataName': 'sessionData', 'errorCode': 'BIOMETRICS_DISABLED', 'success': True} 2023-08-12 17:18:36.434 DEBUG (MainThread) [subarulink.connection] GET: https://mobileapi.prod.subarucs.com/g2v27/selectVehicle.json, params={'vin': '', '_': 1691876416}, json_data=None 2023-08-12 17:18:36.625 DEBUG (MainThread) [subarulink.connection] {'data': {'accessLevel': -1, 'active': True, 'authorizedVehicle': False, 'cachedStateCode': '', 'crmRightToRepair': False, 'customer': {'email': None, 'firstName': None, 'lastName': None, 'oemCustId': None, 'phone': None, 'sessionCustomer': None, 'zip': None}, 'email': None, 'engineSize': 2.5, 'extDescrip': 'Sepia Bronze Metallic', 'features': ['ABS_MIL', 'ATF_MIL', 'AWD_MIL', 'CEL_MIL', 'EBD_MIL', 'EOL_MIL', 'EPAS_MIL', 'EPB_MIL', 'ESS_MIL', 'EYESIGHT', 'OPL_MIL', 'RES', 'SRS_MIL', 'TEL_MIL', 'TIF_33', 'TIR_32', 'TPMS_MIL', 'VDC_MIL', 'WASH_MIL', 'g2'], 'firstName': None, 'intDescrip': 'Black', 'lastName': None, 'licensePlate': '*', 'licensePlateState': '', 'modelCode': 'MFF', 'modelName': 'Forester', 'modelYear': '2021', 'needEmergencyContactPrompt': False, 'needMileagePrompt': False, 'nickname': '2021 Forester Premium', 'oemCustId': 'CRM-3-FNQD4HWH', 'phev': None, 'phone': None, 'preferredDealer': None, 'provisioned': True, 'remoteServicePinExist': True, 'show3gSunsetBanner': False, 'stolenVehicle': False, 'subscriptionFeatures': ['SAFETY', 'Retail', 'REMOTE'], 'subscriptionPlans': [], 'subscriptionStatus': 'ACTIVE', 'sunsetUpgraded': True, 'timeZone': 'America/Chicago', 'transCode': 'CVT', 'userOemCustId': 'CRM-3-FNQD4HWH', 'vehicleGeoPosition': {'heading': None, 'latitude': **, 'longitude': ****, 'speed': None, 'timestamp': '2023-08-12T22:11:53'}, 'vehicleKey': *, 'vehicleMileage': None, 'vehicleName': '2021 Forester Premium', 'vin': '*****', 'zip': None}, 'dataName': 'vehicle', 'errorCode': None, 'success': True} 2023-08-12 17:18:36.625 DEBUG (MainThread) [subarulink.connection] POST: https://mobileapi.prod.subarucs.com/g2v27/twoStepAuthContacts.json, params=None, json_data=None 2023-08-12 17:18:36.755 ERROR (MainThread) [custom_components.subaru.config_flow] Unable to communicate with Subaru API: HTTP 500: {"httpCode":500,"errorCode":"error","errorMessage":"java.lang.ArrayIndexOutOfBoundsException - null"} RequestInfo(url=URL('https://mobileapi.prod.subarucs.com/g2v27/twoStepAuthContacts.json'), method='POST', headers=<CIMultiDictProxy('Host': 'mobileapi.prod.subarucs.com', 'User-Agent': 'HomeAssistant/2023.8.2 aiohttp/3.8.5 Python/3.11', 'Accept': '/', 'Accept-Encoding': 'gzip, deflate', 'Cookie': 'JSESSIONID=84608D5111A22F5C6E906E53CEB6443F; X-Oracle-BMC-LBS-Route=4f65eea550dddceedeb77fa2e2997443fe398a63c42389c0a9970cf511be0189adcacbfb6c50b1b1', 'Content-Length': '0', 'Content-Type': 'application/octet-stream')>, real_url=URL('https://mobileapi.prod.subarucs.com/g2v27/twoStepAuthContacts.json'))

G-Two commented 10 months ago

I don't see anything unusual in your logs.

I turned on my debug traces to try to replicate and confirmed the specific API call (that is failing for you) is functional on my end:

2023-08-13 13:52:31.619 DEBUG (MainThread) [subarulink.connection] POST: https://mobileapi.prod.subarucs.com/g2v27/twoStepAuthContacts.json, params=None, json_data=None
2023-08-13 13:52:31.790 DEBUG (MainThread) [subarulink.connection] {'data': {'phone': '***-***-****', 'userName': '*********@******.com'},
 'dataName': 'dataMap',
 'errorCode': None,
 'success': True}

I'm not sure why this is, but hopefully customer service is able to fix it.

Assuming the problem is something specific about your account, a clunky alternative approach to circumventing this issue would be to try authorizing access to your vehicle to a separate MySubaru account that you setup for yourself using a different email address/alias that you control.

From the MySubaru website FAQ:

An authorized user is someone (like a partner or child of driving age) you add to your MySubaru Account to give them access to remote services, vehicle health reports, and more. The authorized user will have their own MySubaru log-in and be able to set their own preferences for receiving notifications from STARLINK®. You can set up different levels of access for your authorized users so they can control different STARLINK® features. To add an authorized user on your desktop or laptop computer, select the My Profile menu and then Security Settings. Within the Security Settings section, select Authorized Users and then select Add Authorized User to enter their details. If the authorized user does not have a MySubaru account, they will receive an email with details on how to finish their account setup. If they already have an existing MySubaru account, the vehicle they are authorized to access will be added to their existing account.

Once you setup a new MySubaru account, you could try seeing if it also has the same problem.

JPorter-02 commented 10 months ago

Following up on this, i ended up having to call Subaru customer support and they opened a ticket for me after some basic troubleshooting. They asked me to send in some screenshots and details of the issue. I also sent in a screenshot of the HTTP 500 error HA game me. This information was then forwarded up to L2 technical support where the issue was eventually fixed. I am not sure what they did to fix it, but calling them and sending in this info seemed to work for me. The techs from start to finish were very nice and patient, and even took down my contact info incase they needed to call me back for more info.

I will also add, while i was having this trouble with the HA integration, i was also unable to edit or update any contact info in MySubaru account or add/modify authorized users from the website via a web browser on a desktop PC. The entire website was clunky for me and nothing seemed to work right except the remote commands and billing (Of course) until this was resolved.

Thankfully, everything seems to work now and the Subaru integration allowed me to login along with the mobile app. I see my vehicle stats and remote commands in HA now. Thanks @G-Two for your help on this issue!