# Import forms

URL: https://docs.hanzo.ai/docs/openapi/form/import-form-responses

> Brings responses made elsewhere into a form, keeping when each was made, a batch of at most 500 at a time.

`POST /v1/form/forms/{id}/import`

> [Form →](https://docs.hanzo.ai/docs/openapi/form) · [All API references →](https://docs.hanzo.ai/docs/openapi) · [Get started →](https://docs.hanzo.ai/docs/guides)

|               |                                                  |
| ------------- | ------------------------------------------------ |
| **Address**   | `https://api.hanzo.ai/v1/form/forms/{id}/import` |
| **Method**    | `POST`                                           |
| **Operation** | `import_form_responses`                          |
| **Auth**      | `Authorization: Bearer $HANZO_API_KEY`           |

Brings responses made elsewhere into a form, keeping when each was made, a
batch of at most 500 at a time. Each is keyed by its external id (on a
subscribe form, by its address), so a batch sent again, or an import resumed
from any point, makes nothing twice. Each answer is read against its field as
a submission's is; a required field may be unanswered. With file, each new
response is also filed in the CRM at the time it was made; nothing is mailed
and no webhook is told. An org admin only.

## Request

18 fields, body `application/json` (required).

| Field                           | In   | Type             | Required | Description                                                                                                                       |
| ------------------------------- | ---- | ---------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------- |
| `id`                            | path | string           | yes      | ID is the form's id or slug, from the path.                                                                                       |
| `file`                          | body | boolean          | —        | File also files each new response in the CRM, at the time it was made.                                                            |
| `id`                            | body | string           | —        | ID is the form's id or slug, from the path.                                                                                       |
| `responses`                     | body | form.Imported\[] | —        | Responses are the responses, at most 500.                                                                                         |
| `responses[].answers`           | body | form.Answer\[]   | —        | Answers are its answers, each read against the form's field as a submission's is; a required field may be unanswered.             |
| `responses[].answers[].boolean` | body | boolean          | —        |                                                                                                                                   |
| `responses[].answers[].choices` | body | string\[]        | —        |                                                                                                                                   |
| `responses[].answers[].date`    | body | string           | —        |                                                                                                                                   |
| `responses[].answers[].field`   | body | string           | —        | Field is the ref of the field answered.                                                                                           |
| `responses[].answers[].number`  | body | number (double)  | —        |                                                                                                                                   |
| `responses[].answers[].text`    | body | string           | —        |                                                                                                                                   |
| `responses[].answers[].type`    | body | string           | —        | Type is the field's type.                                                                                                         |
| `responses[].at`                | body | string           | —        | At is when it was made, RFC 3339.                                                                                                 |
| `responses[].email`             | body | string           | —        | Email is the address it was from, when the source knew one.                                                                       |
| `responses[].external`          | body | string           | —        | External is its id where it was made: at most 200 characters, and the response's key, so importing it again is the same response. |
| `responses[].hidden`            | body | object           | —        | Hidden are values it carried, by the names the form declares.                                                                     |
| `responses[].hidden.*`          | body | string           | —        |                                                                                                                                   |
| `responses[].source`            | body | string           | —        | Source is where it was made, at most 100 characters: commerce, a list's name.                                                     |

## Response

| Status    | Body            | Meaning |
| --------- | --------------- | ------- |
| `200`     | form.Imports    | ok      |
| `default` | problem-details | refused |

`200` body — 5 fields.

| Field               | In   | Type                  | Always | Description                                                                     |
| ------------------- | ---- | --------------------- | ------ | ------------------------------------------------------------------------------- |
| `created`           | body | integer (int64)       | —      | Created counts the responses made new.                                          |
| `existing`          | body | integer (int64)       | —      | Existing counts the ones already held: imported before, or the same subscriber. |
| `failed`            | body | form.ImportFailure\[] | —      | Failed are the ones refused, with why.                                          |
| `failed[].external` | body | string                | —      |                                                                                 |
| `failed[].reason`   | body | string                | —      |                                                                                 |

Failure carries the platform error shape — see [Errors](https://docs.hanzo.ai/docs/errors).

## Examples

**CLI**

```bash
hanzo form forms import <id>
```

**SDK**

**.ts**

```ts
import { Configuration, FormApi } from 'hanzoai';

const api = new FormApi(new Configuration({ accessToken: process.env.HANZO_API_KEY }));
const { data } = await api.importFormResponses({ id: 'id', file: false, id: "<id>" });
```

**.py**

```python
from hanzoai.cloud import ApiClient, Configuration
from hanzoai.cloud.api import FormApi

client = ApiClient(Configuration(access_token=os.environ["HANZO_API_KEY"]))
result = FormApi(client).import_form_responses(id='id', file=False, id="<id>")
```

**.go**

```go
cfg := hanzoai.NewConfiguration()
cfg.AddDefaultHeader("Authorization", "Bearer "+os.Getenv("HANZO_API_KEY"))
client := hanzoai.NewAPIClient(cfg)

resp, _, err := client.FormAPI.ImportFormResponses(context.Background()).Execute()
if err != nil {
	return err
}
```

**.rs**

```rust
use hanzo_client::apis::{configuration::Configuration, form_api};

let mut cfg = Configuration::new();
cfg.bearer_access_token = std::env::var("HANZO_API_KEY").ok();

let result = form_api::import_form_responses(&cfg, Default::default()).await?;
```

**.java**

```java
import ai.hanzo.cloud.ApiClient;
import ai.hanzo.cloud.api.FormApi;

ApiClient client = new ApiClient();
client.setBearerToken(System.getenv("HANZO_API_KEY"));

var result = new FormApi(client).importFormResponses();
```

The method above is the one at the current release of the document. `hanzoai@8.5.914` (npm) and `hanzoai@8.5.914` (PyPI) were generated from an earlier release, where this operation carried a different id, so it spells the method differently — regenerating the clients is what makes the two agree. [SDKs →](https://docs.hanzo.ai/docs/sdks)

**HTTP**

```bash
curl -X POST https://api.hanzo.ai/v1/form/forms/<id>/import \
  -H "Authorization: Bearer $HANZO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
       "file": false,
       "id": "<id>"
     }'
```

**MCP**

Tool `form`, op `import_form_responses` — POST the JSON-RPC envelope to `https://api.hanzo.ai/v1/mcp`.

```bash
curl -X POST https://api.hanzo.ai/v1/mcp \
  -H "Authorization: Bearer $HANZO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
       "jsonrpc": "2.0",
       "id": 1,
       "method": "tools/call",
       "params": {
         "name": "form",
         "arguments": {
           "op": "import_form_responses",
           "input": {
             "id": "<id>",
             "file": false
           }
         }
       }
     }'
```

---

[Form API](https://docs.hanzo.ai/docs/openapi/form) · [All Hanzo APIs](https://docs.hanzo.ai/docs/openapi) · [Interactive reference](https://docs.hanzo.ai/docs/openapi/reference)
