This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Simple HTTP - Tesla API
#6
Hi,

The function GetToken() does a request to the API with your credentials and returns the Bearer Token so you don't have to look it up all the time. Its returned in the table 'ret' inside de function, i think the field is access_token but you need to check that by adding log(ret) in the function to see what fields are returned. the variable API_Token should be automatically filled with a valid token and will be used in the further API requests. (is already include in the other functions as Authorization header so you dont need to change anything)

The function RequestFromTesla(request) should be used for all GET requests and the static part of the URL is already included to the function so you only have to pass the latest part of the URL as request variable so RequestFromTesla("products") will actually request the URL https://owner-api.teslamotors.com/api/1/products and returns the response as a table where all your Tesla product should be listed. I think the ID is also a field in this returned table that you could use in next requests as variable as 'product.id'

The function WriteToTesla(request) should be used for all POST commands and here is also the static part of the URL already included to the function, here you also only need to pass the latest part of the URL as request variable and returns the response as table (probably returns 'success' or something)

So with these 3 functions you should be able to request the token, request data and write data from/to the vehicle.

Basically you only need to set your username & passwords and use the 2 functions RequestFromTesla(request) + WriteToTesla(request) to exchange data with your car. 

Succes!

BR,

Erwin
Reply


Messages In This Thread
Simple HTTP - Tesla API - by Mr.D - 13.12.2018, 19:35
RE: Simple HTTP - Tesla API - by Mr.D - 13.12.2018, 19:59
RE: Simple HTTP - Tesla API - by Mr.D - 14.12.2018, 15:19
RE: Simple HTTP - Tesla API - by Erwin van der Zwart - 14.12.2018, 20:04
RE: Simple HTTP - Tesla API - by Mr.D - 27.01.2019, 12:04
RE: Simple HTTP - Tesla API - by admin - 10.01.2020, 09:21
RE: Simple HTTP - Tesla API - by alexgleyzer - 26.05.2020, 07:38
RE: Simple HTTP - Tesla API - by admin - 26.05.2020, 08:19
RE: Simple HTTP - Tesla API - by alexgleyzer - 26.05.2020, 10:35
RE: Simple HTTP - Tesla API - by admin - 26.05.2020, 11:14
RE: Simple HTTP - Tesla API - by alexgleyzer - 27.05.2020, 06:34

Forum Jump: