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.
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
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?
 
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?
 
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.
 
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"
 
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
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.