# Integrations

<figure><img src="https://content.gitbook.com/content/vFXzdRN8pEVkEDSMo1qe/blobs/sKlrC7sWp02f2kxxduoh/integrations-light.png" alt=""><figcaption><p>Integrations</p></figcaption></figure>

## Configuration <a href="#configuration" id="configuration"></a>

Set up a new instance with `config` parameters and `set`/`get` methods:

```javascript
const integrations = appmixer.ui.Integrations(config)

integrations.set(key, value)
integrations.get(key)
```

#### **`config.el`** **`...`**

{% hint style="info" %}
Learn about `widget` `config` [here](https://docs.appmixer.com/appmixer-ui-sdk/ui-and-widgets/..#configuration).
{% endhint %}

#### **`config.options`**

Type: `Object` | Default: `{}`

#### **`config.options.customFilter`**

Type: `Object` | Default: `{}`

Filter the integrations with additional parameters:

```javascript
appmixer.ui.Integrations({
  /* ... */
  options: {
    customFilter: {
      // displaying Integrations with a certain customField
      'customFields.category': 'healthcare',
      // that are shared with someone
      'sharedWith': '![]'
      // and in this example, that are shared throught the 'domain'
      // options with a 'testdomain.com'
      'sharedWith.domain': 'testdomain.com'
      // or we could filter only Integrations that are shared with
      // scope 'user'
      // 'sharedWith.scope': 'user',
    }
  }
}
```

The `customFilter` option can also be an array for templates and instances:

```javascript
appmixer.ui.Integrations({
    /* ... */
    options: {
        customFilter: [
            { 'customFields.category': 'your-category-for-templates' },
            { 'customFields.category': 'your-category-for-instances' }
        ]
    }
});
```

#### Updating the Custom Filter Dynamically

You can change the custom filter after the widget has already been initialized. For example, when a user selects a new category, you can update the filter and reload the widget:

```javascript
// Get the current widget options.
const currentOptions = integrations.get('options') || {};

// Override the custom filter and keep the rest of the options unchanged.
integrations.set('options', {
    ...currentOptions,
    customFilter: {
        'customFields.category': 'finance'
    }
});

// Reload the widget to apply the updated filter.
integrations.reload();
```

## Instance <a href="#state" id="state"></a>

{% hint style="info" %}
Learn about `widget` instance [here](https://docs.appmixer.com/appmixer-ui-sdk/ui-and-widgets/..#instance).
{% endhint %}

### State

```javascript
integrations.state(name, value)
```

#### **`loader`**

Type: `Boolean` | Default: `null`

Toggle a custom loading state.

#### **`error`**

Type: `String` | Default: `null`

Toggle a custom error message.

### Events <a href="#events" id="events"></a>

```javascript
integrations.on(event, handler)
```

#### **`integration:create`**

```javascript
integrations.on('integration:create', integrationId => {/* ... */})
```

Click a button to to create a new integration from template.

#### **`integration:edit`**

```javascript
integrations.on('integration:edit', integrationId => {/* ... */})
```

Click a button to edit integration.

#### **`integration:remove`**

```javascript
integrations.on('integration:remove', integrationId => {/* ... */})
```

Click a button to remove integration.

#### **`integration:start`**

```javascript
integrations.on('integration:start', integrationId => {/* ... */})
```

Click a button to start integration.

#### **`integration:stop`**

```javascript
integrations.on('integration:stop', integrationId => {/* ... */})
```

Click a button to stop integration.

## Example

```javascript
const integrations = appmixer.ui.Integrations({
    el: '#integrations'
})

integrations.open()

integrations.on('integration:create', async templateId => {
    // Create integration flow as a clone of the template. Disconnect
    // accounts because they might not be shared with the end user.
    const integrationId = await appmixer.api.cloneFlow(templateId, { connectAccounts: false })
    await appmixer.api.updateFlow(integrationId, { templateId })

    const wizard = appmixer.ui.Wizard({
        el: '#your-wizard-div',
        flowId: integrationId,
    });

    wizard.open()
    integrations.reload()
})

integrations.on('integration:edit', function(integrationId) {
    var wizard = appmixer.ui.Wizard({
        el: '#wizard',
        flowId: integrationId
    });
    wizard.open()
});

integrations.open()
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.appmixer.com/appmixer-ui-sdk/ui-and-widgets/integrations.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
