Seam provides a universal API to connect and control many brands of IoT devices and systems, including smart locks, access control systems (ACSs), thermostats, and noise sensors.
This guide gives you a rapid introduction to connecting and controlling your TTLock lock using the Seam API. For application developers, you can use the Seam API in your app, and your users can authorize your app to control their devices using Seam.
Seam supports the following TTLock locks:
To learn more about other IoT device and system brands that Seam supports—such as Yale, Schlage, Google Nest, and many more—visit our integration page.
This guide shows you how to install a Seam SDK and then control your TTLock lock using the Seam API.
Another easy way to learn about what you can do with the Seam API is to explore the interactive Seam CLI, which you can access from directly within the Seam Console.
Seam provides client libraries for many languages, including JavaScript, Python, Ruby, PHP, and others, as well as a Postman collection and an OpenAPI spec.
This guide uses a sandbox workspace. You can only connect virtual devices and systems in this type of workspace. If you want to connect a real TTLock lock, use a non-sandbox workspace and API key.
Step 2: Link your TTLock account with Seam
To control your TTLock lock using the Seam API, you must first authorize your Seam workspace to connect to your TTLock account. If your application needs to connect to your users' TTLock accounts, Seam provides fully-embedded, customizable client-side Connect Webviews to collect their authorization securely. These user-friendly pre-built authorization flows walk your users through the process of granting your Seam workspace permission to control their TTLock locks. The Connect Webview presents a flow that prompts your users to enter their credentials for their TTLock account.
In this guide, you create a Connect Webview object. Then, you display the graphical component of the created Connect Webview and enter a set of sample credentials to connect a sandbox TTLock account.
This guide shows you how to create a Connect Webview programmatically using the Seam API.
The Seam Console provides another easy way to connect devices to your Seam workspace.
Create a connect_webview object and then note the returned URL.
Code:
from seam import Seamseam =Seam()# Seam automatically uses your exported SEAM_API_KEY.connect_webview = seam.connect_webviews.create(accepted_providers=["ttlock"])assert connect_webview.login_successful isFalse# Use the returned Connect Webview URL to display# the Connect Webview authorization flow to your user.print(connect_webview.url)
import { Seam } from"seam";constseam=newSeam(); // Seam automatically uses your exported SEAM_API_KEY.constconnectWebview=awaitseam.connectWebviews.create({ accepted_providers: ['ttlock']});console.log(connectWebview.login_successful); // false// Use the returned Connect Webview URL to display// the Connect Webview authorization flow to your user.console.log(connectWebview.url);
require"seamapi"seam =Seam::Client.new() # Seam automatically uses your exported SEAM_API_KEY.connect_webview = seam.connect_webviews.create( accepted_providers: ["ttlock"])puts connect_webview.login_successful # false# Use the returned Connect Webview URL to display# the Connect Webview authorization flow to your user.puts connect_webview.url
<?phprequire'vendor/autoload.php';$seam =newSeam\SeamClient(); // Seam automatically uses your exported SEAM_API_KEY.$connect_webview = $seam->connect_webviews->create( accepted_providers: ["ttlock"]);echo $connect_webview->login_successful ?'true':'false',"\n"; // false// Use the returned Connect Webview URL to display// the Connect Webview authorization flow to your user.echo $connect_webview->url;
usingSeam.Client;var seam =newSeamClient(apiToken: SEAM_API_KEY);var connectWebview =seam.ConnectWebviews.Create( acceptedProviders:new() {Seam.Api.ConnectWebviews.CreateRequest.AcceptedProvidersEnum.Ttlock});Console.WriteLine(connectWebview.LoginSuccessful); // False// Use the returned Connect Webview URL to display// the Connect Webview authorization flow to your user.Console.WriteLine(connectWebview.Url);
importjava.io.Console;importjava.util.*;importcom.fasterxml.jackson.annotation.*;importcom.fasterxml.jackson.databind.annotation.JsonDeserialize;importcom.seam.api.Seam;importcom.seam.api.core.ObjectMappers;importcom.seam.api.types.ConnectWebview;importcom.seam.api.types.Device;importcom.seam.api.types.Manufacturer;importcom.seam.api.types.ActionAttempt;importcom.seam.api.types.AccessCode;importcom.seam.api.resources.connectwebviews.requests.ConnectWebviewsCreateRequest;importcom.seam.api.resources.connectwebviews.requests.ConnectWebviewsGetRequest;importcom.seam.api.resources.devices.requests.DevicesListRequest;importcom.seam.api.resources.devices.requests.DevicesGetRequest;importcom.seam.api.resources.locks.requests.LocksUnlockDoorRequest;importcom.seam.api.resources.accesscodes.requests.AccessCodesCreateRequest;importcom.seam.api.resources.accesscodes.requests.AccessCodesListRequest;publicclassMain {publicstaticvoidmain(String[] args) {Seam seam =Seam.builder().apiKey(SEAM_API_KEY).build();ConnectWebview connectWebview =seam.connectWebviews().create(ConnectWebviewsCreateRequest.builder().acceptedProviders(List.of(AcceptedProvider.TTLOCK)).build());System.out.println(connectWebview.getLoginSuccessful()); // false// Use the returned Connect Webview URL to display// the Connect Webview authorization flow to your user.System.out.println(connectWebview.getUrl()); }}
In a web browser, go to the URL that the Connect Webview object returned.
For application developers, you can redirect your user to this Connect Webview URL so that they can authorize your app to control their devices using Seam. We even provide a prebuilt Connect Account Button within our suite of Seam Components that help you build your device management flow.
Because you're using a sandbox workspace, you can connect Seam's test TTLock account. We provide virtual devices for each of the brands that we support. These sandbox devices and systems enable you to test your app with devices from multiple brands without the need to own all the corresponding physical devices.
Complete the Connect Webview authorization flow by entering the following TTLock sandbox account credentials:
Email: jane@example.com
Password: 1234
Confirm that authorization through the Connect Webview was successful by querying its status.
When you link a TTLock account with Seam, we create a device object to represent each TTLock lock in your account. You can then retrieve these TTLock devices using the List Devices and Get Device endpoints.
The Seam API exposes each device's properties, such as the door lock status, power status, capabilities, and so on.
Code:
# Retrieve all devices, filtered by manufacturer,# which is one of several filters that list() supports.all_ttlock_locks = seam.devices.list(manufacturer="ttlock")# Select the first device as an example.front_door = all_ttlock_locks[0]# Inspect specific properties.assert front_door.properties["online"]isTrue# Trueassert front_door.properties["locked"]isTrue# True# View the entire returned device object.pprint(front_door)
# Retrieve all devices, filtered by manufacturer, which is# one of several filters that the list endpoint supports.all_ttlock_locks=$(# Use GET or POST.curl-X'GET' \'https://connect.getseam.com/devices/list' \-H'accept: application/json' \-H"Authorization: Bearer ${SEAM_API_KEY}" \-H'Content-Type: application/json' \-d'{ "manufacturer": "ttlock" }')# Select the first device as an example.front_door=$(jq-r'.devices[0]'<<<${all_ttlock_locks})# Inspect specific properties.echo $(jq-r'"Online (true): " + (.properties.online | tostring)'<<<${front_door})echo $(jq-r'"Locked (true): " + (.properties.locked | tostring)'<<<${front_door})# View the entire returned device object.echo ${front_door}
// Retrieve all devices, filtered by manufacturer,// which is one of several filters that list() supports.constallTtlockLocks=awaitseam.devices.list({manufacturer:"ttlock"});// Select the first device as an example.constfrontDoor= allTtlockLocks[0];// Inspect specific properties.console.log(frontDoor.properties.online); // trueconsole.log(frontDoor.properties.locked); // true// View the entire returned device object.console.log(frontDoor);
# Retrieve all devices, filtered by manufacturer,# which is one of several filters that list() supports.all_ttlock_locks = seam.devices.list(manufacturer: "ttlock")# Select the first device as an example.front_door = all_ttlock_locks[0]# Inspect specific properties.puts front_door.properties['online'] # trueputs front_door.properties['locked'] # true# View the entire returned device object.puts front_door.inspect
// Retrieve all devices, filtered by manufacturer,// which is one of several filters that list() supports.$all_ttlock_locks = $seam->devices->list(manufacturer:"ttlock");// Select the first device as an example.$front_door = $all_ttlock_locks[0];// Inspect specific properties.echo $front_door->properties->online ?'true':'false',"\n"; // trueecho $front_door->properties->locked ?'true':'false',"\n"; // true// View the entire returned device object.echojson_encode($front_door, JSON_PRETTY_PRINT);
// Retrieve all devices, filtered by manufacturer,
// which is one of several filters that list() supports.
var allTtlockLocks = seam.Devices.List(
manufacturer: Seam.Api.Devices.ListRequest.ManufacturerEnum.Ttlock
);
// Select the first device as an example.
Device frontDoor = allTtlockLocks[0];
// Inspect specific properties.
Console.WriteLine(frontDoor.Properties.Online); // true
Console.WriteLine(frontDoor.Properties.Locked); // true
// View the entire returned device object.
Console.WriteLine(frontDoor);
// Retrieve all devices, filtered by manufacturer,
// which is one of several filters that list() supports.
var allTtlockLocks = seam.devices().list(DevicesListRequest.builder()
.manufacturer(Manufacturer.TTLOCK)
.build());
// Select the first device as an example.
Device frontDoor = allTtlockLocks.get(0);
// Inspect specific properties.
System.out.println(frontDoor.getProperties().getOnline()); // true
System.out.println(frontDoor.getProperties().getLocked()); // true
// View the entire returned device object.
System.out.println(frontDoor);
// Retrieve all devices, filtered by manufacturer,
// which is one of several filters that list() supports.
allTtlockLocks, err := client.Devices.List(
context.Background(), &api.DevicesListRequest{
Manufacturer: api.ManufacturerTtlock.Ptr(),
},
)
// Select the first device as an example.
frontDoor := allTtlockLocks[0]
if err != nil {
return err
}
// Inspect specific properties.
fmt.Println(frontDoor.Properties.Online) // true
fmt.Println(*frontDoor.Properties.Locked) // true
// View the entire returned device object.
fmt.Println(frontDoor)
return nil
Next, you can use the Seam API to control your lock.
Each device that you connect to Seam has a specific set of capabilities. These capabilities define the Seam API actions that you can use, such as remote unlock actions, programming access codes, and so on. Seam's intuitive and granular capability flags inform your application about what features and behaviors each device supports. Notice the capability flags within the code samples in this guide.
Try out the following actions on your TTLock lock: