Welcome to Tesla Motors Club
Discuss Tesla's Model S, Model 3, Model X, Model Y, Cybertruck, Roadster and More.
Register

Model S REST API

This site may earn commission on affiliate links.
Sorry to ask again, but I am stuck.

Why does that not work? It is copied from the API docs php sample:

Code:
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://owner-api.teslamotors.com/api/1/vehicles/".$VEHICLE_ID."/command/honk_horn");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);

curl_setopt($ch, CURLOPT_POST, TRUE);

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  "Authorization: Bearer $token"
));

$response = curl_exec($ch);
curl_close($ch);

var_dump($response);

I just get a 404 back. All the request-type functions work, but all the command ones don't.

I don't know much PHP, but is this actually sending the colon as well?

Code:
"Authorization: Bearer $token"
 
Is it just for me, or does the old way (passing 'lat', 'lon' and 'action' parameter in the POST body) of making the car summon no longer working? No matter what I do, I get the "too far away from car" response, even when using the exact same lat/lon coordinates that the car returns for its current position.

EDIT: never mind, found the problem: 'Lat' != 'lat' ... :cool:
 
Last edited:
Does anyone have any examples getting streaming data via Python?

I've written a few scripts using teslajson from GitHub but it doesn't include any streaming data.

Thanks

GitHub - jstenback/pytesla: pytesla is a python bindings for the Model S REST API does streaming in python, though for some reason I'm having issues with authentication using that code right now.

Authentication worked fine a couple of months ago, did something change recently around Tesla's oAuth authentication?
 
Those are hours if I recall correctly. So 150 days. Or until you change the mytesla-password. So make sure to check the tokens, regardless of the expiration date.

Are you sure they're hours? the oauth spec says they're supposed to be seconds, I just generated a new token and it gave me the following:

expires_in:7776000
created_at:1463347242

if it is seconds, 7776000 / 60 = 129600(minutes) / 60 = 2160(hours) / 24 = 90 days
if it's hours 7776000 / 24 = 324000(days) / 365 = 887.67 years

I find it hard to believe that the token has a lifetime of 887 years :eek:
 
So I have been trying to use the REST API with cURL as described here: Tesla Model S Remote Access Protocol

But for some reason i keep getting "failed to connect to portal.vn.teslamotors.com port 443. timeout."

I have used this command as stated in the document:

curl -c cookie-jar -F ‘user_session=EMAIL’ -F ‘user_session[password]=PW’ [URL]https://portal.vn.teslamotors.com/login[/URL]

Using my mail and password as usual.

I am trying to make an java program to do some small stuff and as far as i can see there is no java liberary that I can use so I was thinking about using cURL with java to make it, but I have never used cURL before so i am not sure what I am doing wrong. For now I am only running it from the shell for testing.

Sorry for my noob question, but do you guys have any tips for me?

thanks
 
Are you sure they're hours? the oauth spec says they're supposed to be seconds, I just generated a new token and it gave me the following:

expires_in:7776000
created_at:1463347242

if it is seconds, 7776000 / 60 = 129600(minutes) / 60 = 2160(hours) / 24 = 90 days
if it's hours 7776000 / 24 = 324000(days) / 365 = 887.67 years

I find it hard to believe that the token has a lifetime of 887 years :eek:


It's seconds and they last 90 days.
 
  • Helpful
Reactions: L-P-G
Yea that's what I was thinking as well. Any idea how to decode the created_at date?

That's a Unix timestamp. How you parse it depends on the language. The only thing that could trip you up when working with it is that this particular Unix timestamp is in seconds, and some date libraries expect milliseconds, so you would need to multiple it by 1,000.

If you pop open your JavaScript Console in your browser's developer tools and type...

Code:
new Date(1463347242 * 1000) // The created_at timestamp quoted above multiple by 1,000

...it will return a human-readable date string corresponding to that Unix timestamp.

The timestamp above gave me this: "Mon May 16 2016 06:20:42 GMT+0900 (KST)". Note that this is Korean Standard Time, so you will probably get a half-day earlier or so.
 
  • Helpful
Reactions: L-P-G
So I have been trying to use the REST API with cURL as described here: Tesla Model S Remote Access Protocol

But for some reason i keep getting "failed to connect to portal.vn.teslamotors.com port 443. timeout."

I have used this command as stated in the document:

curl -c cookie-jar -F ‘user_session=EMAIL’ -F ‘user_session[password]=PW’ https://portal.vn.teslamotors.com/login

Using my mail and password as usual.

I am trying to make an java program to do some small stuff and as far as i can see there is no java liberary that I can use so I was thinking about using cURL with java to make it, but I have never used cURL before so i am not sure what I am doing wrong. For now I am only running it from the shell for testing.

Sorry for my noob question, but do you guys have any tips for me?

thanks

Any help on this would be much appritiated. I guess you all do login this way so there has to be some obvius wrong with my call?
 
Any help on this would be much appritiated. I guess you all do login this way so there has to be some obvius wrong with my call?

That is not the URL used to login. The base URL has been replaced by https://owner-api.teslamotors.com and the login URL is now POST https://owner-api.teslamotors.com/oauth/token with the following form URL-encoded body parameters:
  • grant_type ('password')
  • client_id
  • client_secret
  • email
  • password
The current client ID and client secret can be found here. This will give you back an OAuth token which you can then use to authenticate all further requests related to the account you logged in with.

For instance, to get the account's vehicles, the URL is GET https://owner-api.teslamotors.com/api/1/vehicles with the Authorization header set to 'Bearer theOAuthTokenFromThePreviousRequest'.

I would suggest using Apache HttpClient if you're using Java to do this without any kind of framework.
 
That is not the URL used to login. The base URL has been replaced by https://owner-api.teslamotors.com and the login URL is now POST https://owner-api.teslamotors.com/oauth/token with the following form URL-encoded body parameters:
  • grant_type ('password')
  • client_id
  • client_secret
  • email
  • password
The current client ID and client secret can be found here. This will give you back an OAuth token which you can then use to authenticate all further requests related to the account you logged in with.

For instance, to get the account's vehicles, the URL is GET https://owner-api.teslamotors.com/api/1/vehicles with the Authorization header set to 'Bearer theOAuthTokenFromThePreviousRequest'.

I would suggest using Apache HttpClient if you're using Java to do this without any kind of framework.

Thanks for usefull help! I have got my token, but when trying to do calls I dont get a respons. As of now I am trying this:

Code:
curl -H "Authorization: Bearer <2a6906127b5125833a09abaa945db9e5b3e273c5fa9ce7f74ee261ba85af61>" https:/
/owner-api.teslamotors.com/api/1/vehicles
 
That's a Unix timestamp. How you parse it depends on the language. The only thing that could trip you up when working with it is that this particular Unix timestamp is in seconds, and some date libraries expect milliseconds, so you would need to multiple it by 1,000.

If you pop open your JavaScript Console in your browser's developer tools and type...

Code:
new Date(1463347242 * 1000) // The created_at timestamp quoted above multiple by 1,000

...it will return a human-readable date string corresponding to that Unix timestamp.

The timestamp above gave me this: "Mon May 16 2016 06:20:42 GMT+0900 (KST)". Note that this is Korean Standard Time, so you will probably get a half-day earlier or so.

There is a really good online Unix Epoch Timestamp converter than I have found helpful at Epoch Converter - Unix Timestamp Converter