---
updatedAt: 2025-01-08T23:20:40.000Z
agentTools:
  projectIndex: https://dev.frontapp.com/llms.txt
---

# Sample Applications

To demonstrate common Core API concepts, Front provides sample applications that help bootstrap your development.

* [Import application](#conversationmessage-import-application)
* [Export application](#conversationmessage-export-application)

## Conversation/Message Import application

This example application demonstrates how to import conversations and messages to Front.

**Conversations** are the parent objects for the communications you have in Front inboxes. Each conversation contains **messages** that represent the actual communications between recipients.

For example, if `john@example.com` sends an email to `wendy@example.com` and `gloria@example.com`, and then `gloria@example.com` replies, you would have one conversation with two messages in it (one message from John, and one message from Gloria, all in the same conversation).

### Source code

This project is available on [GitHub](https://github.com/frontapp/coreapi-import-template).

### Noteworthy concepts

This sample application demonstrates the following important Core API concepts:

* **Importing messages**—The application uses the [buildRequest()](https://github.com/frontapp/coreapi-import-template/blob/main/src/index.ts#L50) function to map data from an example message file to [interfaces](https://github.com/frontapp/coreapi-import-template/blob/main/src/front_import.ts) that represent Front message types.
* **Setting headers and attachments**—The example application uses [Needle](https://www.npmjs.com/package/needle) to make the [HTTP requests](https://github.com/frontapp/coreapi-import-template/blob/main/src/front_import.ts#L47) and demonstrates how to include headers and attachments.
* **Rate limiting**—Including rate limiting is extremely important to avoid missing data in your integrations, and this project demonstrates [an example](https://github.com/frontapp/coreapi-import-template/blob/main/src/index.ts#L21) of how you can do so with the help of a [utility function](https://github.com/frontapp/coreapi-import-template/blob/main/src/util.ts#L9). Read more about rate limiting [here](https://dev.frontapp.com/docs/rate-limiting).

### Prerequisites

These applications use [Node.js](https://nodejs.org/en/), [Yarn](https://classic.yarnpkg.com/lang/en/docs/getting-started/), and [TypeScript](https://www.typescriptlang.org/), but the concepts can be adapted to any framework. To run this application, however, you will need to install these frameworks.

### Configuring the application

1. Clone the repository from [GitHub](https://github.com/frontapp/coreapi-import-template).
2. In the project root, run `yarn install` to load the project dependencies.
3. In the `.env` file, add your API token to the `API_KEY` variable.

> 👍 How to generate an API token
>
> Learn about authentication [here](https://dev.frontapp.com/docs/authentication). For purposes of this sample application, you can create an [API token](https://dev.frontapp.com/docs/create-and-revoke-api-tokens) to get up and running quickly. Just make sure it has a scope with permissions for the inboxes you want to import messages to. For production applications, you can consider implementing [OAuth](https://dev.frontapp.com/docs/oauth).

> 📘 Keep the `.env` file private
>
> Do not commit the `.env` file to source code, as it can expose your private API key. This project is set up to not track changes to this file.

### Running the demo message import

This application imports randomly generated messages into inboxes of your choice. By default, the example logic generates messages for two inboxes, `sales@example.com` and `support@example.com`, and imports these conversations into two inboxes.

To run this example, complete the following steps:

1. In [src/inbox\_mapping.json](https://github.com/frontapp/coreapi-import-template/blob/main/src/inbox_mapping.json), update the two inbox values with the IDs for the inboxes you want to import messages to. You can use [List inboxes](https://dev.frontapp.com/reference/get_inboxes) to get a list of inbox IDs at your company. You can pick any two inboxes so long as your API token has access to them. You do not need to change the names of the inboxes in this file (`support@example.com`, `sales@example.com`).
2. (Optional) In [src/examples.prepare.ts](https://github.com/frontapp/coreapi-import-template/blob/main/src/examples/prepare.ts), change the `NUM_OF_MESSAGES` and `NUM_OF_CONVERSATIONS` that the message generation script generates. You can also change the inbox handles in `createRecipients` if you'd like, but make sure to update the names of the inboxes in `src/inbox_mapping.json` if you do (otherwise, there won't be any matches so the example logic won't import anything).
3. Run `yarn prepare` to generate the example messages.
4. Run `yarn import` to import the example messages to the inboxes you mapped in `src/inbox_mapping.json`.

> 📘 The import process can take a few minutes (or longer) depending on the number of messages you import. The default number of 5 conversations and 25 messages shouldn't take longer than a minute to complete.

After the import completes, you should see the messages in the Front inboxes you mapped in `src/inbox_mapping.json`. By default, the `src/examples/prepare.ts` file generates messages with random creation dates, but all of them use the subject `I am like the blue rose`. Searching for that phrase should make the messages easy to find.

![1434](https://files.readme.io/dfaae67-Screenshot_2023-02-15_at_1.02.41_PM.png "Screenshot 2023-02-15 at 1.02.41 PM.png")

### Adapting this sample application for production code

This sample application generates random messages and imports them into inboxes of your choosing. To adapt the code to a real-world use case:

* Customize the `buildRequest()` function in [src/index.ts](https://github.com/frontapp/coreapi-import-template/blob/main/src/index.ts#L50) to map messages from your external message system to the Front interface. You can customize the specifics of the mapping [in this section of the function](https://github.com/frontapp/coreapi-import-template/blob/588b7766b4984df1cbdb5a5346ebcd850fc4528a/src/index.ts#L66), which connects to the interfaces set up in the [src/front\_import.ts](https://github.com/frontapp/coreapi-import-template/blob/main/src/front_import.ts) file.
* In the `main()` function in [src/index.ts](https://github.com/frontapp/coreapi-import-template/blob/main/src/index.ts#L18), import messages from your external message system rather than from the example file.
* In the `getInboxId()` function in [src/index.ts](https://github.com/frontapp/coreapi-import-template/blob/main/src/index.ts#L44), update how messages are assigned to inboxes during the import.

  The example code currently routes messages in two ways:

  * For inbound messages, the email of the first recipient determines the inbox the message is imported to. In the real world, you would likely want to want to import the message to additional inboxes based on more detailed routing logic, such as the full list of participants or specific IDs in the subject or body text.
  * For outgoing messages, the email of the sender determines the inbox that the messages are imported to.  In the real world, you would likely want to want to import the message to additional inboxes based on more detailed routing logic, such as the full list of participants or specific IDs in the subject or body text.
  * The mappings in the example code are based on on the [src/inbox\_mapping.json](https://github.com/frontapp/coreapi-import-template/blob/main/src/inbox_mapping.json) file, but you can build a more comprehensive mapping strategy for production code.
* You can get rid of anything in the `examples` directory, as well as the [import](https://github.com/frontapp/coreapi-import-template/blob/4fdb3a4c5e4e29d8ab1cf5b749aeb13fb7a16da3/src/index.ts#L1) in `src/index.ts`, since these files are used only to generate example messages for this tutorial.

## Conversation/Message Export application

This example application demonstrates how to export conversations and messages from Front. This is an ETL script, with Front serving as the *extract* point rather than the *load* point.

**Conversations** are the parent objects for the communications you have in Front inboxes. Each conversation contains **messages** that represent the actual communications between recipients.

For example, if `john@example.com` sends an email to `wendy@example.com` and `gloria@example.com`, and then `gloria@example.com` replies, you would have one conversation with two messages in it (one message from John, and one message from Gloria, all in the same conversation).

### Source code

This project is available on [GitHub](https://github.com/frontapp/coreapi-export-template).

### Noteworthy concepts

This sample application demonstrates the following important Core API concepts:

* **Searching for conversations**—The application [searches for conversations](https://github.com/frontapp/coreapi-export-template/blob/8ebb5053c780a2e5e8aa9eac2d7b9b81ab48dfe2/src/index.ts#L22) by status, exact phrase, and date filters. The [exportSearchConversations](https://github.com/frontapp/coreapi-export-template/blob/8ebb5053c780a2e5e8aa9eac2d7b9b81ab48dfe2/src/export.ts#L43) function demonstrates how you might implement the [Search conversations](https://dev.frontapp.com/reference/search-conversations) API endpoint.
* **Handling pagination**—The [makePaginatedAPIRequest](https://github.com/frontapp/coreapi-export-template/blob/8ebb5053c780a2e5e8aa9eac2d7b9b81ab48dfe2/src/connector.ts#L8) function demonstrates how to aggregate API resources returned by the Core API across multiple pages. You can see an example of a function that awaits the API to return all the inboxes for an account and utilizes the pagination function [here](https://github.com/frontapp/coreapi-export-template/blob/8ebb5053c780a2e5e8aa9eac2d7b9b81ab48dfe2/src/export.ts#L25).
* **Exporting messages, comments, and attachments**—The application demonstrates how to [export conversations](https://github.com/frontapp/coreapi-export-template/blob/8ebb5053c780a2e5e8aa9eac2d7b9b81ab48dfe2/src/export.ts#L53-L110) with all messages, comments, and attachments included.
* **Typing responses from the Core API**—The application contains [non-exhaustive typing](https://github.com/frontapp/coreapi-export-template/blob/main/src/types.ts) for responses from Front's API, which allows for easy casting in paginated responses.
* **Rate limiting**—Including rate limiting is extremely important to avoid missing data in your integrations, and this project demonstrates [an example](https://github.com/frontapp/coreapi-export-template/blob/8ebb5053c780a2e5e8aa9eac2d7b9b81ab48dfe2/src/connector.ts#L45) of how you can do so. Read more about rate limiting [here](https://dev.frontapp.com/docs/rate-limiting).

### Prerequisites

These applications use [Node.js](https://nodejs.org/en/), [Yarn](https://classic.yarnpkg.com/lang/en/docs/getting-started/), and [TypeScript](https://www.typescriptlang.org/), but the concepts can be adapted to any framework. To run this application, however, you will need to install these frameworks.

### Configuring the application

1. Clone the repository from [GitHub](https://github.com/frontapp/coreapi-export-template).
2. In the project root, run `yarn install` to load the project dependencies.
3. In the `.env` file, add your API token to the `API_KEY` variable.

> 👍 How to generate an API token
>
> Learn about authentication [here](https://dev.frontapp.com/docs/authentication). For purposes of this sample application, you can create an [API token](https://dev.frontapp.com/docs/create-and-revoke-api-tokens) to get up and running quickly. Just make sure it has a scope with permissions for the inboxes you want to import messages to. For production applications, you can consider implementing [OAuth](https://dev.frontapp.com/docs/oauth).

> 📘 Keep the `.env` file private
>
> Do not commit the `.env` file to source code, as it can expose your private API key. This project is set up to not track changes to this file.

### Running the demo message export

This application searches for conversations that match the criteria specified in the [configuration file](https://github.com/frontapp/coreapi-export-template/blob/main/src/index.ts). The application searches through all the inboxes that your API token has access to. For each conversation that matches, the export application will generate JSON files that contain the conversation details, including the details of the messages, comments, and attachments of the conversation (depending on which options you enabled in the configuration).

To run this example, complete the following steps:

1. In [src/index.ts](https://github.com/frontapp/coreapi-export-template/blob/main/src/index.ts), choose:

* Whether to include messages, comments, and attachments in the [options](https://github.com/frontapp/coreapi-export-template/blob/150c7670d8e65e66051d1c93fb588447b2f98bd4/src/index.ts#L3-L7).
* How to [search for conversations](https://github.com/frontapp/coreapi-export-template/blob/150c7670d8e65e66051d1c93fb588447b2f98bd4/src/index.ts#L22-L26).
  * The first argument is a phrase the conversation should contain. Use double quotes if you want an exact match, or omit the double quotes if you desire partial matching.
  * The second argument is a `before`, `after`, or `during` Unix timestamp for when the first message in the conversation was created. Read more about these filters in our [Search](https://dev.frontapp.com/docs/search-1#supported-search-filters) topic.
  * The third argument is the conversation status. Read more about the `is` status filter in our our [Search](https://dev.frontapp.com/docs/search-1#supported-search-filters) topic.
* If you want to search for all messages in an inbox, you can adapt the code to `FrontExport.exportSearchConversations(*inbox*, options)`.
* If you want to search for all messages across all inboxes, uncomment [this section](https://github.com/frontapp/coreapi-export-template/blob/150c7670d8e65e66051d1c93fb588447b2f98bd4/src/index.ts#L9-L20) and comment out [this section](https://github.com/frontapp/coreapi-export-template/blob/150c7670d8e65e66051d1c93fb588447b2f98bd4/src/index.ts#L22-L26).
* By default, the export application includes all messages, comments, and attachments, and searches for conversations that contain the exact phrase "cup of coffee", were created after September 13th, 2020, and have an Open status.

> 📘 The export process can take a while to complete
>
> The export process can take a lengthy time to complete, depending on how many conversations match your search. We recommend starting with a conversation search that will return limited results so that you can gauge the time it might take for a full export in a real-world scenario.

2. Run `yarn start` to run the export.

After the export completes, the application generates an `export` directory that contains JSON files for each conversation and its associated messages that matched your search.

### Adapting this sample application for production code

This sample application generates JSON files for conversations that match a search query. To adapt this application for production code, you should consider the following items:

* Customize the [conversation search](https://github.com/frontapp/coreapi-export-template/blob/8ebb5053c780a2e5e8aa9eac2d7b9b81ab48dfe2/src/index.ts#L23) for the real-world use case you are implementing. You can augment the [exportSearchConversations](https://github.com/frontapp/coreapi-export-template/blob/150c7670d8e65e66051d1c93fb588447b2f98bd4/src/export.ts#L43) function to include more [filters](https://dev.frontapp.com/docs/search-1#supported-search-filters) in the [query arguments](https://github.com/frontapp/coreapi-export-template/blob/150c7670d8e65e66051d1c93fb588447b2f98bd4/src/export.ts#L112-L149) provided by the sample application.
* Define how you would like to load the extracted data in the [src/helpers.ts](https://github.com/frontapp/coreapi-export-template/blob/main/src/helpers.ts) file. This sample application only writes the data to an `export` folder.
* Consider [filtering which inboxes](https://github.com/frontapp/coreapi-export-template/blob/8ebb5053c780a2e5e8aa9eac2d7b9b81ab48dfe2/src/export.ts#L24) the export applies to. The sample application currently lists all inboxes the API token has access to.