Welcome to Tesla Motors Club
Discuss Tesla's Model S, Model 3, Model X, Model Y, Cybertruck, Roadster and More.
Register
  • We just completed a significant update, but we still have some fixes and adjustments to make, so please bear with us for the time being. Cheers!

Model S REST API

Missile Toad

Member
Aug 30, 2016
581
530
Houston
Did you read the last page of posts aboud id vs id_s?

It all makes sense, if you are prepared for Tesla to change the id_s every couple of weeks. I wonder what that's all about? I'm updating my code to daily check what the id_s is for each car now. Kinda like trying to balance on logs floating down the river.
 

darth_vad3r

Well-Known Sith
May 6, 2019
1,574
1,119
Canada
OK, code to get a list of today's 'id_s's:

curl -s --max-time 20 -X GET https://owner-api.teslamotors.com/api/1/vehicles -H "Authorization: bearer <nothing to see here>" | jq '.' | egrep -o "id_s.:.*" | sed -e 's/^:\? \?//g' -e 's/,$//g' | egrep -o "[0-9]+" | xargs -n2 | tr ' ' ','

Rinse, lather, repeat.

Thanks. I'm also using curl and jq! :) (wrapped up in some bash scripts)

Why not just query https://owner-api.teslamotors.com/api/1/vehicles to get {id_s} each time you need it? It's a super quick query. Who knows how often Tesla will change it.

BTW, my {id_s} didn't change.

There are various levels of API tinkerers on here. Some between scripts with curl + commandline stuff, and some with apps/programs/services like private versions of TeslaFi :)

For the script-kiddies amongst us, it's easy enough to just realize ... "hmm, my command failed" => check for new id_s ... update it.

But yes, could check more often, or EVERY command. It's unlikely to change more than once a day probably, not like an expiring token or something ... hmm.

I dunno, are they building some sort of token into the id?

It might be a security issue they are trying to deal with?

I dunno.
 
  • Like
Reactions: Missile Toad

ckoval7

Mild One
Sep 19, 2018
662
599
Maryland
Anyone know what's going on with the streaming API? This is what I'm getting from what someone posted back in 2018:
Code:
VEHICLE_TOKEN='[redacted]'
TESLA_EMAIL='[redacted]'
VEHICLE_ID='[redacted]'
curl --user "$TESLA_EMAIL:$VEHICLE_TOKEN" "https://streaming.vn.teslamotors.com/stream/$VEHICLE_ID/?values=speed,odometer,soc,elevation,est_heading,est_lat,est_lng,power,shift_state"

Output:
<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx</center>
</body>
</html>

And this is what I'm getting from some python that I found from February
Code:
import requests
TeslaEmail = "[redacted]"
Tesla_Streamingtoken = "[redacted]"
Tesla_vehicle_id = [redacted]
#v.wake_up()
r = requests.get("https://streaming.vn.teslamotors.com/stream/" + str(Tesla_vehicle_id) + "/?values=speed,odometer,soc,elevation,est_heading,est_lat,est_lng,power,shift_state,est_range",data={}, auth=(TeslaEmail, Tesla_Streamingtoken), stream=True)

for line in r.iter_lines():
    if line:
        print line
print "Stream end"

Output:
<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx</center>
</body>
</html>

Is anyone successfully using the streaming currently?
 

darth_vad3r

Well-Known Sith
May 6, 2019
1,574
1,119
Canada
Anyone know what's going on with the streaming API? This is what I'm getting from what someone posted back in 2018:
Code:
VEHICLE_TOKEN='[redacted]'
TESLA_EMAIL='[redacted]'
VEHICLE_ID='[redacted]'
curl --user "$TESLA_EMAIL:$VEHICLE_TOKEN" "https://streaming.vn.teslamotors.com/stream/$VEHICLE_ID/?values=speed,odometer,soc,elevation,est_heading,est_lat,est_lng,power,shift_state"

Output:
<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx</center>
</body>
</html>

And this is what I'm getting from some python that I found from February
Code:
import requests
TeslaEmail = "[redacted]"
Tesla_Streamingtoken = "[redacted]"
Tesla_vehicle_id = [redacted]
#v.wake_up()
r = requests.get("https://streaming.vn.teslamotors.com/stream/" + str(Tesla_vehicle_id) + "/?values=speed,odometer,soc,elevation,est_heading,est_lat,est_lng,power,shift_state,est_range",data={}, auth=(TeslaEmail, Tesla_Streamingtoken), stream=True)

for line in r.iter_lines():
    if line:
        print line
print "Stream end"

Output:
<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx</center>
</body>
</html>

Is anyone successfully using the streaming currently?

I've never tried myself :) ... but ... IIIRC... something something the tokens change a lot so try a bunch of the different ones you get back until one works?
 

markb1

Active Member
Feb 17, 2012
3,031
638
San Diego, CA
Anyone know what's going on with the streaming API? This is what I'm getting from what someone posted back in 2018:
Code:
VEHICLE_TOKEN='[redacted]'
TESLA_EMAIL='[redacted]'
VEHICLE_ID='[redacted]'
curl --user "$TESLA_EMAIL:$VEHICLE_TOKEN" "https://streaming.vn.teslamotors.com/stream/$VEHICLE_ID/?values=speed,odometer,soc,elevation,est_heading,est_lat,est_lng,power,shift_state"

Output:
<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx</center>
</body>
</html>

And this is what I'm getting from some python that I found from February
Code:
import requests
TeslaEmail = "[redacted]"
Tesla_Streamingtoken = "[redacted]"
Tesla_vehicle_id = [redacted]
#v.wake_up()
r = requests.get("https://streaming.vn.teslamotors.com/stream/" + str(Tesla_vehicle_id) + "/?values=speed,odometer,soc,elevation,est_heading,est_lat,est_lng,power,shift_state,est_range",data={}, auth=(TeslaEmail, Tesla_Streamingtoken), stream=True)

for line in r.iter_lines():
    if line:
        print line
print "Stream end"

Output:
<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx</center>
</body>
</html>

Is anyone successfully using the streaming currently?

I haven't had any problems with the streaming API recently. Sorry, not sure what could be wrong. The bad gateway error seems to usually be a server-side issue, but not sure why it would happen to you and not me.
 

darth_vad3r

Well-Known Sith
May 6, 2019
1,574
1,119
Canada
Hmm, I just tried exactly this:

Code:
curl --user $USERNAME:$TOKEN https://streaming.vn.teslamotors.com/stream/$VEHICLE_ID/?values=speed,odometer,soc,elevation,est_heading,est_lat,est_lng,power,shift_state

... and it seemed to work, except my vehicle is currently "offline" so I just got back:
"Vehicle is offline"

Looks the same as yours:
Code:
curl --user "$TESLA_EMAIL:$VEHICLE_TOKEN" "https://streaming.vn.teslamotors.com/stream/$VEHICLE_ID/?values=speed,odometer,soc,elevation,est_heading,est_lat,est_lng,power,shift_state"
 

darth_vad3r

Well-Known Sith
May 6, 2019
1,574
1,119
Canada
After reading this on github, I tried /connect/$VEHICLE_ID, like so:

Code:
curl --output response.dat --user $USERNAME:$TOKEN -i -N --header "Sec-WebSocket-Key: SGVsbG8sIHevcmxkIQ==" -H "Sec-WebSocket-Version: 13" -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: streaming.vn.teslamotors.com" -H "Origin: https://streaming.vn.teslamotors.com" https://streaming.vn.teslamotors.com/connect/$VEHICLE_ID

... and I get this (after filtering out some binary):

Code:
HTTP/1.1 101 Switching Protocols
Server: nginx
Date: Fri, 20 Sep 2019 02:12:17 GMT
Connection: upgrade
Upgrade: websocket
Sec-WebSocket-Accept: <base 64 string>


{
  "msg_type": "control:hello",
  "connection_timeout": 20000,
  "autopark": {
    "heartbeat_frequency": 100,
    "autopark_pause_timeout": 2000,
    "autopark_stop_timeout": 10000
  }
}
{
  "autopark_style": "dead_man",
  "msg_type": "autopark:style"
}
{
  "autopark_state": "ready",
  "autopark_state_reason": "",
  "msg_type": "autopark:status"
}
{
  "homelink_nearby": false,
  "msg_type": "homelink:status"
}
{
  "heading": 0,
  "latitude": <X>,
  "longitude": <Y>,
  "msg_type": "vehicle_data:location",
  "shift_state": "<invalid>",
  "speed": 0
}

Of note here is that on that github issue comments thread, I didn't see heading, speed, shift_state in the "vehicle_data:location" msg_type. It was only lat/long before.

Now it has more info:
Code:
{
  "heading": 0,
  "latitude": <X>,
  "longitude": <Y>,
  "msg_type": "vehicle_data:location",
  "shift_state": "<invalid>",
  "speed": 0
}

For above, my car is parked. Dunno if heading/shift/speed would fill in if I was driving. Can't try that right now.
 
Last edited:
  • Helpful
Reactions: ckoval7

brianman

Burrito Founder
Nov 10, 2011
17,515
2,980
Ah.. that's the difference. Old vs. new streaming API. The old streaming API is dead, AFAIK. The websocket (new) API is what I'm using.
And, AFAIK, that API (new streaming) doesn't work with MCU 2 cars (which includes all Model 3s). It worked fine on my pre-MCU2 S, but has never worked on our 3s.
 
Last edited:

brianman

Burrito Founder
Nov 10, 2011
17,515
2,980
Oh, and actually I thought you meant the old one. Hmm. It seemed to work on my 3? (that wasn't driving, but returned back the one data point while parked with 0 heading and speed but correct lat/long)
I tried months ago and gave up (too many projects, heh). I figured I'd wait until I saw some consistent reporting (here or otherwise) that people got it working with the 3 reliably.
 

markb1

Active Member
Feb 17, 2012
3,031
638
San Diego, CA
In my testing, the websocket streaming API works on Model 3 occasionally. But more often than not, I get no data from it. That's really weird and makes me think I'm doing something wrong. But who knows!
 

darth_vad3r

Well-Known Sith
May 6, 2019
1,574
1,119
Canada
In my testing, the websocket streaming API works on Model 3 occasionally. But more often than not, I get no data from it. That's really weird and makes me think I'm doing something wrong. But who knows!

Any recommended websocket client/tool to use? I just hit it with curl yesterday for a test, which is only good for a one-shot AFAICT.
 

About Us

Formed in 2006, Tesla Motors Club (TMC) was the first independent online Tesla community. Today it remains the largest and most dynamic community of Tesla enthusiasts. Learn more.

Do you value your experience at TMC? Consider becoming a Supporting Member of Tesla Motors Club. As a thank you for your contribution, you'll get nearly no ads in the Community and Groups sections. Additional perks are available depending on the level of contribution. Please visit the Account Upgrades page for more details.


SUPPORT TMC
Top