> For the complete documentation index, see [llms.txt](https://docs-en.dydu.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-en.dydu.ai/developers/api-reference/import-export-bot.md).

# Import Export Bot

The bot import/export APIs let you duplicate a whole bot: for example to copy a production bot to a staging bot, or to move from a SaaS server to an OnPremise server.

## Before you start

You need:

* the **identifier of the bot to export** (source bot) and the **identifier of the target bot**. The target bot must already exist: if needed, create it before the import;
* an **authorization** on the server of the source bot and an authorization on the server of the target bot (see [Authentication](https://docs-en.dydu.ai/developers/api-reference/authentication)). The account used must be an administrator of the bot.

These APIs are in the Swagger interface, **Bot data transfer** category: go to **Preferences > Api > API access** and click the link provided. The Swagger interface is also available at `https://<server>/servlet/api/doc3/index.html`.

The procedure has four steps:

1. [Start the export of the source bot.](#id-1.-start-the-export)
2. [Check that the export is finished.](#id-2.-check-that-the-export-is-finished)
3. [Start the import on the target bot.](#id-3.-start-the-import)
4. [Check that the import is finished.](#id-4.-check-that-the-import-is-finished)

You can also [download the export](#download-the-export) to keep it, but you do not need it for the import.

## 1. Start the export

1. Click **POST /bot/export/{botUUID}/{includeGallery}** ("Export bot data"), then **Try it out**.
2. Fill in the fields:
   * **botUUID**: identifier of the bot to export;
   * **includeGallery**: `true` to also export the gallery (recommended), `false` otherwise;
   * **Authorization**: your token on the server of the source bot;
   * **DialogsPassword**: only if the dialog encryption option is enabled in the BMS, the decryption password. Without it, the content of the dialogs is hidden in the export.
3. Click **Execute**.

If the export starts, the API returns a **202** code. The `Location` header of the response gives the address to use to follow the export.

If the API returns a **401** code with the "Invalid authentication" message, check your login and password, and that you did not forget "Basic" or "Bearer" before the token.

## 2. Check that the export is finished

1. Click **GET /bot/export/{botUUID}/status** ("Get export bot data status"), then **Try it out**.
2. Fill in the **botUUID** and **Authorization** fields.
3. Click **Execute**.

The `exportStatus` field of the response gives the status of the export:

| Value        | Meaning                                                                                                 |
| ------------ | ------------------------------------------------------------------------------------------------------- |
| `PROCESSING` | The export is in progress. Check the status again a bit later (after 5 to 10 minutes for a large base). |
| `DONE`       | The export is finished.                                                                                 |
| `ERROR`      | The export failed. The response gives the reason.                                                       |
| `NOT_FOUND`  | No export was found for this bot (404 code).                                                            |

A frequent cause of error is a chatbox configuration that is not up to date. The response then contains for example `"configurationsStatuses":{"5588419e-2fc7-4266-97aa-bd0982d2593c":"TO_FIX"}`: the configuration shown must be fixed before you start the export again. The export fails as soon as a configuration is not in the `STABLE` state.

## 3. Start the import

1. Click **POST /bot/import/{botUUID}/fromurl** ("import bot data from url"), then **Try it out**.
2. Fill in the fields:
   * **botUUID**: identifier of the target bot;
   * **Authorization**: your token on the server of the target bot;
   * **Url-Authorization**: your token on the server of the source bot. This field is only needed if the URL is the one of the export API;
   * **body**: the URL of the export, for example `https://<source-server>/servlet/api/bot/exported/<source-botUUID>`, or the URL of a zip file (for example "<https://www.mysite.com/exports/mybot.zip>").
3. Click **Execute**.

If the import starts, the API returns a **202** code.

{% hint style="info" %}
You can also import a zip file you downloaded beforehand with **POST /bot/import/{botUUID}** ("import bot data"), by selecting it in the **file** field.
{% endhint %}

{% hint style="warning" %}
The import does not delete the data already present on the target bot.
{% endhint %}

## 4. Check that the import is finished

1. Click **GET /bot/import/{botUUID}/status** ("Get import bot data status"), then **Try it out**.
2. Fill in the **botUUID** (target bot) and **Authorization** fields.
3. Click **Execute**.

The `importStatus` field of the response takes the same values as for the export (`PROCESSING`, `DONE`, `ERROR`). When the import is finished, the response also contains:

* `startDate` and `endDate`: start and end dates of the import;
* `importedKnowledges`: result of the knowledge import;
* `importedDialogs`: result of the dialog import;
* `importedUsers`: result of the user import.

If an error occurs, the response gives the reason.

## Download the export

This step is optional.

1. Click **GET /bot/exported/{botUUID}** ("Get exported bot data"), then **Try it out**.
2. Fill in the **botUUID** (source bot) and **Authorization** fields.
3. Click **Execute**, then **Download file** to get the zip file.

## Limits

The export/import includes in particular the knowledge base, chatbox configurations, users, languages and consultation spaces, bot settings, competencies and operators, URLs, surveys and the gallery.

Two points need special attention:

* **Dialogs**: only the dialogs of the last 31 days are exported.
* **Matching groups of the social bot or of external bots** (for example a meta assistant): the link with these groups is not always kept, because they are referenced by identifiers that change from one server to another. Check and fix them manually after the import. The matching groups defined in the bot are imported correctly.

## Follow the import in the console

Once the import is finished, its traces are available in the **Console** section, by displaying the **Info** level messages.
