Send your first API request

Make your first call to the gospace API to verify your setup, authenticate successfully, and retrieve live data from your workspace environment.

Prerequisites

  • Completed Setup Your Development Environment

  • Node.js v18+ and npm v9+

  • A valid gospace API key in your .env file

1. Install dependencies

If you haven’t already:

npm install @gospace-ai/api dotenv

2. Create a request script

Create first-request.ts:

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

async function main() {
  // Initialize the client with your API key
  const gospace = new GospaceAI(process.env.GOSPACE_API_KEY!, {
    // Optional: use sandbox when available
    // url: "https://sandbox.api.gospace.app",
  });

  // Example: fetch supported countries from the System API
  const res = await gospace.system.getCountries();

  // Print the response data
  console.log(JSON.stringify(res.data, null, 2));
}

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

Prefer TypeScript? Run with tsx. Prefer JavaScript? See the JS version below.

3. Run the script

With TypeScript (recommended):

npx tsx first-request.ts

Last updated

Was this helpful?