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

Get Safety Score endpoints data #37

Closed
rog0978 opened this issue Oct 13, 2021 · 7 comments
Closed

Get Safety Score endpoints data #37

rog0978 opened this issue Oct 13, 2021 · 7 comments

Comments

@rog0978
Copy link

rog0978 commented Oct 13, 2021

Anyone managed to get Safety Score data? I see the end points in endpoints.json, but they don't seem to work with e.g. the cli.py example.

@tdorssers
Copy link
Owner

tdorssers commented Oct 13, 2021

It seems that some of the new endpoints require a different base URL, but there is still not much documentation about this. Take a look at timdorr/tesla-api#444 and timdorr/tesla-api#445 for some details.

@tdorssers
Copy link
Owner

As suggested here: timdorr/tesla-api#445 (comment), I have removed JWT usage for Owner API access and I use the OAuth2 SSO token for everything in f42b423. This commit also adds the option to use an absolute URL as an argument to request(), which makes this possible:

from teslapy import Tesla

with Tesla('elon@tesla.com') as tesla:
    vehicles = tesla.vehicle_list()
    url = 'https://akamai-apigateway-vfx.tesla.com/safety-rating/daily-metrics'
    print(tesla.get(url, params={'vin': vehicles[0]['vin'],
                                 'deviceLanguage': 'en',
                                 'deviceCountry': 'US'}))

Can you pull the latest commit and give this a try?

@philipsd6
Copy link

FYI, you need to add timezone to the params, otherwise you get a validation error.

...
    print(tesla.get(url, params={'vin': vehicles[0]['vin'],
                                 'deviceLanguage': 'en',
                                 'deviceCountry': 'US',
                                 'timezone': 'UTC'}))

@tdorssers
Copy link
Owner

Thanks, I have added this example to the readme!

@philipsd6
Copy link

yw! Now the only thing I'm struggling to figure out is what the numbers mean in the dailyAggregation.metrics. Seems like the Deciles are a float between 0 and 1, and they are opposite of what I understand decile rankings to be, and I guess it appears to be a ranking against all other drivers? The Median... the median of what? Same for Average -- average of what? Are these numbers aggregated by an unknown number of measurements taken during that daily period? I dunno if I did it right, but I made some graphs out of the data -- but if anyone has a better sense of the data, maybe that can be shared!? :)

@andeplane
Copy link

andeplane commented Dec 10, 2021

I'm getting a 400 on this request, but maybe it's because I'm not in the US and my car isn't measuring safety score?

with Tesla('my@email.com') as tesla:
    vehicles = tesla.vehicle_list()
    url = 'https://akamai-apigateway-vfx.tesla.com/safety-rating/daily-metrics'
    print(tesla.get(url, params={'vin': vehicles[0]['vin'], 'deviceLanguage': 'en',
                                 'deviceCountry': 'US', 'timezone': 'UTC'}))

@tdorssers
Copy link
Owner

Yes, as far as I know it's US only.

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

4 participants