HelloJohn / docs
SDKsNode.js SDK

Organizations

Manage organizations server-side with the HelloJohn Node.js SDK — create, update, list members, and manage invitations.

Organizations

The organizations namespace provides server-side management of organizations and their members.

import { HelloJohn } from "@hellojohn/node";

const hj = new HelloJohn({
  tenantId: process.env.HELLOJOHN_TENANT_ID!,
  secretKey: process.env.HELLOJOHN_SECRET_KEY!,
});

Create an Organization

const org = await hj.organizations.create({
  name: "Acme Corp",
  slug: "acme-corp",           // URL-safe identifier (auto-generated if omitted)
  ownerId: "usr_01HABCDEF123456", // User to assign as owner
  metadata: {
    plan: "enterprise",
  },
});

Get an Organization

// By ID
const org = await hj.organizations.get("org_01HABCDEF000001");

// By slug
const org = await hj.organizations.getBySlug("acme-corp");

List Organizations

const { organizations } = await hj.organizations.list({
  limit: 50,
});

Filter by member:

// Get orgs a specific user belongs to
const { organizations } = await hj.organizations.listForUser(
  "usr_01HABCDEF123456"
);

Update an Organization

await hj.organizations.update("org_01HABCDEF000001", {
  name: "Acme Corporation",
  metadata: {
    plan: "enterprise",
    seats: 50,
  },
});

Members

List Members

const { members } = await hj.organizations.listMembers("org_01HABCDEF000001");

Member object:

interface Member {
  id: string;
  userId: string;
  organizationId: string;
  role: "owner" | "admin" | "member";
  joinedAt: Date;
  user: {
    id: string;
    email: string;
    firstName: string | null;
    lastName: string | null;
  };
}

Add a Member

await hj.organizations.addMember("org_01HABCDEF000001", {
  userId: "usr_01HABCDEF234567",
  role: "member",
});

Update a Member's Role

await hj.organizations.updateMemberRole(
  "org_01HABCDEF000001",
  "usr_01HABCDEF234567",
  "admin"
);

Remove a Member

await hj.organizations.removeMember(
  "org_01HABCDEF000001",
  "usr_01HABCDEF234567"
);

Invitations

Invite by Email

const invitation = await hj.organizations.inviteMember("org_01HABCDEF000001", {
  email: "newmember@example.com",
  role: "member",
  redirectTo: "https://app.example.com/accept-invite",
});

HelloJohn sends an invitation email with a link. The user clicks the link to accept and join the organization.

List Pending Invitations

const { invitations } = await hj.organizations.listInvitations(
  "org_01HABCDEF000001"
);

Revoke an Invitation

await hj.organizations.revokeInvitation(
  "org_01HABCDEF000001",
  "inv_01HABCDEF999999"
);

Delete an Organization

await hj.organizations.delete("org_01HABCDEF000001");

All memberships are removed. User accounts are not deleted.


On this page