API Oauth question


#1

I don’t understand how to implement based on this statement:

“Your authorization code is valid for one POST call. Before each POST call, get a new authorization code. To do this, reload your authorization URL. Then change the POST’s code= field to include the new authorization code.”

For my second and subsequent API calls, if I reload the authorization URL, I’m redirected to the Works With Nest sign-in/Accept page. How do I get a new authorization code, in order to get a token, without having to login/accept with each API call?

Thanks, Len


#2

Please see the following documentation on using OAuth 2.0.

https://developers.nest.com/documentation/cloud/how-to-auth

After logging in to the Works with Nest sign-in page, you will be returned and authorization code. This code is then exchanged for an access token. Once you have an access token, that token is used for all subsequent API calls and is valid until the access is revoked, or removed, for that token.


#3

Thanks Lionel, that makes total sense to me, but doesn’t this statement mean that you need to get a new auth code / access token per call?

https://developers.nest.com/documentation/cloud/how-to-auth/

“Your authorization code is valid for one POST call. Before each POST call, get a new authorization code. To do this, reload your authorization URL. Then change the POST’s code= field to include the new authorization code.”


#4

Authorization codes are short lived and are only used to exchange for an access token. The access token is what you will use when making API calls to get device, structure, etc. data. Access tokens are long lived, e.g. until revoked.


#5

I’m also working on the authorization and think I have the codes correct, but for the life of me can’t find the thermostat ID’s?


#6

I’m not 100% sure, but I think that the IDs are in the returned structure, marked ID Here

[structures] => Array
(
[jqUuZdw2ze07UqHkreLSMdzjhuGlqdG_qjcp8r2AvPBqARl89ugT8A] => Array
(
[smoke_co_alarms] => Array
(
[0] => *smoke_co_alarm ID HERE
)

                [name] => name
                [country_code] => US
                [time_zone] => America/Chicago
                [away] => home
                [thermostats] => Array
                    (
                        [0] => **first thermostat ID HERE**
                        [1] => **second thermostat ID HERE**
                    )

                [structure_id] => jqUuZdw2ze07UqHkreLSMdzjhuGlqdG_qjcp8r2AvPBqARl89ugT8A
                [rhr_enrollment] => 
                [co_alarm_state] => ok
                [smoke_alarm_state] => ok
                [eta_begin] => 1970-01-01T00:00:00.000Z

#7

You should also be able to get the ID’s by making a call to /devices