Skip to content

Examples

Ready-to-use code examples for common widget patterns using the SDK. Each example shows a complete, self-contained call to connectors.execute that you can copy and adapt.

Prerequisites

These examples run inside a widget hosted in Customer Community, where window.WidgetServiceSDK is globally available. See Widget SDK for constructor options.

GET request with query parameters

Fetch weather data by passing query parameters to the connector:

javascript
(async () => {
  const sdk = new window.WidgetServiceSDK();

  const weather = await sdk.connectors.execute({
    permalink: "weather-api",
    method: "GET",
    queryParams: {
      q: "Warsaw",
      units: "metric"
    }
  });

  console.log(weather);
})();

POST request with JSON body

Create a resource by sending a JSON payload:

javascript
(async () => {
  const sdk = new window.WidgetServiceSDK();

  const result = await sdk.connectors.execute({
    permalink: "crm-contacts",
    method: "POST",
    payload: {
      firstName: "Jane",
      lastName: "Doe",
      email: "jane@example.com"
    }
  });

  console.log(result);
})();

PUT request to update a resource

Update an existing resource by its identifier:

javascript
(async () => {
  const sdk = new window.WidgetServiceSDK();

  const updated = await sdk.connectors.execute({
    permalink: "crm-contacts",
    method: "PUT",
    queryParams: { id: "contact-42" },
    payload: {
      firstName: "Jane",
      lastName: "Smith"
    }
  });

  console.log(updated);
})();

DELETE request

Remove a resource using DELETE:

javascript
(async () => {
  const sdk = new window.WidgetServiceSDK();

  await sdk.connectors.execute({
    permalink: "task-manager",
    method: "DELETE",
    queryParams: { taskId: "task-99" }
  });
})();

Custom headers per request

Pass additional headers for a single request without affecting the global SDK configuration:

javascript
(async () => {
  const sdk = new window.WidgetServiceSDK();

  const data = await sdk.connectors.execute({
    permalink: "internal-api",
    method: "GET",
    headers: {
      "X-Request-Id": crypto.randomUUID(),
      "Accept-Language": "en-US"
    }
  });
})();

Global headers via constructor

Set headers that apply to every request made through the SDK instance:

javascript
(async () => {
  const sdk = new window.WidgetServiceSDK({
    headers: {
      "X-App-Version": "2.1.0",
      "X-Client": "custom-widget"
    }
  });

  const data = await sdk.connectors.execute({
    permalink: "analytics-api",
    method: "GET"
  });
})();

Custom timeout

Override the default 30-second timeout for long-running requests:

javascript
(async () => {
  const sdk = new window.WidgetServiceSDK({
    timeout: 60000
  });

  const report = await sdk.connectors.execute({
    permalink: "report-generator",
    method: "POST",
    payload: { range: "last-90-days" }
  });
})();

Next Steps

Gainsight CC Developer Portal