Getting Started¶
Registering OAuth clients¶
You can register OAuth clients with Tapkey using our self-service registration page on Tapkey Integrator Portal.
OAuth clients are registered under an owner account in Tapkey's eco-system. After registration, an owner account will be created when registering your first lock.
Don't have a lock?
You can still create an owner account without registering a lock. Go to the Tapkey Integrator Portal on https://portal.tapkey.io and make sure you are logged in with the desired user. Afterwards expand the drop down menu in the navigation drawer saying "Locking systems". This will reveal a button stating "Create own locking system". Use it to create a new owner account and you are good to go.
List Locks¶
After registering a new OAuth client, listing a user's locks can be easily done using the Tapkey Access Management API. After obtaining an access token via OAuth, a user's owner accounts can be retrieved using the GET /owners
operation.
var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _accessToken);
var ownerAccountsTask = client.GetStringAsync("https://my.tapkey.com/api/v1/owners");
var json = await ownerAccountsTask;
var ownerAccounts = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(json);
After that, ownerAccount
contains a list of owner accounts for the current user. If present, an owner account can be chosen from that list in order to query bound locks.
// For demo purposes, just take the first Owner Account…
var ownerAccountId = ownerAccounts.First()["id"];
// … and query for bound locks
var boundLocksTask = client.GetStringAsync(
$"https://my.tapkey.com/api/v1/owners/{ownerAccountId}/boundlocks");
var json = await boundLocksTask;
var boundLocks = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(json);
At this point, boundLocks
contains a list of bound locks for the selected owner account. Information about the respective locks is delivered as defined in the GET /owners/{ownerAccount}/boundlocks
operation's response description below.
// Print a list of all bound locks
foreach (var boundLock in boundLocks)
{
var lockInfo = new StringBuilder();
lockInfo.AppendLine($"Lock ID: {boundLock["id"]}");
lockInfo.AppendLine($"Title: {boundLock["title"]}");
lockInfo.AppendLine($"Description: {boundLock["description"]}");
lockInfo.AppendLine($"Lock is active: {boundLock["active"]}");
lockInfo.AppendLine($"Binding date: {boundLock["bindDate"]}");
Console.WriteLine(lockInfo);
}
Runnable Example Available
A complete, runnable console application that prints a list of locks can be found in the Tapkey Web API .NET samples repository on GitHub.