Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.go.gbgplc.com/llms.txt

Use this file to discover all available pages before exploring further.

The Core SDK (@gbg/go-core) provides a type-safe TypeScript client for the GBG GO Captain API. Use it on your server to authenticate, start journeys, manage tasks, connect devices, and generate the tokens and URLs needed to embed web journeys in your apps.
The Core SDK is in beta. Pin to a specific version to avoid breaking changes between releases.

Installation

npm
npm install @gbg/go-core
pnpm
pnpm add @gbg/go-core
yarn
yarn add @gbg/go-core
The package ships with both CommonJS and ES module builds, and includes TypeScript declarations. Supported runtimes: Node.js 18+, Bun 1+, Deno 1.39+, modern browsers.

Authentication

Generate an access token, then pass it to the SDK:
import { Go } from "@gbg/go-core";

// Generate a token
const go = new Go();
const tokenResult = await go.tokens.generate({
  clientId: "your-client-id",
  clientSecret: "your-client-secret",
  username: "api-user@example.com",
  password: "your-secure-password",
  grantType: "password",
});

// Use the token for subsequent calls
const authenticatedGo = new Go({
  customerAccess: tokenResult.accessToken,
});
You can also set the GO_CUSTOMER_ACCESS environment variable instead of passing the token directly.

Region selection

GBG GO is deployed across three regions. Set your region when initializing the SDK:
const go = new Go({
  serverURL: "https://eu.platform.go.gbgplc.com/v2/captain",
  customerAccess: process.env.GO_CUSTOMER_ACCESS,
});

Available operations

These are the resources and methods exposed by the SDK:
ResourceMethodDescription
tokensgenerate()Generate an access token
journeysstart()Start a journey instance
journeysgetState()Get journey state
taskslist()Get end-user tasks
tasksupdate()Submit end-user data
tasksgetSchema()Get a task’s schema
taskslistSchema()Get all tasks with schemas
devicesadd()Create a connect secret
devicesconnect()Connect or refresh an end-user device
interactionssubmit()Submit an interaction
interactionsfetch()Fetch an interaction
instancesdelete()Delete a journey instance
healthget()Check service health

Start a journey

Pass the resource ID of the journey template you want to run. The response includes the instanceId you’ll use to track the journey:
const result = await go.journeys.start({
  resourceId: "your-journey-resource-id",
  context: {
    subject: {},
    config: { delivery: "page" },
  },
});

console.log(result.instanceId); // Use this to track the journey

Connect an end-user device

Generate a connect token on your server, then pass it to the end user’s device:
// Server: create a connect secret
const connectResult = await go.devices.add({
  instanceId: "PiIuACmx8Q8R7qPnAkLAqBAT",
  scope: ["mobile"],
});

// Device: exchange the connect token for an end-user token
const deviceResult = await go.devices.connect(
  { deviceConnect: connectResult.connectToken },
  {
    connectToken: connectResult.connectToken,
    deviceInfo: {
      deviceId: "device-uuid",
      deviceName: "iPhone 15",
      deviceType: "iOS",
    },
  }
);

Error handling

Catch GoError to inspect the HTTP status code and response body when an API call fails:
import { Go } from "@gbg/go-core";
import * as errors from "@gbg/go-core/models/errors";

try {
  const result = await go.journeys.start({ resourceId: "..." });
} catch (error) {
  if (error instanceof errors.GoError) {
    console.error(`API error ${error.statusCode}: ${error.message}`);
    console.error("Response body:", error.body);
  }
}

Retries

Configure retry behaviour globally or per-request:
const go = new Go({
  customerAccess: process.env.GO_CUSTOMER_ACCESS,
  retryConfig: {
    strategy: "backoff",
    backoff: {
      initialInterval: 1,
      maxInterval: 50,
      exponent: 1.1,
      maxElapsedTime: 100,
    },
    retryConnectionErrors: false,
  },
});

Further reading

For the complete API reference, standalone functions for tree-shaking, custom HTTP client configuration, and debugging options, see the full SDK documentation on GitHub: