# Create spaces

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

{% tabs %}
{% tab title="Node.js" %}

### 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`:

```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:

```bash
npx tsx create-spaces.ts
```

### 3) (Optional) Verify spaces on a layer

List spaces for your layer:

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

main().catch(console.error);
```

Run:

```bash
npx tsx list-spaces.ts
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.gospace.com/start-building/create-a-location/create-a-layer/create-spaces.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
