Get started
Get started

Node quickstart

Node quickstart

One script: mint a session token, list your itineraries, and route a hike from Chamonix to Argentière.

1

Install
mkdir mountaya-node && cd mountaya-node
npm init -y && npm pkg set type=module
npm install @mountaya/client

Node 22.18 or later runs TypeScript files as they are, with no build step.

2

Set your keys

Create both keys under Organization → API keys in the Mountaya app. The publishable key needs the publishing and data scopes.

export MOUNTAYA_PUBLISHABLE_KEY="pk_your_publishable_key"
export MOUNTAYA_SECRET_KEY="sk_your_secret_key"

3

Write the script
main.ts
import { isMountayaApiError, Mountaya } from "@mountaya/client";

const publishableKey = process.env.MOUNTAYA_PUBLISHABLE_KEY;
const secretKey = process.env.MOUNTAYA_SECRET_KEY;
if (publishableKey === undefined || secretKey === undefined) {
  throw new Error("Set MOUNTAYA_PUBLISHABLE_KEY and MOUNTAYA_SECRET_KEY.");
}

try {
  // The secret key mints a session token. It lasts five minutes.
  const server = new Mountaya({ credential: { secretKey } });
  const { data: session } = await server.admin.sessions.postSession({
    body: { publishable_key: publishableKey },
  });

  // Every other call sends the publishable key and the token.
  const mountaya = new Mountaya({
    credential: { publishableKey, sessionToken: session.token },
  });

  // Map Studio API: your five most recently updated itineraries.
  const { data: itineraries } = await mountaya.studio.itineraries.getItineraries({
    query: { limit: 5, sort: "-updated_at" },
  });
  for (const itinerary of itineraries) {
    console.log(`${itinerary.name}, updated ${itinerary.updated_at.toISOString()}`);
  }

  // Data API: a hike from Chamonix to Argentière.
  const { routes } = await mountaya.data.directions(
    {
      activity: "HIKING_AND_TRAIL",
      waypoints: [
        [6.8712, 45.9231],
        [6.9271, 45.9822],
      ],
    },
    { select: { routes: { distance: true, duration: true, summary: true } } },
  );
  console.log(routes[0]?.summary);
} catch (error) {
  if (isMountayaApiError(error)) {
    console.error(`${error.status} ${error.code ?? ""}: ${error.errors[0]?.message}`);
    process.exitCode = 1;
  } else {
    throw error;
  }
}

4

Run it
node main.ts
Output
Docs Tour du Mont-Blanc, updated 2026-11-09T10:53:23.814Z
9.0 km, ~2h40m, +277m / -56m elevation, 67% path, 12% track, 8% road.

Dates arrive as Date objects, distances in meters and durations in seconds. The full program is the examples/client-node directory of the SDK repository.

Next steps

Last updated