---
title: "Import collection data"
method: POST
path: "/_fabric/{fabric}/_api/import/{collection}"
tags: ["Import Export"]
---

# Import collection data

`POST /_fabric/{fabric}/_api/import/{collection}`

## Request

- The document declares no server URL.
- Auth: one of:
  - API key in header `Authorization`
  - HTTP bearer
- TypeScript: <https://skmtc.dev/macrometa/apis/macrometa-api-reference/docs/_fabric/:fabric/_api/import/:collection/post.ts> (a function with typed inputs; its response is checked against the schema)

Create documents in the collection identified by collection parameter.

## Path parameters

- `fabric` string, string, required
- `collection` string, string, required

## Request body

- ApiImport
  - `data` object[]: An array of JSON documents. Each document is interpreted separately. If the `primaryKey` property (see below) is not set or equals `auto`, then the `_key` attribute values of the documents must be strings. The maximum number of documents that can be imported is limited by the `Max Documents Imported Per API Call` limit.
  - `details` boolean: If *true* extra information for errors and unprocessed documents are returned in the result.
  - `primaryKey` string, string: If used, this attribute becomes the *_key* for the new document. If the values in the attribute are not strings, they are convert to strings before import. Any existing *_key* value is renamed to *old_key*. Use the following naming convention: https://macrometa.dev/documents/naming-conventions/#document-keys
  - `replace` boolean: If *true*, existing document having same *_key* in the colletion, shall be replaced.

## Response `200`

Successfully imported data.

If there are any errors, an additional header *X-C8-Error-Codes* is set, that contains a map of the error codes that occurred together with their multiplicities, as in: 1205:10,1210:17 which means that in 10 cases the error 1205 "illegal document handle" and in 17 cases the error 1210 "unique constraint violated" has happened. The response body has additional failed document details in *details* object.

- ImportHttpExamplesRc200
  - `code` integer: HTTP response code.
  - `error` boolean: Flag if there is an error in response. *False* for this response.
  - `result` object
    - `created` integer: Number of records created.
    - `errors` integer: Number of records with errors.
    - `unprocessed` integer: Number of records not processed.

## Other responses

- `400`: Failed due to missing or malformed data. Verify that all parameters are complete.
- `401`: Failed to validate because you do not have access to the GeoFabric.
- `403`: Failed to validate because you do not have access to the server.

---

[API](https://skmtc.dev/macrometa/apis/macrometa-api-reference.md) - [All operations](https://skmtc.dev/macrometa/apis/macrometa-api-reference/llms.txt) - [OpenAPI document](https://skmtc.dev/macrometa/apis/macrometa-api-reference/revisions/2006b6d7f31d?raw)
