From 6daa326c370e93771202bfd45cd6207091f83973 Mon Sep 17 00:00:00 2001 From: andig Date: Sat, 29 Oct 2022 15:57:50 +0200 Subject: [PATCH] Ford: fix api (#4958) --- vehicle/ford.go | 2 ++ vehicle/ford/api.go | 29 +++++++++++++++++++---------- vehicle/ford/types.go | 6 +++--- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/vehicle/ford.go b/vehicle/ford.go index fdef337ab..b5e4b75ba 100644 --- a/vehicle/ford.go +++ b/vehicle/ford.go @@ -10,6 +10,8 @@ import ( ) // https://github.com/d4v3y0rk/ffpass-module +// https://github.com/ianjwhite99/connected-car-node-sdk +// https://github.com/TA2k/ioBroker.ford // Ford is an api.Vehicle implementation for Ford cars type Ford struct { diff --git a/vehicle/ford/api.go b/vehicle/ford/api.go index 19300985b..de227aeb6 100644 --- a/vehicle/ford/api.go +++ b/vehicle/ford/api.go @@ -13,7 +13,7 @@ import ( const ApiURI = "https://usapi.cv.ford.com" -// API is the VW api client +// API is the Ford api client type API struct { *request.Helper } @@ -30,8 +30,11 @@ func NewAPI(log *util.Logger, ts oauth2.TokenSource) *API { if err == nil { for k, v := range map[string]string{ "Content-type": request.JSONContent, + "User-Agent": "FordPass/5 CFNetwork/1333.0.4 Darwin/21.5.0", + "locale": "de-DE", "Application-Id": ApplicationID, "Auth-Token": token.AccessToken, + "CountryCode": "DEU", } { req.Header.Set(k, v) } @@ -46,24 +49,30 @@ func NewAPI(log *util.Logger, ts oauth2.TokenSource) *API { // Vehicles returns the list of user vehicles func (v *API) Vehicles() ([]string, error) { - var resp VehiclesResponse - var vehicles []string + var res []string - uri := fmt.Sprintf("%s/api/users/vehicles", TokenURI) + data := map[string]string{ + "dashboardRefreshRequest": "All", + } - err := v.GetJSON(uri, &resp) + uri := fmt.Sprintf("%s/api/expdashboard/v1/details", TokenURI) + + req, err := request.New(http.MethodPost, uri, request.MarshalJSON(data), request.JSONEncoding) if err == nil { - for _, v := range resp.Vehicles.Values { - vehicles = append(vehicles, v.VIN) + var resp VehiclesResponse + if err = v.DoJSON(req, &resp); err == nil { + for _, v := range resp.UserVehicles.VehicleDetails { + res = append(res, v.VIN) + } } } - return vehicles, err + return res, err } // Status performs a /status request func (v *API) Status(vin string) (StatusResponse, error) { - uri := fmt.Sprintf("%s/api/vehicles/v3/%s/status", ApiURI, vin) + uri := fmt.Sprintf("%s/api/vehicles/v5/%s/status", ApiURI, vin) var res StatusResponse err := v.GetJSON(uri, &res) @@ -75,7 +84,7 @@ func (v *API) Status(vin string) (StatusResponse, error) { func (v *API) RefreshResult(vin, refreshId string) (StatusResponse, error) { var res StatusResponse - uri := fmt.Sprintf("%s/api/vehicles/v3/%s/statusrefresh/%s", ApiURI, vin, refreshId) + uri := fmt.Sprintf("%s/api/vehicles/v5/%s/statusrefresh/%s", ApiURI, vin, refreshId) err := v.GetJSON(uri, &res) return res, err diff --git a/vehicle/ford/types.go b/vehicle/ford/types.go index 8b8327c95..2ed72bf85 100644 --- a/vehicle/ford/types.go +++ b/vehicle/ford/types.go @@ -6,10 +6,10 @@ import ( ) type VehiclesResponse struct { - Vehicles struct { - Values []struct { + UserVehicles struct { + VehicleDetails []struct { VIN string - } `json:"$values"` + } } }