Add directory people/teams

Populate your workplace directory with people and teams, then link people to their respective teams for allocations and analytics.

Prerequisites

  • Completed Setup Your Development Environment and Send Your First API Request

  • Node.js v18+ and npm v9+

  • A valid gospace API key in your .env file


1) Add people

Create add-people.ts:

import "dotenv/config";
import GospaceAI from "@gospace-ai/api";

async function main() {
  const gospace = new GospaceAI(process.env.GOSPACE_API_KEY!);

  const res = await gospace.directory.createPeople({
    people: [
      { email: "[email protected]", first_name: "Alice", last_name: "Smith" },
      { email: "[email protected]", first_name: "Bob", last_name: "Nguyen" }
    ],
  });

  console.log(JSON.stringify(res.data.people, null, 2));
}

main().catch((err) => {
  console.error("Create people failed:", err);
  process.exit(1);
});

Run:

npx tsx add-people.ts

2) Add teams

Create add-teams.ts:

import "dotenv/config";
import GospaceAI from "@gospace-ai/api";

async function main() {
  const gospace = new GospaceAI(process.env.GOSPACE_API_KEY!);

  const res = await gospace.directory.createTeams({
    teams: [
      { team_name: "Engineering" },
      { team_name: "People Operations" }
    ],
  });

  console.log(JSON.stringify(res.data.teams, null, 2));
}

main().catch((err) => {
  console.error("Create teams failed:", err);
  process.exit(1);
});

Run:

npx tsx add-teams.ts

3) Map people to teams (add team members)

You’ll need the team_id values from step 2 and the people_id values from step 1.

Create add-team-members.ts:

import "dotenv/config";
import GospaceAI from "@gospace-ai/api";

const TEAM_ID = "team_123"; // replace with your real team_id

async function main() {
  const gospace = new GospaceAI(process.env.GOSPACE_API_KEY!);

  await gospace.directory.addTeamMembers(TEAM_ID, {
    members: [
      { people_id: "person_abc" },
      { people_id: "person_def" },
    ],
  });

  console.log("Members added.");
}

main().catch((err) => {
  console.error("Add team members failed:", err);
  process.exit(1);
});

Run:

npx tsx add-team-members.ts

Last updated

Was this helpful?