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

Add new Nearby Chargers endpoint 🔗 #615

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions docs/vehicle/state/nearbychargingsites.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,97 @@ Returns a list of nearby Tesla-operated charging stations. (Requires car softwar
}
}
```

## POST `https://akamai-apigateway-charging-ownership.tesla.com/graphql`

Returns a list of the ten closest Tesla-operated charging stations to the given coordinates.

### Headers

This endpoint requires a few additional headers to work. (Values are pulled from the Tesla iOS App)

| Header | Value | Example | Description |
| :----------------- | :-------------------------------------------------------------------------- | :-------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| x-tesla-user-agent | TeslaApp/{app-version}/{app-extra}/ios/{ios-version} | TeslaApp/4.11.1/12ad93c62a/ios/16.0 | This is the tesla app's user-agent for iOS. It is composed of the version number, the version extra, and the iOS version. You can find `app-version` and `app-extra` inside of the Tesla App at the bottom of the settings page. |
| User-Agent | Tesla/{app-version-extra} CFNetwork/1388 Darwin/{ios-darwin-kernel-version} | Tesla/1195 CFNetwork/1388 Darwin/22.0.0 | This is the `User-Agent` it is composed of the `app-version-extra` which can be found at the bottom of the Tesla App next to the app version number, and the darwin kernel version, corresponding to the ios version specified above. |
| Content-Type | application/json | application/json | Always `application/json`. |

> Don't forget to pass your Bearer Access Token, in the `Authorization` header as well.

### Parameters

| Parameter | Example | Description |
| :------------- | :--------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| deviceLanguage | en | The device's language. This is not relevant and can be left as `en`. |
| deviceCountry | US | The device's country/region. Match this to your [country code](https://www.iban.com/country-codes). |
| ttpLocale | en_US | This is the http locale/language. This locale is in the UTF-8 format, you can find a list [here](https://docs.moodle.org/dev/Table_of_locales). You can leave it as `en_US` or match it to your preferred language. |
| vin | 5YJ/7SA | Your vehicles full vin number. |
| operationName | GetNearbyChargingSites | This is the operation name/what you want the api to do, for this request, it will always be `GetNearbyChargingSites` |

### Body

```json
{
"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": 12345.67,
"longitude": -12345.67
},
"northwestCorner": {
"latitude": 12345.67,
"longitude": -12345.67
},
"southeastCorner": {
"latitude": 12345.67,
"longitude": -12345.67
},
"openToNonTeslasFilter": {
"value": false
},
"languageCode": "Referr to 'deviceLanguage' in the parameters above.",
"countryCode": "Referr to 'deviceCountry' in the parameters above.",
"vin": "5YJ/7SA"
}
},
"operationName": "GetNearbyChargingSites"
}
```

### Response

> Note: Response is estimated, due to the API returning `null` for me.

```json
{
"data": {
"charging": [
{
"available_stalls": 37,
"distance_miles": 11.48318,
"location": {
"lat": 12345.67,
"long": 12345.67
},
"name": "Mars, Supercharger",
"site_closed": false,
"total_stalls": 40,
"type": "supercharger"
},
{
"available_stalls": 9,
"distance_miles": 16.54368,
"location": {
"lat": 12345.67,
"long": 12345.67
},
"name": "Mars, Small Supercharger",
"site_closed": false,
"total_stalls": 10,
"type": "supercharger"
}
]
}
}
```