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.
Thanks Andy. Looks like a standard range charge and a max range charge are the same on a 40. If we can figure out how to set charge_limit_soc_max to 100, you'll have a 60 ;-)

That would be nice:smile: But, I'd be surprised if it was that simple. I think they have checks somewhere else thats causing those limits to be imposed. /vehicles shows it identifies itself as having a 40 kWh battery and not a 60. Plus, when I set it to do a range charge via the iPhone app, it immediately reverts back to "normal".

I plugged a USB keyboard into it tonight and thought I might be able to get to a console or something but the keyboard was non-responsive.

Oh well, don't think I want to brick my new car anyways....

--Andy
 
I must have missed it somewhere, but PureAmps says the odometer reading is available.

Could someone point me to that api query? Thanks.
It's part of the streaming API data. The URL looks like this:
Code:
        https://streaming.vn.teslamotors.com/stream/<vehicle_id>/?values=speed,odometer,soc,elevation,est_heading,est_lat,est_lng,power,shift_state,range,est_range

Be aware that the streaming API requires a bit more care and feeding than the other queries.
 
It's part of the streaming API data.

Be aware that the streaming API requires a bit more care and feeding than the other queries.

Yep, that is how I get the odometer data. And the streaming API definitely requires a little more effort and thought to use successfully.

I wish this data was available in the drive_state command and also displayed in the mobile app. (hint, hint to any Tesla employees reading...)
 
Yep, that is how I get the odometer data. And the streaming API definitely requires a little more effort and thought to use successfully.

I wish this data was available in the drive_state command and also displayed in the mobile app. (hint, hint to any Tesla employees reading...)
Thanks, got to work. It looks to me like the elevation is in meters. Mine says the elevation is 255, and my car is in the garage which is at around 830 feet.

I haven't actually tried it while the car is moving yet.

Second the wish to add the odometer data to the non-streaming interface.
 
All, this is an awesome thread. I am a newbie to .NET programming but am trying to the write an app in Visual C#. Based on feedback in ths thread I think I have my base code set correctly. I seem to connect ok through the portal but encounter a content length exception when I try to get vehicle information. If I provide a content length, I still get an exception. Can someone shed some light on what I am doing wrong?

Code:
Code:
class Program
{
    static void Main(string[] args)
    {
        // Set up POST parameters.
        var values = new NameValueCollection() 
        { 
            { "user_session[email]", "[email protected]" },
            { "user_session[password]", "xxxxxxxx" }
        };

        // Create a cookie jar to hold the returned cookies.
        var webClient = new WebClientWithCookies();

        // Perform the POST request.
        webClient.UploadValues("https://portal.vn.teslamotors.com/login",values);
            
        // Get the list of vehicles (using the cookies from the container above).
        webClient.Headers.Set("Content-Length", "0");
        string vehiclesResponse = webClient.DownloadString("https://portal.vn.teslamotors.com/vehicles");
        Console.WriteLine(vehiclesResponse);
        }
    }

class WebClientWithCookies : WebClient
{
    private CookieContainer _container = new CookieContainer();

    protected override WebRequest GetWebRequest(Uri address)
    {
        HttpWebRequest request =
           base.GetWebRequest(address) as HttpWebRequest;

        if (request != null)
        {
            request.Method = "Post";
            request.CookieContainer = _container;
        }

        return request;
    }
}
 
you might try creating a separate WebClientWithCookies, but share the cookiecontainer instance between the two, and you shouldn't need the content-length. that's the only difference I see from code where I used to use WebClient (that and I didn't use UploadValues but manually set post & the ContentType). Also you might need / at the end of vehicles in your query url, my queries have it.

if you still have problems, try using fiddler to see whats happening.
 
Has anyone else noticed the REST api not returning data from a climate_state call with their car? It seems if my car sits for a while it will stop returning this data (it occurs both with ahimberg's Win Phone app, and via direct PowerShell calls to the API). Doing a call to turn AC on will cause the car to start returning data again, but that's a pain.
 
Has anyone else noticed the REST api not returning data from a climate_state call with their car? It seems if my car sits for a while it will stop returning this data (it occurs both with ahimberg's Win Phone app, and via direct PowerShell calls to the API). Doing a call to turn AC on will cause the car to start returning data again, but that's a pain.

Yup. I see that all the time. The climate data is very consistently missing (returns "null" data) after the car sits parked for a while.
 
Has anyone else noticed the REST api not returning data from a climate_state call with their car? It seems if my car sits for a while it will stop returning this data (it occurs both with ahimberg's Win Phone app, and via direct PowerShell calls to the API). Doing a call to turn AC on will cause the car to start returning data again, but that's a pain.

I've noticed this in the iOS app as well...
 
Well, good that it's not just my car, annoying that it's a bug. Anybody reported it yet? And is there a good way to report this kind of issue, or just general emails to ownership?

I didn't think this was a bug so I didn't report it. I just thought that the car was shutting down the HVAC system (like a HVAC sleep mode) and therefore the temperature sensors were no longer accessible.
 
I didn't think this was a bug so I didn't report it. I just thought that the car was shutting down the HVAC system (like a HVAC sleep mode) and therefore the temperature sensors were no longer accessible.
That was my interpretation as well. Similarly, when the vehicle is "off" things like shift_state and speed become null.
 
I didn't think this was a bug so I didn't report it. I just thought that the car was shutting down the HVAC system (like a HVAC sleep mode) and therefore the temperature sensors were no longer accessible.

Possible I guess, but in my testing it's not as simple as "once off stays off" - my temp readings seem to come and go throughout the day, with no interaction from me other than querying the state of the car.
 
I didn't think this was a bug so I didn't report it. I just thought that the car was shutting down the HVAC system (like a HVAC sleep mode) and therefore the temperature sensors were no longer accessible.

This probably explains why the Android app often doesn't display the internal cabin temp. I reported this in the "app" thread a while back.

I've found that if I pop over to the "controls" page of the app and toggle the sunroof vent to a different state, then I start getting cabin temp again... so it doesn't seem to be strictly tied to the HVAC system state.
 
Possible I guess, but in my testing it's not as simple as "once off stays off" - my temp readings seem to come and go throughout the day, with no interaction from me other than querying the state of the car.

Same for me. I always get the climate setting returned, but the interior and exterior temp sensor readings come and go. Must be on a circuit with other stuff that wakes up from time to time for some reason. Sending a "wake up" REST request doesn't wake up any of the temperature sensors. The funny thing is that it always knows if the rear defroster is on, but when it "sleeps" it doesn't know if the front defroster is on.