Create spaces

Define individual spaces such as desks, workstations, or generic areas within a layer to represent your workplace layout.

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

  • An existing location_id and layer_id (spaces belong to a layer)

1) Create the script

Create create-spaces.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.spatial.createSpaces({
    spaces: [
      {
        layer_id: "layer_123",     // required: the layer this space belongs to
        name: "Desk A-1",          // required: space name
        // external_id: "desk-a-1", // optional
      },
      {
        layer_id: "layer_123",
        name: "Desk A-2",
        // external_id: "desk-a-2",
      }
    ],
  });

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

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

2) Run the script

With TypeScript:

npx tsx create-spaces.ts

3) (Optional) Verify spaces on a layer

List spaces for your layer:

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.spatial.getSpaces({
    layer_id: "layer_123",
    skip: 0,
    limit: 50,
  });
  console.log(JSON.stringify(res.data.spaces, null, 2));
}

main().catch(console.error);

Run:

npx tsx list-spaces.ts

Last updated

Was this helpful?