Create a location

After retrieving a list of available countries using the /system/v1/country endpoint, you can create a location using the @gospace-ai/api SDK. Locations represent physical sites (e.g., an office building) and require a valid country_id from the previous API call.

Create a Script

Create a JavaScript file to create a location:javascript

// create_location.js
const { GospaceClient } = require('@gospace-ai/api');
require('dotenv').config();

async function createLocation() {
  try {
    const client = new GospaceClient({ api_key: process.env.GOSPACE_API_KEY || '' });
    const location = await client.workplace.locationsCreate({
      name: 'Main Office',
      address: '123 Tech St, London, UK',
      country_id: 'UK',
      timezone: 'Europe/London'
    });
    console.log('Location created:', location.id);
  } catch (error) {
    console.error('Error creating location:', error);
  }
}

createLocation();

Run the Script

Ensure your .env file contains a valid GOSPACE_API_KEY, then run:bash

node create_location.js

You should see the created location’s ID printed, such as:json

Location created: loc_12345

Note: Replace 'UK' with a valid country_id from the /system/v1/country endpoint. The @gospace-ai/api SDK supports TypeScript for type-safe development. To use TypeScript, rename the file to create_location.ts, install ts-node (npm install ts-node --save-dev), and run with npx ts-node create_location.ts. See developer.gospace.com for TypeScript setup and API documentation.

Last updated

Was this helpful?