# Import a file

`POST /api/v1/imports`

Send an export of Monica 4, or an export of this application, to be read. Nothing is written into a vault yet.

Send the file as multipart form data, in a field called file. A file over 512 MB answers 422. The console of the instance imports a larger one with php artisan monica:import-account.

The file is read in the background. Ask for the import until its status is read, look at what it holds, then choose where it goes with PUT /imports/{accountImport}. A file that cannot be imported ends as refused, with the reason.

An account runs one import at a time. Sending a file while another import is reading, waiting for a decision, writing or being undone answers 422.

## Body parameters

- `file` (file, required): The export, as the JSON file Monica 4 or this application wrote it, at most 512 MB.

## Returns

The import object, reading the file.

- `data` (object): The import.
- `data.type` (string): Always account_import. It names the kind of record, so a caller holding several kinds can tell them apart without looking at where they came from.
- `data.id` (string): The id of this record, as a string even when it reads as a number. It is what every endpoint naming this record takes.
- `data.attributes` (object): Everything the record holds.
- `data.attributes.status` (string): Where the import stands: reading, refused, read, writing, rolling_back, rolled_back, rollback_failed or completed. rollback_failed means an undo kept failing and what the import wrote is still in place. Nothing is written into a vault before the file is read and you have chosen where it goes.
- `data.attributes.source_format` (string): What the file is: monica_4 for an export of Monica 4, monica for an export of this application. Null while the file is read, and when it was refused as neither.
- `data.attributes.refusal` (string): Why the file cannot be imported, when the status is refused. Null otherwise.
- `data.attributes.already_imported_into` (array): The vaults this same file was completely imported into before. An import only adds, so importing it again into one of them writes every record a second time.
- `data.attributes.already_imported_into[]` (uuid): The id of one of those vaults.
- `data.attributes.progress` (object): How far the writing has gone.
- `data.attributes.progress.done` (integer): How many records are written.
- `data.attributes.progress.total` (integer): How many records there are to write, known once the file is read.
- `data.attributes.vault` (uuid): The id of the vault the file is written into, or null until one is chosen.
- `data.attributes.me_contact` (string): The id, in the file, of the contact who is you, or null for none. Until you choose, it is the contact the file names as its owner.
- `data.attributes.created_at` (timestamp): When the file was received, as a count of seconds since 1970.
- `data.attributes.ended_at` (timestamp): When the import completed or finished being undone, as a count of seconds since 1970, or null.
- `data.attributes.summary` (array): What the file holds, one entry per kind of record, once it is read. Null while it is read.
- `data.attributes.report` (array): What became of the records of the file, one entry per kind, once the import has completed. Null before that, and for an import that was undone, since nothing of it stayed.
- `data.links` (object): Where to find this record.
- `data.links.self` (string): The absolute address this record is read from.

## Rate limit

Sixty requests per minute, per user, shared by every key and device. Every answer carries the budget left in `X-RateLimit-Remaining`.

## Request

```sh
curl https://my.monicahq.com/api/v1/imports \
  -X POST \
  -H "Authorization: Bearer $MONICA_TOKEN"
```

```javascript
const response = await fetch('https://my.monicahq.com/api/v1/imports', {
  method: 'POST',
  headers: { Authorization: `Bearer ${token}` },
})
const data = await response.json()
```

```php
$response = Http::withToken($token)->post('https://my.monicahq.com/api/v1/imports');
```

## Response

`202`

```json
{
    "data": {
        "type": "account_import",
        "id": "3f8a1c52-7d4e-4b19-9a06-c2e5b8d71f40",
        "attributes": {
            "status": "reading",
            "source_format": null,
            "refusal": null,
            "summary": null,
            "already_imported_into": [
                "9b2d4f6a-1e3c-4a5b-8c7d-0f1e2d3c4b5a"
            ],
            "progress": {
                "done": 0,
                "total": 0
            },
            "vault": null,
            "me_contact": null,
            "report": null,
            "created_at": 1792310400,
            "ended_at": null
        },
        "links": {
            "self": "https://my.monicahq.com/api/v1/imports/3f8a1c52-7d4e-4b19-9a06-c2e5b8d71f40"
        }
    }
}
```
