API Keys

The following section assumes that you have already created an account and installed the client library SDK.

About API Keys

API keys provide the fundamental way to access the Relaybox services and to limit who has access to which features.

When used in combination with Auth Tokens and dynamic permissions, you can create a resilient, least privilege system where you maintain full control over the security of the operations carried out through your applications.

How to Generate an API Key

To gain access to Relaybox services, you first need to generate an API key for your application. To generate an API key, head over to the dashboard and locate the "API keys" section.

https://www.relaybox.com/dashboard
API keys section in the dashboard

From here you have the options to create, revoke, and manage the API keys associated with your applications. For more information on associating custom permissions with API keys, please view the Access Controls section.

Connecting to Relaybox Services

Now that you have created an API key for your application, you will be able to connect to Relaybox services. However, while this is possible and the quickest way to establish a connection, we recommend that you use Auth Tokens to manage connections.

import { RelayBox } from '@relaybox/client';

const relayBox = new RelayBox({
  apiKey: xxxx.xxxx.xxxxxxxx // Replace with your api key
});

await relayBox.connect();

relayBox.connection.on('connect', () => {
  console.log('connection successful');
})

Granting Permissions via API Keys

When you generate an API key, it is automatically (but explicitly) granted access to all operations in all rooms.

https://www.relaybox.net/dashboard
Creating an API key in the dashboard

To refine the permissions granted to an access key, use the dashboard to add and remove permissions as you see fit. There's more on this in the Access Controls section.

Using API keys with REST

While not recommended when working with the client-side library, the recommended way to connect to RelayBox REST services is by using an API key.

// Server side
import { RelayBox } from '@relaybox/rest';

const relayBox = new RelayBox({
  apiKey: xxxx.xxxx.xxxxxxxxxxxx // Use API key responsibly on your server
});

const response = relayBox.publish('room:one', 'message', data);

    On this page