Navigation

Create & Manage API Keys

Create a User API Key

var newKey = await user.ApiKeys.CreateAsync("someKeyName");
Console.WriteLine($"I created a key named {newKey.Name}. " +
    $"Is it enabled? {newKey.IsEnabled}");

Look up a User API Key

To get a single key:

var key = await user.ApiKeys.FetchAsync(ObjectId.Parse("00112233445566778899aabb"));
Console.WriteLine($"I fetched the key named {key.Name}. " +
    $"Is it enabled? {key.IsEnabled}");

To get all keys:

var allKeys = await user.ApiKeys.FetchAllAsync();
foreach (var key in allKeys)
{
    Console.WriteLine($"I fetched the key named {key.Name}. " +
        $"Is it enabled? {key.IsEnabled}");
}

Enable or Disable an API Key

var key = await user.ApiKeys.FetchAsync(ObjectId.Parse("00112233445566778899aabb"));
if (!key.IsEnabled)
{
    // enable the key
    await user.ApiKeys.EnableAsync(key.Id);
}
else
{
    // disable the key
    await user.ApiKeys.DisableAsync(key.Id);
}

Delete an API Key

await user.ApiKeys.DeleteAsync(ObjectId.Parse("00112233445566778899aabb"));