> ## Documentation Index
> Fetch the complete documentation index at: https://flatfileinc-feat-updatereactquickstart.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# @flatfile/plugin-automap

> A plugin to provide automapping imported files for headless workflows.

<Warning>
  When embedding Flatfile, this plugin should be deployed in a server-side
  listener. [Learn more](/orchestration/listeners#listener-types)
</Warning>

<CardGroup cols={1}>
  <Card title="@flatfile/plugin-automap" icon="download">
    The `@flatfile/plugin-automap` plugin listens for and responds to file
    extraction jobs and then creates a mapping job for automation. Currently,
    every field in the Job Execution plan must meet the minimum confidence level
    specified by the `accuracy` config prop.
  </Card>
</CardGroup>

## Parameters

<ParamField path="accuracy" required type="'confident' | 'exact'">
  The `accuracy` parameter match columns either by 'confident' (> 90% match) or
  'exact' (100% match).
</ParamField>

<ParamField path="debug" type="boolean">
  The `debug` parameter lets you toggle on/off helpful debugging messages for
  development purposes.
</ParamField>

<ParamField path="defaultTargetSheet" type="'string' | '(fileName: string) => string | Promise<string>'">
  The `defaultTargetSheet` parameter takes the exact sheet slug or a callback
  function that resolves to the exact sheet slug to import data to.
</ParamField>

<ParamField path="matchFilename" type="RegExp">
  The `matchFilename` parameter takes a regular expression to match specific
  files to perform automapping on.
</ParamField>

<ParamField path="onFailure" type="(event: FlatfileEvent) => void">
  The `onFailure` parameter takes a callback function to be executed when plugin
  bails.
</ParamField>

<ParamField path="targetWorkbook" type="string">
  The `targetWorkbook` parameter specifies destination Workbook id or name.
</ParamField>

## API Calls

* `api.files.get`
* `api.files.update`
* `api.jobs.create`
* `api.jobs.execute`
* `api.jobs.getExecutionPlan`
* `api.workbooks.list`
* `api.workbooks.get`

## Imported NPM Packages

* [`@flatfile/api@1.5.11+`](https://www.npmjs.com/package/@flatfile/api) is the official Flatfile SDK for JavaScript.
* [`@flatfile/common-plugin-utils@1.0.1+`](https://www.npmjs.com/package/@flatfile/common-plugin-utils) is a utility library for Flatfile plugins.
* [`@flatfile/listener@0.3.15+`](https://www.npmjs.com/package/@flatfile/listener) is a library for listening to Flatfile events.
* [`@flatfile/utils-debugger@0.0.3+`](https://www.npmjs.com/package/@flatfile/utils-debugger) is a utility debugger designed to facilitate the tracking, logging and debugging of various events, issues and processes in your application.
* [`remeda`](https://remedajs.com/) offers a set of utility functions for functional programming and data manipulation in JavaScript, providing a convenient way to work with arrays and objects.

## Usage

For automation workflows, upload a file using the `files` endpoint. For testing, you import via the Files area in the UI and use the `debug` config property.

```bash install
npm i @flatfile/plugin-automap
```

```ts
import { automap } from "@flatfile/plugin-automap";
```

```ts listener.ts
listener.use(
  automap({
    accuracy: "confident",
    defaultTargetSheet: "Contact",
    matchFilename: /test.csv$/g,
    onFailure: (event: FlatfileEvent) => {
      // send an SMS, an email, post to an endpoint, etc.
      console.error(
        `Please visit https://spaces.flatfile.com/space/${event.context.spaceId}/files?mode=import to manually import file.`
      );
    },
  })
);
```

## See the code

<CardGroup cols={2}>
  <Card title="@flatfile/plugin-automap" href="https://github.com/FlatFilers/flatfile-plugins/tree/main/plugins/automap" icon="github" />
</CardGroup>
