---
# System prepended metadata

title: Handle default integrations with multiple integrations in export/import

---

- Assume there is already enabled integrations and processes useing them.
- Removing these integrations upon import will break things out since the integrationId will be changed
- Keep already existing integrations, get the already existing integrations and merge them with the bundle integrations, either create or update to ensure that no integration ids are missed
- The step knows the integration based on the slug, we need to change the integrations translations so that it maps the old integration id(from the bundle) to the new integration id(on the system)

## Export

- Two process in which they use different CW integrations
![](https://hackmd.io/_uploads/HJHZlFAs3.png)

- Two enabled CW int, one of them is default
![](https://hackmd.io/_uploads/By6fetRj2.png)

- Export the two integrations like below:
![](https://hackmd.io/_uploads/SkxGn9y33.png)

## Import


- ### Import from the UI(marketplace or minibundles)

> Put the UI from the marketplace import in for what Zaher is doing, It could default to default integrations, and then could use what he added to autofill the creation form if they don't exist

![](https://hackmd.io/_uploads/H1a91iJn3.png)

### import with useDefault = true (used in the non-UI operations like the provisioning and bundle tests)

**bundleIntegrations:**
```json
[
        {
            "slug": "connectwise",
            "integrationId": "OLD_1",
            "name": "Core CW"
        },
        {
            "slug": "connectwise",
            "integrationId": "OLD_2",
            "name": "Edge CW"
        }
]

```

**systemIntegrations**
```json
[
    {
        "_id" : "SYSTEM_1",
        "integrationName" : "connectwise",
        "name" : "Connectwise",
        "defaultIntegration" : false,
        ...
    },
    {
        "_id" : "SYSTEM_2",
        "integrationName" : "connectwise",
        "name" : "Connectwise",
        "defaultIntegration" : true,
        ...
    }
]

```

**integrationsTranslations**
```json
[
    {
      "importKey": "connectwise",
      "oldIntegrationId": "OLD_1",
      "newIntegrationId": "SYSTEM_1"
    },
    {
      "importKey": "connectwise",
      "oldIntegrationId": "OLD_2",
      "newIntegrationId": "NEW_2",
      "integrationName": "Edge CW"
    },
]
```

```javascript
const translateIntegrationOption = (
  integrationOptionKey,
  outputStep,
  intSlug,
  intId, <====================  
  integrationTranslations
) => {
  ...
  const integrationTranslation = integrationTranslations
      .find(t => t.importKey === intSlug && t.oldIntegrationId === intId); <=========
    
  outputStep.stepOptions[integrationOptionKey] = integrationTranslation.newIntegrationId; <============
};
```




- ### Import from non-UI(provisioning, bundle tests)

    - **Bundle Tests:** utility to create integrations with the needed creds then pass the translations like we do with the UI
    ```javascript
    const initializeTests = async ({
      bundleName,
      bundlePath,
      sortedProcesses,
      vaultEntries = [],
    }) => {
    ```

    - **Provisioning:** useDefault flag will be present and will be creating dummy integrations to match the number of integrations in the imported bundle, if the imported bundle has a default integration flag then the created/matched integration should be the default one, other wise select the first integration to be the default and then the user can change it to thier needs

    ![](https://hackmd.io/_uploads/BJ-h-jJ23.png)

