Getting Devices in all Sub-accounts
We often are asked, How do I get all the devices in all of my sub-accounts? This could be because they want to check on the status of all of the devices, or it could be that they are trying to match up this data with another data source. This is a great question and this article will help answer the question.
We will assume that you have a valid Eagle Eye user and that it is part of a reseller account. We will also assume that you have been permission to access at least one sub-account that contains devices. As a reseller you known that devices such as bridges, cameras, and switches do not exist at the reseller level but instead live in sub-accounts.
Step 1: Login as a user in the reseller account.
Step 2: Get a List of Sub-accounts
You can get a list of the all the sub-accounts using the Get List of Accounts API call. This call with return all of the accounts that your user has access to. You can only call this API when you are in the context of the reseller account. In future steps you will switch into one of these other accounts so please take care to be in the reseller context when making this call.
Step 3: Switch Your User Account
Users have two properties on their user object returned by the Get User endpoint. The account that owns your account (ie the reseller you belong to) is the `owner_account_id`. In order for a user to see what is going on in a sub-account they need to change the account context. The curent account context is stored in the `active_account_id`.
You can change your account context by usign the Switch Account API. Please note that you can switch back to the reseller context by calling it with your `owner_account_id` or with an empty string.
Step 4: Get List of Devices
When you are in the context of a sub-account you are able to Get List of Devices as if you were a user in that sub-account. You can also retrieve images and video or subscribe to the poll stream. Using the switch account API provides great functionality when using sub-accounts.
Step 5: Repeat for Each Sub-account
For each sub-account you can follow this same procedure to iterate through each sub-account. Please note that if you are subscribing to the poll stream for devices in the sub-account you will need to maintain that connection while inside the context of the sub-account. This means you can not switch out of the sub-account without the connection closing. You would need to start multiple sessions by logging-in again as a reseller and maintaining a separate cookie/session.
What else can we do with this?
This is a very common questions once API users start dealing with a large number of cameras. This can be used to monitor the status of all the cameras, switches, and bridges. It can also be used to track motion events across different locations. A great example would be counting motion events on all the front door cameras across all locations.
If you have questions please feel free to reach out to me directly at firstname.lastname@example.org