Organizations and workspaces
Use one organization key to work in each of your client workspaces.
An organization, such as an agency, holds several workspaces, one per client. The organization's API key can act on any workspace inside it. Tell the SDK which workspace, and every request runs there as if it used that workspace's own key. See Organization for how organizations, seats and members work.
Act on a workspace
Make a client per workspace with withOptions:
const swarmhit = new Swarmhit(); // the organization's key
const acme = swarmhit.withOptions({ workspace: 'ws_acme' });
const globex = swarmhit.withOptions({ workspace: 'ws_globex' });
const acmeCampaigns = await acme.campaigns.list();
await globex.webhooks.create({ url: 'https://example.com/hooks/globex', events: ['message.received'] });Or name the workspace for a single request:
await swarmhit.campaigns.list({}, { workspace: 'ws_acme' });The SDK sends the workspace id in the X-Swarmhit-Workspace header. A
workspace's own key cannot act on another workspace: the API refuses the
request with an AuthenticationError. An organization's key that names a
workspace outside the organization gets the same error. The workspaces
endpoints always manage the key's organization, whatever the header says.
List and manage workspaces
const org = await swarmhit.workspaces.list();
console.log(`${org.available} of ${org.pool} seats free`);
for (const ws of org.workspaces) {
console.log(ws.id, ws.name, `${ws.sendersUsed}/${ws.seatAllocation} senders`);
}
// A new client workspace with two seats from the pool.
const client = await swarmhit.workspaces.create({ name: 'Initech', seatAllocation: 2 });swarmhit.workspaces.members lists and manages the people with access to one
of the organization's workspaces.
Run the same job for every client
const { workspaces } = await swarmhit.workspaces.list();
for (const ws of workspaces) {
const client = swarmhit.withOptions({ workspace: ws.id });
const stats = await client.stats.get();
console.log(ws.name, stats);
}