Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nearby Chargers #612

Open
israndy opened this issue Aug 5, 2022 · 9 comments
Open

Nearby Chargers #612

israndy opened this issue Aug 5, 2022 · 9 comments

Comments

@israndy
Copy link

israndy commented Aug 5, 2022

The current documentation on how the API works still works in that it returns the 4 Destination and 4 Superchargers, but the current Tesla app now has a location entry that shows your car on a map and if you scroll down it shows the 10 closest Superchargers. Has anyone figured out this change? The old way of doing it seems to return rather random Superchargers, not the 4 closest, perhaps the new way is better

@idriskhenchil
Copy link

You can access the 10 closest with this new endpoint

POST https://akamai-apigateway-charging-ownership.tesla.com/graphql?deviceLanguage=en&deviceCountry=US&ttpLocale=en_US&vin=XXXXXX&operationName=GetNearbyChargingSites

Body:

{
  "query": "\n    query GetNearbyChargingSites($args: GetNearbyChargingSitesRequestType!) {\n  charging {\n    nearbySites(args: $args) {\n      sitesAndDistances {\n        ...ChargingNearbySitesFragment\n      }\n    }\n  }\n}\n    \n    fragment ChargingNearbySitesFragment on ChargerSiteAndDistanceType {\n  activeOutages {\n    message\n  }\n  availableStalls {\n    value\n  }\n  centroid {\n    ...EnergySvcCoordinateTypeFields\n  }\n  drivingDistanceMiles {\n    value\n  }\n  entryPoint {\n    ...EnergySvcCoordinateTypeFields\n  }\n  haversineDistanceMiles {\n    value\n  }\n  id {\n    text\n  }\n  localizedSiteName {\n    value\n  }\n  maxPowerKw {\n    value\n  }\n  totalStalls {\n    value\n  }\n  siteType\n  accessType\n}\n    \n    fragment EnergySvcCoordinateTypeFields on EnergySvcCoordinateType {\n  latitude\n  longitude\n}\n    ",
  "variables": {
    "args": {
      "userLocation": {
        "latitude": XXXXXX,
        "longitude": -XXXXXX
      },
      "northwestCorner": {
        "latitude": XXXXXX,
        "longitude": -XXXXXX
      },
      "southeastCorner": {
        "latitude": XXXXXX,
        "longitude": -XXXXXX
      },
      "openToNonTeslasFilter": {
        "value": false
      },
      "languageCode": "en",
      "countryCode": "US",
      "vin": "XXXXXX"
    }
  },
  "operationName": "GetNearbyChargingSites"
}

Headers to send

x-tesla-user-agent: TeslaApp/4.11.1/12ad93c62a/ios/16.0
User-Agent: Tesla/1195 CFNetwork/1388 Darwin/22.0.0
Content-Type: application/json
Authorization: Bearer XXXX

@rawmean
Copy link

rawmean commented Aug 29, 2022

I can't get the original endpoint for getting 4 nearby chargers to work. Does it work for you?

@israndy
Copy link
Author

israndy commented Aug 30, 2022 via email

@Niek
Copy link

Niek commented Aug 31, 2022

@idriskhenchil did you find out how to access the pricing info? The endpoint you listed does not contain it.

There is also a bff/v2/mobile-app/charging/site/{id} mobile endpoint, but I didn't get that working yet.

@idriskhenchil
Copy link

idriskhenchil commented Aug 31, 2022

@Niek I've only been able to view select charging station prices (all but one in Europe) with the following endpoint. There is one private station in California I have been able to view pricing for, which is also visible via the app in the "Charge non-Tesla" map.

https://akamai-apigateway-charging-ownership.tesla.com/graphql?deviceLanguage=en&deviceCountry=US&ttpLocale=en_US&operationName=GetChargingSitePricing

With the following body (Also include your authorization header)

{
  "query": "\n    query GetChargingSitePricing($siteId: String!, $deviceCountry: String!, $deviceLanguage: String!, $upselling: Boolean) {\n  charging {\n    sitePricing(\n      siteId: $siteId\n      deviceCountry: $deviceCountry\n      deviceLanguage: $deviceLanguage\n      upselling: $upselling\n    ) {\n      userRates {\n        ...ChargingSiteRatesFragment\n      }\n      memberRates {\n        ...ChargingSiteRatesFragment\n      }\n    }\n  }\n}\n    \n    fragment ChargingSiteRatesFragment on ChargingSiteRatesType {\n  charging {\n    uom\n    rates\n    currencyCode\n    programType\n    priceBookID\n    vehicleMakeType\n  }\n  parking {\n    uom\n    rates\n    currencyCode\n    programType\n    priceBookID\n    vehicleMakeType\n  }\n}\n    ",
  "variables": {
    "siteId": "XXX",
    "ttpLocale": "en_US",
    "deviceLanguage": "en",
    "deviceCountry": "US",
    "vin": "XXX"
  },
  "operationName": "GetChargingSitePricingTsla"
}

Reponse

{
  "data": {
    "charging": {
      "sitePricing": {
        "userRates": {
          "charging": {
            "uom": "kwh",
            "rates": [
              0.21
            ],
            "currencyCode": "USD",
            "programType": "PTWCR",
            "priceBookID": 55597,
            "vehicleMakeType": "NTSLA"
          },
          "parking": {
            "uom": "min",
            "rates": [
              0
            ],
            "currencyCode": "USD",
            "programType": "PTWCR",
            "priceBookID": 55597,
            "vehicleMakeType": "NTSLA"
          }
        },
        "memberRates": null
      }
    }
  },
  "extensions": {
    "txId": "XXX"
  }
}

When making the request with a site-id for a supercharger outside of those in Europe it will return an error.

@Niek
Copy link

Niek commented Aug 31, 2022

Thanks @idriskhenchil - excellent work! Using this it's rather easy to show the pricing info of the 10 closest superchargers in Europe.

Unfortunately the site IDs do not correspond to those in the cua-api endpoints (used by the supercharger map), so if one wants to gather a list of pricing of all superchargers, I guess the sites have to be manually scraped at most 10 per batch.

@idriskhenchil
Copy link

@Niek Yeah that's how it appears to be, but at the moment I've only been able to view pricing for less than 50 chargers. I would be interested to see if someone could figure out why you're able to get pricing for some, and not others. Particularly in the U.S.

@Niek
Copy link

Niek commented Sep 4, 2022

FYI I added a repo that updates daily all known superchargers with pricing info in Europe: https://github.com/Niek/tesla-superchargers

I would love to map more but the 10 chargers per API call limit is killing my API quota.

@9cat
Copy link

9cat commented Dec 6, 2022

The current documentation on how the API works still works in that it returns the 4 Destination and 4 Superchargers, but the current Tesla app now has a location entry that shows your car on a map and if you scroll down it shows the 10 closest Superchargers. Has anyone figured out this change? The old way of doing it seems to return rather random Superchargers, not the 4 closest, perhaps the new way is better

Any updated solution for this? I found the new opened charge sites also not appear on the API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants