Skip to content

API Reference

Complete reference for the WidgetServiceSDK constructor, the connectors.execute method, and error behavior. Use this page when you need exact parameter names, default values, or error codes.

WidgetServiceSDK

Constructor

javascript
const sdk = new window.WidgetServiceSDK(config);

The config argument is optional — see Constructor options for available fields.

connectors.execute(options)

Execute a connector and return the response.

javascript
const result = await sdk.connectors.execute({
  permalink: "my-connector",
  method: "POST",
  payload: { name: "Monstera", size: "M" },
  headers: { "X-Request-Id": "abc-123" },
  queryParams: { format: "json" },
  pathParams: { user_id: 42 }
});

Parameters

ParameterTypeRequiredDefaultDescription
permalinkstringYesThe connector's unique permalink identifier
method"GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS"YesHTTP method
payloadRecord<string, JsonValue>NoundefinedRequest body. Only sent for POST, PUT, PATCH methods
queryParamsRecord<string, string>No{}Query parameters appended to the request URL
pathParamsRecord<string, string | number>No{}Values substituted into {{ pathParams.X }} URL template references on the connector. See Dynamic URL Path Segments
headersRecord<string, string>No{}Additional headers for this request

JsonValue covers strings, numbers, booleans, null, arrays, and nested objects.

Returns Promise<Record<string, JsonValue>>

Path parameter validation

pathParams is validated synchronously at the SDK boundary before any network call. The SDK throws ConnectorBoundaryError on:

  • An empty or whitespace-only key (e.g. { "": "x" })
  • A value whose type is not string | number — catches untyped JS callers passing null, undefined, booleans, objects, or arrays
  • A serialized header value over 4096 characters (gateway / CDN per-header limits typically sit around 8–16 KB; this cap leaves headroom)
  • Passing pathParams to sdk.connectors.composite.execute (composite connectors don't accept path parameters)

Omitting pathParams or passing {} sends no header — the request goes out unchanged. See Dynamic URL Path Segments — Validation and errors for the server-side error codes returned when validation passes the SDK but fails server-side.

Error handling

Wrap execute calls in a try/catch to handle network errors, timeouts, and connector failures:

javascript
import {
  ConnectorBoundaryError,
  ConnectorExecuteError
} from "@gainsight-hub/connectors-sdk";

try {
  const data = await sdk.connectors.execute({
    permalink: "my-connector",
    method: "GET",
    pathParams: { user_id: 42 }
  });
  console.log(data);
} catch (error) {
  if (error instanceof ConnectorBoundaryError) {
    // Client-side rejection — invalid pathParams shape, composite + pathParams, etc.
    console.error("Boundary rejection:", error.reason);
  } else if (error instanceof ConnectorExecuteError) {
    switch (error.code) {
      case "MISSING_PATH_PARAMETERS":
      case "INVALID_PATH_PARAMETERS":
        // error.params: string[] — the failing keys
        console.error("Path params failed:", error.code, error.params);
        break;
      case "CONNECTOR_MISCONFIGURED":
        // error.detail: string — operator-facing detail
        console.error("Misconfigured:", error.detail);
        break;
      default:
        // Legacy shape — error.failureScope / error.reason / error.requestId / error.status
        console.error("Execute failed:", error.failureScope, error.reason, error.status);
    }
  } else {
    // Network / timeout / unknown
    console.error("Connector execution failed:", error.message);
  }
}

ConnectorBoundaryError is thrown synchronously before any HTTP call — it signals a malformed call. ConnectorExecuteError normalises two server-error shapes: the envelope { success: false, errors: { code, detail, scope?, params? }, request_id } returned for connector execution errors — path-parameter validation (HTTP 400) as well as connection, template, and authentication failures (HTTP 422/502/500) — exposed as optional code / params / detail fields, and the legacy { failure_scope, reason, request_id } (exposed as failureScope / reason). Branch on error.code to handle envelope errors; fall back to failureScope for legacy ones.

Common failure scenarios:

ScenarioCauseError class
Network errorThe backend is unreachableError
TimeoutRequest exceeded the configured timeout (default 30s)Error
Connector not foundThe permalink does not match any existing connectorError (HTTP 404)
Authentication failureThe connector's auth credentials are invalid or expiredConnectorExecuteError
Upstream errorThe destination API returned an errorConnectorExecuteError
Invalid pathParams shapeEmpty key, wrong value type, oversized payload, or passed to compositeConnectorBoundaryError
Missing required path param valueURL references {{ pathParams.X }} but caller omitted one or more keys from pathParamsConnectorExecuteError (code: "MISSING_PATH_PARAMETERS")
Path param value fails URL-safe validationCaller supplied a value containing characters outside [A-Za-z0-9._~-], or a path-traversal segment (..)ConnectorExecuteError (code: "INVALID_PATH_PARAMETERS")

Next Steps

Gainsight CC Developer Portal