How to turn camera on and off from rest api


#1

From the documentation there is a section is streaming that states

Is streaming
Use the is_streaming field to turn the camera on or off.

Depending on the user’s home network and your implementation, there may be a lag in response time
You must ask the user if it’s ok to change streaming status (turn the camera on/off)

However the documentation does not provide an example of how to do this. How do you turn the camera on and off with is_streaming field.


#2

Use a PUT request to update the is_streaming field to true or false.


#3

Do I use the whole camera object or can I just use one field?

for example

{
  "is_streaming":true
}

vs

{
  "devices":{
    "cameras":{
      "myCameraId":{
        "is_streaming":true,
        "other_field":"other_value",
        "etc":"etc",...
      }
    }
  }
}

#4

It will depend on what structure you’re using for your URL, but you don’t need the whole thing.

Two main options would be to make a PUT call to:

URL
https://developer-api.nest.com/devices/cameras/<camera_id>?auth=<token>

Payload
{"is_streaming":true}

Or

URL
https://developer-api.nest.com/devices/cameras/<camera_id>/is_streaming?auth=<token>

Payload
true


#5

Also, please keep in mind that any changes to the camera streaming state requires a user confirmation or explicit action by a user.

https://developers.nest.com/documentation/cloud/how-to-cameras-object#is-streaming

Also, please avoid placing the authorization as a query parameter in the URL. The preferred way to pass the authorization is as a Bearer token in the request header.

https://developers.nest.com/documentation/cloud/how-to-read-data#bearer-authentication


#6

I’m making the call to the url with the python “requests” library in this instance. From what I’ve read, you are required to put the authentication token as a query parameter in the URL for it to work. I initially attempted to add the token as a header but frequently received 401 responses back. Do you know of a way to make a request from python with the authentication token in the header?


#7

Most likely the problem you are having is that the authorization header is being removed upon redirect, thus causing the authorization failure.

https://developers.nest.com/documentation/cloud/data-rate-limits#handling-307-redirects
http://docs.python-requests.org/en/master/user/quickstart/#custom-headers

Here’s a discussion about this issue with Python.