> ## Documentation Index
> Fetch the complete documentation index at: https://docs.seam.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Get started with ControlByWeb Devices

> Learn how to connect and control your ControlByWeb device with the Seam API.

export const DeviceList = ({manufacturers, capabilityName, token = "6c51f0a4-d421-429e-8295-d02271aa4f23"}) => {
  const cdn = "https://cdn.devicedb.seam.co/v/0.0.15/DeviceListByCapability.global.js";
  const close = "</scr" + "ipt>";
  const srcDoc = ['<!doctype html><html><head><meta charset="utf-8">', "<style>html,body{margin:0;padding:0;background:transparent}</style></head><body>", `<script type="module" src="${cdn}">${close}`, `<device-list-by-capability manufacturers="${manufacturers}" capability-name="${capabilityName}" token="${token}"></device-list-by-capability>`, `<script>new ResizeObserver(function(){parent.postMessage({__devicedb:true,height:document.documentElement.scrollHeight},"*")}).observe(document.documentElement)${close}`, "</body></html>"].join("");
  const onRef = iframe => {
    if (!iframe || iframe.dataset.devicedbBound) return;
    iframe.dataset.devicedbBound = "1";
    window.addEventListener("message", event => {
      if (event.source === iframe.contentWindow && event.data && event.data.__devicedb) {
        iframe.style.height = `${event.data.height}px`;
      }
    });
  };
  return <iframe ref={onRef} srcDoc={srcDoc} title="Compatible devices" style={{
    width: "100%",
    minHeight: "320px",
    border: "none"
  }} />;
};

<img src="https://strapi-media-bucket.fly.storage.tigris.dev/sq_controlbyweb_c67fb17fa0.svg" alt="ControlByWeb logo" width="192" height="192" style={{ width: "192px", height: "192px", objectFit: "contain" }} />

<img src="https://mintcdn.com/seam/GnR-zBVMHFed214Q/images/guides/controlbyweb-getting-started-guide-cover.jpg?fit=max&auto=format&n=GnR-zBVMHFed214Q&q=85&s=be32cf821f9c05bbdc6f47cb0210265f" alt="ControlByWeb Devices" width="2400" height="1260" data-path="images/guides/controlbyweb-getting-started-guide-cover.jpg" />

## Overview

Seam provides a universal API to connect and control many brands of smart devices. This guide provides a rapid introduction to connecting and controlling your [ControlByWeb](https://www.seam.co/manufacturers/controlbyweb) relay device using the Seam API. To learn more about other smart device brands supported by Seam such as Yale, Schlage, and August, head over to our [integration page](https://www.seam.co/supported-devices-and-systems).

## 1 — Install Seam SDK

Seam provides client libraries for many languages, such as JavaScript, Python, Ruby, PHP, and others, as well as a Postman collection and [OpenAPI](https://connect.getseam.com/openapi.json) spec.

* JavaScript / TypeScript ([npm](https://www.npmjs.com/package/seam), [GitHub](https://github.com/seamapi/javascript))
* Python ([pip](https://pypi.org/project/seam/), [GitHub](https://github.com/seamapi/python))
* Ruby Gem ([rubygem](https://rubygems.org/gems/seam), [GitHub](https://github.com/seamapi/ruby))
* PHP ([packagist](https://packagist.org/packages/seamapi/seam), [GitHub](https://github.com/seamapi/php))
* C# ([nuget](https://www.nuget.org/packages/Seam), [GitHub](https://github.com/seamapi/csharp))

<Tabs>
  <Tab title="JavaScript">
    ```bash theme={null}
    npm i seam
    ```
  </Tab>

  <Tab title="Python">
    ```bash theme={null}
    pip install seam
    # For some development environments, use pip3 in this command instead of pip.
    ```
  </Tab>

  <Tab title="Ruby">
    ```bash theme={null}
    bundle add seam
    ```
  </Tab>

  <Tab title="PHP">
    ```bash theme={null}
    composer require seamapi/seam
    ```
  </Tab>

  <Tab title="C#">
    Install using [nuget](https://www.nuget.org/packages/Seam).
  </Tab>
</Tabs>

Once installed, [sign-up for Seam](https://console.seam.co/) to get your API key, and export it as an environment variable:

```
$ export SEAM_API_KEY=seam_test2ZTo_0mEYQW2TvNDCxG5Atpj85Ffw
```

<Info>
  This guide uses a Sandbox Workspace. Only virtual devices can be connected. If
  you need to connect a real ControlByWeb device, use a non-sandbox workspace
  and API key.
</Info>

## 2 — Link ControlByWeb Account with Seam

To control your ControlByWeb relay device via the Seam API, you must first authorize your Seam workspace against your ControlByWeb Cloud account. To do so, Seam provides[ Connect Webviews](/core-concepts/connect-webviews): pre-built UX flows that walk you through authorizing your application to control your ControlByWeb device.

#### Request a Connect Webview

<CodeGroup>
  ```javascript JavaScript theme={null}
  import { Seam } from 'seam'

  const seam = new Seam()

  const connectWebview = await seam.connectWebviews.create({
    accepted_providers: ['controlbyweb'],
  })

  console.log(connectWebview.login_successful) // false

  // Send the webview URL to your user
  console.log(connectWebview.url)
  ```

  ```python Python theme={null}
  from seam import Seam

  seam = Seam()

  webview = seam.connect_webviews.create(accepted_providers=["controlbyweb"])

  assert webview.login_successful is False

  # Send the webview URL to your user
  print(webview.url)
  ```

  ```ruby Ruby theme={null}
  require "seam"

  seam = Seam.new(api_key: "MY_API_KEY")

  webview = seam.connect_webviews.create(
    accepted_providers: ["controlbyweb"]
  )

  puts webview.login_successful # false

  # Send the webview URL to your user
  puts webview.url
  ```
</CodeGroup>

#### Authorize Your Workspace

Navigate to the URL returned by the Webview object. Since you are using a sandbox workspace, complete the login flow by entering the ControlByWeb [sandbox test account](/device-and-system-integration-guides/controlbyweb-relays/controlbyweb-relays-sample-data) credentials below:

* **username:** jane
* **password:** 1234

<img src="https://mintcdn.com/seam/GnR-zBVMHFed214Q/images/guides/controlbyweb-connect-flow-screens.jpg?fit=max&auto=format&n=GnR-zBVMHFed214Q&q=85&s=c8afe56eddfd6077efbc38f72863f061" alt="Seam Connect Webview flow to connect ControlByWeb account with Seam" width="3372" height="1897" data-path="images/guides/controlbyweb-connect-flow-screens.jpg" />

Confirm the Connect Webview was successful by querying its status:

<CodeGroup>
  ```javascript JavaScript theme={null}
  const updatedWebview = await seam.connectWebviews.get(
    connectWebview.connect_webview_id,
  )

  console.log(updatedWebview.login_successful) // true
  ```

  ```python Python theme={null}
  updated_webview = seam.connect_webviews.get(connect_webview_id: webview.connect_webview_id)

  assert updated_webview.login_successful # true
  ```

  ```ruby Ruby theme={null}
  updated_webview = seam.connect_webviews.get(connect_webview_id: webview.connect_webview_id)

  puts updated_webview.login_successful # true
  ```
</CodeGroup>

## 3 — Retrieve ControlByWeb devices

After a ControlByWeb account is linked with Seam, you can retrieve devices for this ControlByWeb account. The main device property currently exposed by the Seam API is whether the device is online and reachable.

<CodeGroup>
  ```javascript JavaScript theme={null}
  const allLocks = await seam.locks.list()

  const someLock = allLocks[0]

  console.log(someLock.properties.online) // true
  console.log(someLock.properties.locked) // true

  console.log(someLock)
  /*
  {
    device_id: '4a570d13-9704-46e0-b69c-9fea80d6a7aa',
    device_type: 'controlbyweb_device',
    capabilities_supported: [ 'lock' ],
    properties: {
      locked: true,
      online: true,
      manufacturer: 'controlbyweb',
      controlbyweb_metadata: {
        device_id: '9997',
        relay_name: 'firstRelay',
        device_name: 'Device 2'
      },
      name: 'Device 2',
      image_url: 'https://connect.getseam.com/assets/images/devices/unknown-lock.png',
      image_alt_text: 'Placeholder Lock Image'
    },
    location: null,
    connected_account_id: '5e0f49ac-3cb5-4e81-8c74-aba262218611',
    workspace_id: '40a179ca-3553-4226-9483-21df4e12f5fe',
    created_at: '2023-04-25T14:34:50.508Z',
    errors: [],
    warnings: []
  }
  */
  ```

  ```python Python theme={null}
  all_locks = seam.locks.list()

  some_lock = all_locks[0]

  assert some_lock.properties["online"] is True
  assert some_lock.properties["locked"] is True

  print(some_lock)
  # Device(
  #   device_id='4a570d13-9704-46e0-b69c-9fea80d6a7aa',
  #   device_type='controlbyweb_device',
  #   location=None,
  #   properties={
  #     'locked': True,
  #     'online': True,
  #     'manufacturer': 'controlbyweb',
  #     'controlbyweb_metadata': {
  #       'device_id': '9997',
  #       'relay_name': 'firstRelay',
  #       'device_name': 'Device 2'
  #     },
  #     'name': 'Device 2',
  #     'image_url': 'https://connect.getseam.com/assets/images/devices/unknown-lock.png',
  #     'image_alt_text': 'Placeholder Lock Image'
  #   },
  #   capabilities_supported=['lock'],
  #   errors=[]
  # )
  ```

  ```ruby Ruby theme={null}
  some_lock = seam.locks.list.first

  puts some_lock.properties.online # true
  puts some_lock.properties.locked # true

  puts some_lock.inspect
  # <Seam::Device:0x00146639380
  #   device_id="4a570d13-9704-46e0-b69c-9fea80d6a7aa"
  #   device_type="controlbyweb_device"
  #   properties={
  #     "locked"=>true,
  #     "online"=>true,
  #     "manufacturer"=>"controlbyweb",
  #     "controlbyweb_metadata"=>{
  #       "device_id"=>"9997",
  #       "relay_name"=>"firstRelay",
  #       "device_name"=>"Device 2"
  #     },
  #     "name"=>"Device 2",
  #     "image_url"=>"https://connect.getseam.com/assets/images/devices/unknown-lock.png",
  #     "image_alt_text"=>"Placeholder Lock Image"
  #   }
  #   created_at=2023-04-25 14:34:50 UTC
  #   errors=[]
  #   warnings=[]
  ```
</CodeGroup>

**4 — Triggering a ControlByWeb relay**

Next, you can perform the basic action of triggering a relay on the device. This action is mapped to an unlock API call in Seam.

#### Unlock a door

<mark style={{ color: 'green' }}>`POST`</mark>
`https://connect.getseam.com/locks/unlock_door`

**Request Body**

| Name       | Type   | Description |
| ---------- | ------ | ----------- |
| device\_id | String |             |

<CodeGroup>
  ```javascript JavaScript theme={null}
  // trigger the relay
  await seam.locks.unlockDoor(someLock.device_id)
  ```

  ```python Python theme={null}
  # trigger the relay
  seam.locks.unlock_door(some_lock)
  ```

  ```ruby Ruby theme={null}
  # trigger the relay
  seam.locks.unlock_door(device_id: some_lock.device_id)
  ```
</CodeGroup>

## Next Steps

Now that you've completed this guide, you can try to connect a real ControlByWeb device. To do so, make sure to switch to a non-sandbox workspace and API key as real devices cannot be connected to sandbox workspaces.

In addition, if you'd like to explore other aspects of Seam, here is a list of helpful resources:

* [Yale Getting Started Guide](../yale-locks/get-started-with-yale-locks)
* [August Getting Started Guide](../august-locks/get-started-with-august-locks)
* [Schlage Getting Started Guide](../schlage-locks/get-started-with-schlage-locks)
* [SmartThings Getting Started Guide](../smartthings-hubs-+-devices/get-started-with-smartthings-hubs-+-smart-locks)
* [Minut Getting Started Guide](../minut-sensors/get-started-with-minut-sensors)
* [Receiving webhook](/developer-tools/webhooks) for [device events](/api/events/list)
* [Core Concepts](/core-concepts/overview)

If you have any questions or want to report an issue, email us at [support@seam.co](mailto:support@seam.co).

## Supported Devices

<DeviceList manufacturers="controlbyweb" capabilityName="can_remotely_unlock" />
