---
doc_version: "1.0.0"
last_updated: "2026-07-14T15:00:57.718Z"
title: "JavaScript Widget API Reference"
description: "Complete reference for the ChatbotIQ widget JavaScript API: programmatically open, close, toggle, and query the chat widget."
keywords: [JavaScript API, widget API, programmatic control, open widget, close widget, ChatbotIQ]
---

Control the ChatbotIQ widget programmatically using the `window.chatbotiq` function. This API is available as soon as the embed script is on your page, you don't need to wait for the widget to finish loading.

---

## Methods

### `chatbotiq('open')`

Opens the chat widget.

```javascript
window.chatbotiq('open');
```

If the widget is already open, this does nothing.

---

### `chatbotiq('close')`

Closes the chat widget.

```javascript
window.chatbotiq('close');
```

If the widget is already closed, this does nothing.

---

### `chatbotiq('toggle')`

Toggles the widget open or closed.

```javascript
window.chatbotiq('toggle');
```

---

### `chatbotiq('getState')`

Returns the current state of the widget.

```javascript
const state = window.chatbotiq('getState');
// Returns: 'open' or 'closed'
```

---

## Command queuing

The API works even before the widget finishes loading. Commands are automatically queued and executed in order once the widget initializes.

This means you can safely call the API immediately after adding the embed script:

```html
<script>
  // This works even if the widget hasn't loaded yet
  window.chatbotiq('open');
</script>
```

---

For practical use-case patterns (custom buttons, page triggers, keyboard shortcuts, SPA integration), see [Control the Widget with JavaScript](/how-to/control-widget-with-javascript/).

---

## Related

- [Control the Widget with JavaScript](/how-to/control-widget-with-javascript/) - practical how-to guide
- [Embed the Widget](/how-to/embed-the-widget/) - adding the widget to your site
- [How the Widget Loads](/explanation/how-the-widget-loads/) - understand the async loading lifecycle

## Sitemap

Full documentation index: [sitemap.md](/sitemap.md) and [llms.txt](/llms.txt).
