Skip to content

API Reference

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

WidgetServiceSDK

Constructor

typescript
import { WidgetServiceSDK } from "@gainsight-customer-hub/widget-service-sdk";

const sdk = new WidgetServiceSDK(config?: SDKConfig);

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" }
});

Parameters

ParameterTypeRequiredDefaultDescription
permalinkstringYesThe connector's unique permalink identifier
methodHttpMethodYesHTTP method: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS
payloadExecutePayloadNoundefinedRequest body. Only sent for POST, PUT, PATCH methods
queryParamsRecord<string, string>No{}Query parameters appended to the request URL
headersRecord<string, string>No{}Additional headers for this request

Returns Promise<ExecuteResponse>

Types

All types can be imported directly:

typescript
import type {
  HttpMethod,
  ExecuteConnectorOptions,
  ExecutePayload,
  ExecuteResponse,
  SDKConfig
} from "@gainsight-customer-hub/widget-service-sdk";

SDKConfig

typescript
interface SDKConfig {
  csrfToken?: string;
  headers?: Record<string, string>;
  timeout?: number;
}
FieldTypeDefaultDescription
csrfTokenstringAuto-detectedCSRF token. Auto-detected from a DOM element with id csrftoken
headersRecord<string, string>{}Headers included with every request
timeoutnumber30000Request timeout in milliseconds

HttpMethod

typescript
type HttpMethod =
  | "GET"
  | "POST"
  | "PUT"
  | "PATCH"
  | "DELETE"
  | "HEAD"
  | "OPTIONS";

ExecuteConnectorOptions

typescript
interface ExecuteConnectorOptions {
  permalink: string;
  method: HttpMethod;
  payload?: ExecutePayload;
  headers?: Record<string, string>;
  queryParams?: Record<string, string>;
}

ExecutePayload

typescript
interface ExecutePayload {
  [key: string]: JsonValue;
}

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

ExecuteResponse

typescript
interface ExecuteResponse {
  [key: string]: JsonValue;
}

Error handling

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

javascript
try {
  const data = await sdk.connectors.execute({
    permalink: "my-connector",
    method: "GET"
  });
  console.log(data);
} catch (error) {
  console.error("Connector execution failed:", error.message);
}

Common failure scenarios:

ScenarioCause
Network errorThe backend is unreachable
TimeoutRequest exceeded the configured timeout (default 30s)
Connector not foundThe permalink does not match any existing connector
Authentication failureThe connector's auth credentials are invalid or expired
Upstream errorThe destination API returned an error

Next Steps

Gainsight CC Developer Portal