leeyuentuen / polestar_api

Polestar Api - Home Assistant Component
MIT License
112 stars 18 forks source link

Polestar API Down: New API Endpoint "/mystar-v2" #96

Closed leeyuentuen closed 5 months ago

leeyuentuen commented 5 months ago

Discussed in https://github.com/leeyuentuen/polestar_api/discussions/95

Originally posted by **loebse** January 18, 2024 Looks like there is a new API endpoint available. The "old" ``/my-star`` is no longer working. However, there is a new one ``/mystar-v2``
leeyuentuen commented 5 months ago

@loebse, quick fix to let use partial new endpoint (not investigate other stuffs). https://github.com/leeyuentuen/polestar_api/releases/tag/1.5.7

wouterhardeman commented 5 months ago

It appears that getBatteryData and getOdometerData have been moved to mystar-v2. Queries like getConsumerCarsV2 are still in /my-star

image

leeyuentuen commented 5 months ago

@wouterhardeman should work on the new beta version, can you check the message above?

mountainbikert commented 5 months ago

All entities are back up again. There's also a new (static) value: Torque

leeyuentuen commented 5 months ago

All entities are back up again. There's also a new (static) value: Torque

ya, I was planning to do something, but it seems it doesn't work. I want to calculate the charging speed, but I need to know the battery size (what I have) I don't know what the battery limit is set atm. so I can't continue

wouterhardeman commented 5 months ago

All entities are back up again. There's also a new (static) value: Torque

ya, I was planning to do something, but it seems it doesn't work. I want to calculate the charging speed, but I need to know the battery size (what I have) I don't know what the battery limit is set atm. so I can't continue

You could make an estimate by using the time delta between battery percentage going up and then diving that by the battery size. I could have a try and implement it if you want?

leeyuentuen commented 5 months ago

All entities are back up again. There's also a new (static) value: Torque

ya, I was planning to do something, but it seems it doesn't work. I want to calculate the charging speed, but I need to know the battery size (what I have) I don't know what the battery limit is set atm. so I can't continue

You could make an estimate by using the time delta between battery percentage going up and then diving that by the battery size. I could have a try and implement it if you want?

be my guest to try it out. not sure how accurate the delta time will be, because sometimes it only updates every 5 min or something.

leeyuentuen commented 5 months ago

i'll close this issue, for more discussion, we can continue on disuccion https://github.com/leeyuentuen/polestar_api/discussions/95

andig commented 5 months ago

Have just hit the same in https://github.com/evcc-io/evcc/issues/11754. Followed your change, i.e. use /mystar-v2 for battery and odometer. Unfortunately, I'm seeing

{
  "errors" : [ {
    "errorType" : "UnauthorizedException",
    "message" : "Unauthorized"
  } ]
}

for the new endpoint, using identical token as for the original endpoint. Did you notice anything like this?

leeyuentuen commented 5 months ago

Have just hit the same in evcc-io/evcc#11754. Followed your change, i.e. use /mystar-v2 for battery and odometer. Unfortunately, I'm seeing

{
  "errors" : [ {
    "errorType" : "UnauthorizedException",
    "message" : "Unauthorized"
  } ]
}

for the new endpoint, using identical token as for the original endpoint. Did you notice anything like this?

depends which call you get this exception. the call the odo and battery call it is only the url

the other getcarinformation add extra variable to locale

andig commented 5 months ago

Only odo and battery. Maybe I‘ll need to test with different car to see if that makes a difference. Thank you!

andig commented 5 months ago

Btw, https://github.com/leeyuentuen/polestar_api/commit/aa88faf730b03bb3f67a702f70eb948acd884a93#diff-6c13acca0123ef6e56fd0bfc79573379cde1a7f9a1cd556b39f9a301cfdebfeeR106 looks wrong- local instead of locale? But still works?

leeyuentuen commented 5 months ago

Only odo and battery. Maybe I‘ll need to test with different car to see if that makes a difference. Thank you!

Btw, aa88faf#diff-6c13acca0123ef6e56fd0bfc79573379cde1a7f9a1cd556b39f9a301cfdebfeeR106 looks wrong- local instead of locale? But still works?

nice, maybe it should filled in to get work. but i'll change them next time

andig commented 5 months ago

@leeyuentuen thanks for bearing with me. Could I ask you to kindly confirm that this works for you?

TOKEN=...

curl -X POST --data '{"query":"query getCars{getConsumerCarsV2{vin,internalVehicleIdentifier}}","operationName":"getCars"}' \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer $TOKEN" \
https://pc-api.polestar.com/eu-north-1/my-star

curl -X POST --data '{"query":"query GetOdometerData($vin:String!){getOdometerData(vin: $vin){odometerMeters}}","variables":{"vin":"<VIN>"},"operationName":"GetOdometerData"}' \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer $TOKEN" \
https://pc-api.polestar.com/eu-north-1/mystar-v2

It doesn't for me on the 2nd request:

{
  "errors" : [ {
    "errorType" : "UnauthorizedException",
    "message" : "Unauthorized"
  } ]
}
leeyuentuen commented 5 months ago

i'll check later. i'm not at my pc today

leeyuentuen commented 5 months ago

@andig it works for me image

using the following curl call: curl -X POST --data '{"query":"query getCars{getConsumerCarsV2{vin,internalVehicleIdentifier}}","operationName":"getCars"}' \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer $token" \ https://pc-api.polestar.com/eu-north-1/my-star

curl -X POST --data '{"query":"query GetOdometerData($vin:String!){getOdometerData(vin:$vin){averageSpeedKmPerHour eventUpdatedTimestamp{iso unix}odometerMeters tripMeterAutomaticKm tripMeterManualKm}}","variables":{"vin”:”<vin>"},"operationName":"GetOdometerData"}' \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer $token" \ https://pc-api.polestar.com/eu-north-1/mystar-v2

andig commented 5 months ago

Thank you, much appreciated. Seems there are further implementation differences that I'll need to figure out.

andig commented 5 months ago

@leeyuentuen additional difference I've found is authentication. Seems you're using the flow that the web app is using while I was using a different flow for polexplore. Could I kindly ask you to share a curl example for getAuthToken graphQL? For some weird reason I always bump into " BAD USER INPUT and I'm still unsure if really all vehicles should work for the new auth of if this is maybe a weird firmware-difference thing. Much appreciated!

leeyuentuen commented 5 months ago

i haven't use in this api the getAuthToken. but the graphql should be like this:

query GetAuthToken($code: String) { getAuthToken(code: $code) { access_token refresh_token id_token expires_in } }

leeyuentuen commented 5 months ago

by the way, it would be interesting if you were using polexplore. on my API version here I'm using polmystar

if you have token from polexplore, then you should also get access on the climate and the door unlock feature I suppose

leeyuentuen commented 5 months ago

@andig maybe easier to continue in the discussion thread? https://github.com/leeyuentuen/polestar_api/discussions/95 because is not really an issue but more a discussion