Sponsored

Rivian API

staples

Well-Known Member
Joined
Jul 12, 2020
Threads
4
Messages
305
Reaction score
543
Location
Chicago, IL
Vehicles
R1T, Zero FXS, Tesla Y
Clubs
 
API seems to be working just fine for my lazy curl based integration to Home Assistant.
Sponsored

 

OverZealous

Well-Known Member
Joined
Oct 19, 2021
Threads
8
Messages
592
Reaction score
1,477
Location
Louisville, Kentucky
Vehicles
2022 R1T LE, 2023 R1S Quad-Adventure
Occupation
Product Manager / Front-End Developer
Clubs
 
API seems to be working just fine for my lazy curl based integration to Home Assistant.
Tell me more! What have you integrated into HA so far?
 

travbz814

Well-Known Member
Joined
May 24, 2022
Threads
6
Messages
105
Reaction score
46
Location
Iowa
Vehicles
R1T, M3P
Clubs
 
Rivian R1T R1S Rivian API Screen Shot 2022-06-15 at 11.26.37 AM


Python experts - running into this error after loading into pycharm. I've enabled the .env with my credentials. Any thoughts or guidance?

thanks!
 

godfodder0901

Well-Known Member
First Name
Jared
Joined
Mar 12, 2019
Threads
27
Messages
5,749
Reaction score
10,139
Location
Washington
Vehicles
2022 Rivian R1T LE
Screen Shot 2022-06-15 at 11.26.37 AM.png


Python experts - running into this error after loading into pycharm. I've enabled the .env with my credentials. Any thoughts or guidance?

thanks!
EDIT: Last post was before I found the source code..

Have you run through in debug mode to see if the dotenv_values are loaded into conf? Make sure that you place your username and password in quotes?
 

staples

Well-Known Member
Joined
Jul 12, 2020
Threads
4
Messages
305
Reaction score
543
Location
Chicago, IL
Vehicles
R1T, Zero FXS, Tesla Y
Clubs
 
Looks like it is not loading your `.env` file. Check that it is on the same directory as your script. But it might be that pycharm is running the script from another location, possibly your home directory and the `.env` needs to be there instead.
 

Sponsored

travbz814

Well-Known Member
Joined
May 24, 2022
Threads
6
Messages
105
Reaction score
46
Location
Iowa
Vehicles
R1T, M3P
Clubs
 
The .env is in the same directory and the credentials are in quotes. Not sure where/why it's failing.

As a temp workaround I just wrote my credentials into the script. See any harm in doing so?
 

boardthatpowder

Well-Known Member
First Name
Dean
Joined
Sep 10, 2021
Threads
5
Messages
143
Reaction score
155
Location
CO
Vehicles
Rivian R1T, Audi Q5
Rivian R1T R1S Rivian API screen-shot-2022-06-15-at-11-26-37-am-


Python experts - running into this error after loading into pycharm. I've enabled the .env with my credentials. Any thoughts or guidance?
I recognize that code (disclaimer it's mine ;) ).

Try renaming `environment.env` to just `.env`.
 

travbz814

Well-Known Member
Joined
May 24, 2022
Threads
6
Messages
105
Reaction score
46
Location
Iowa
Vehicles
R1T, M3P
Clubs
 
I recognize that code (disclaimer it's mine ;) ).

Try renaming `environment.env` to just `.env`.
No dice. Might be a Mac thing, but it doesn't see the file as just .env. In Finder it moves it to a hidden file. When mapping to it PyCharm Config it showing up to connect it.
 

boardthatpowder

Well-Known Member
First Name
Dean
Joined
Sep 10, 2021
Threads
5
Messages
143
Reaction score
155
Location
CO
Vehicles
Rivian R1T, Audi Q5
No dice. Might be a Mac thing, but it doesn't see the file as just .env. In Finder it moves it to a hidden file. When mapping to it PyCharm Config it showing up to connect it.
Here's a screenshot of mine (Pycharm on Mac):

Rivian R1T R1S Rivian API Screen Shot 2022-06-15 at 1.22.23 PM


`.env` is the default filename that the dotenv library will load. If you rename it to anything else then you need to change L9 to something like `conf = dotenv_values("environment.env")`.
 

travbz814

Well-Known Member
Joined
May 24, 2022
Threads
6
Messages
105
Reaction score
46
Location
Iowa
Vehicles
R1T, M3P
Clubs
 
Here's a screenshot of mine (Pycharm on Mac):

Screen Shot 2022-06-15 at 1.22.23 PM.webp


`.env` is the default filename that the dotenv library will load. If you rename it to anything else then you need to change L9 to something like `conf = dotenv_values("environment.env")`.
That fixed it! Gracias sir!
 
Last edited:

Sponsored

travbz814

Well-Known Member
Joined
May 24, 2022
Threads
6
Messages
105
Reaction score
46
Location
Iowa
Vehicles
R1T, M3P
Clubs
 
Rivian R1T R1S Rivian API Screen Shot 2022-06-15 at 2.39.10 PM


If my questions are annoying due to lack of knowledge feel free to tell me to F off.

Got the Twilio info added. Will it only text if something changes? And is it watching for all the fields?

I used to have a vehicleID but it got null'd out last week. Eager to see something show up there again.
 

boardthatpowder

Well-Known Member
First Name
Dean
Joined
Sep 10, 2021
Threads
5
Messages
143
Reaction score
155
Location
CO
Vehicles
Rivian R1T, Audi Q5
Got the Twilio info added. Will it only text if something changes? And is it watching for all the fields?
yes and yes. It simply compares the full json response to its last known one, and if Theres a difference it will text the full latest response.
 

boardthatpowder

Well-Known Member
First Name
Dean
Joined
Sep 10, 2021
Threads
5
Messages
143
Reaction score
155
Location
CO
Vehicles
Rivian R1T, Audi Q5

atlastracer

Well-Known Member
Joined
Sep 30, 2019
Threads
7
Messages
367
Reaction score
409
Location
BC, Canada
Vehicles
R1S LE, Honda Pilot
If you are using the (fantastic) script that @boardthatpowder provided....but you have more than 1 pre-order (or you have a cancelled and re-instated pre-order). I made some modifications to make it show multiple orders. Hopefully the notes below can help someone out.

Code:
# Modified get_order_status to return all orderSnapshots, I also added some additional data
# from the order items so I could see whether it was my R1S or R1T order
def get_order_statuses(csrf_token, a_sess, u_sess):
    headers = {
        'Content-Type': CONTENT_TYPE,
        'dc-cid': DC_CID,
        'csrf-token': csrf_token,
        'a-sess': a_sess,
        'u-sess': u_sess
    }
    payload = "{\"query\":\"query {\\n\\tuser {\\n  \\t\\torderSnapshots (filterTypes: [PRE_ORDER, VEHICLE, RETAIL]) {\\n\\t\\t    id\\n\\t\\t    state\\n\\t\\t    configurationStatus\\n\\t\\t    fulfillmentSummaryStatus\\n\\t\\t    vehicleId\\n  \\t\\titems {\\n      id\\n      total\\n      unitPrice\\n      quantity\\n      productDetails {\\n      ... on VehicleProduct {\\n      sku\\n      store {\\n      country\\n      __typename\\n      }\\n      __typename\\n      }\\n      }\\n      }}  \\n\\t}\\n}\\n\",\"variables\":{}}"
    response = session.post(url=GQL_ORDERS_URL, headers=headers, data=payload)
    if response.status_code != 200:
        print(response)
    return response.json()['data']['user']['orderSnapshots']
    
# I modified the def single_status_check(): method:
def single_status_check():
    access_token, refresh_token = create_session()
    csrf_token = create_csrf_token()
    a_sess, u_sess = create_graph_session(csrf_token, access_token, refresh_token)
    order_statuses = get_order_statuses(csrf_token, a_sess, u_sess)
    dt_string = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
    
    for order_status in order_statuses:
        vehicle_type = "Unkown"
        for each_item in order_status['items']:
            if 'sku' in each_item['productDetails']:
                vehicle_type = each_item['productDetails']['sku']

        order_status_message = "{}:\n\tvehicle: {}\n\tstate: {}\n\tconfigurationStatus: {}\n\tfulfillmentSummaryStatus: {}\n\tvehicleId: {}".format(
            dt_string,
            vehicle_type,
            order_status['state'],
            order_status['configurationStatus'],
            order_status['fulfillmentSummaryStatus'],
            order_status['vehicleId'])
        print(order_status_message)
        
    # note: I didn't fix up the last_order_status stuff to support multi-orders yet
    #         Nor did I tackle the 8-step as I am no where near that.
Sponsored

 
 








Top