> ## Documentation Index
> Fetch the complete documentation index at: https://docs.eazecustoms.com/llms.txt
> Use this file to discover all available pages before exploring further.

# File Uploads

> Learn how to prepare and upload CSV or Excel files, send the exact file contents, and use the uploaded file in an import.

## What you can do

Upload a CSV or Excel file and receive an `uploadId`. Use this ID to import a Shipment Manifest or NCTS Departure Goods.

Uploading a file does not create a Declaration or Transit Declaration. You must make a separate import request to process the uploaded file.

## Before you start

Make sure you have valid Eaze Customs API credentials and the `X-Eaze-Client-Ref` header.

> [!NOTE]
>
> Create Upload, Complete Upload, and Get Upload currently require the `ncts` module on the credential, including when the file is a Shipment manifest. A credential that only has `import` or `export` cannot call these routes.

| Purpose | Use it for | Content type |
| - | - | - |
| `shipment_manifest` | [Manifest Import](https://docs.eazecustoms.com/implementation/manifest-import.md) | `text/csv` or the Excel content type below |
| `ncts_items` | [NCTS Departure](https://docs.eazecustoms.com/implementation/ncts-departure.md) | `text/csv` or the Excel content type below |

The Excel content type is `application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`.

The file must be 20 MiB or smaller (20,971,520 bytes). The filename starts with a letter or number, is at most 200 characters, uses only letters, numbers, spaces, and `. _ ( ) -`, and does not contain `..`. The extension must match the content type: `.csv` or `.xlsx`.

## Steps

```mermaid theme={null}
flowchart LR
  prepare["1. Read the file bytes"] --> create["2. Create Upload"]
  create --> put["3. PUT the same bytes"]
  put --> complete["4. Complete Upload"]
  complete --> importFile["5. Import with uploadId"]
```

**1. Prepare the file**

Read the file as bytes. `byteLength` is the exact size of those bytes. `sha256` is the SHA-256 fingerprint of the same bytes, written as 64 lowercase hexadecimal characters.

Calculate both values in your integration. Do not re-save or re-encode the file between the calculation and the upload.

**2. Get an upload URL**

Call [Create Upload](https://docs.eazecustoms.com/api-reference/uploads/create-upload.md) with `purpose`, `filename`, `contentType`, `byteLength`, and `sha256`. Send a new `Idempotency-Key`.

The response status is `pending`. It includes `upload.method`, `upload.url`, and `upload.requiredHeaders`. The URL expires in 15 minutes.

**3. Upload and verify**

Send an HTTP `PUT` of the original bytes to `upload.url`. Set every header in `requiredHeaders` exactly as returned. This is not a multipart form upload.

The storage service may answer HTTP 200 with an empty body. Do not parse that body as JSON. A successful PUT does not finish the Eaze Customs upload.

Call [Complete Upload](https://docs.eazecustoms.com/api-reference/uploads/complete-upload.md). Eaze Customs checks the size, checksum, content type, and file structure. This check is not an antivirus scan. A successful completion returns `status: available`.

Call [Get Upload](https://docs.eazecustoms.com/api-reference/uploads/get-upload.md) if you need to confirm `readyForImport`. That flag is true only when the status is `available`.

**4. Import the file**

Use the verified `uploadId` in [Import Manifest](https://docs.eazecustoms.com/api-reference/shipments/import-manifest.md) or [Import Departure Details](https://docs.eazecustoms.com/api-reference/ncts/import-departure-details.md). Then follow [Operations](https://docs.eazecustoms.com/implementation/operations.md).

Each upload can be used for one import. That reservation stays even when the import fails or requires review. A second import needs a new upload and a new `uploadId`.

## Working example

This example uses the same bytes for the fingerprint, the upload, and the import. The sample CSV is 73 bytes. Its SHA-256 is `4ea9a34e9b058915cb420a3b6f18fee40a6b877b0f330e33b5497c1fc0370a4d`.

```javascript theme={null}
import { createHash, randomUUID } from 'node:crypto';
import { readFile } from 'node:fs/promises';

const baseUrl = 'https://staging.api.eazecustoms.com';
const credential = process.env.EAZE_CUSTOMS_API_CREDENTIAL;
const clientRef = 'ACME-AMS';

async function api(path, { method = 'GET', body, idempotencyKey } = {}) {
  const response = await fetch(`${baseUrl}${path}`, {
    method,
    headers: {
      Authorization: `Bearer ${credential}`,
      'X-Eaze-Client-Ref': clientRef,
      ...(body ? { 'Content-Type': 'application/json' } : {}),
      ...(idempotencyKey ? { 'Idempotency-Key': idempotencyKey } : {}),
    },
    body: body ? JSON.stringify(body) : undefined,
  });
  if (!response.ok) throw new Error(`${method} ${path} failed: ${response.status} ${await response.text()}`);
  return response.status === 204 ? null : response.json();
}

const fileBytes = await readFile('./manifest.csv');
const sha256 = createHash('sha256').update(fileBytes).digest('hex');

const created = await api('/public/v1/uploads', {
  method: 'POST',
  idempotencyKey: randomUUID(),
  body: {
    purpose: 'shipment_manifest',
    filename: 'manifest.csv',
    contentType: 'text/csv',
    byteLength: fileBytes.byteLength,
    sha256,
  },
});

const put = await fetch(created.upload.url, {
  method: created.upload.method,
  headers: created.upload.requiredHeaders,
  body: fileBytes,
});
if (!put.ok) throw new Error(`Storage upload failed: ${put.status}`);

const ready = await api(`/public/v1/uploads/${created.id}/complete`, {
  method: 'POST',
  idempotencyKey: randomUUID(),
});
if (ready.status !== 'available') throw new Error(`Upload is ${ready.status}`);

const accepted = await api(`/public/v1/shipments/${shipmentId}/details/import`, {
  method: 'POST',
  idempotencyKey: randomUUID(),
  body: {
    uploadId: ready.id,
    manifestTemplateId: '77777777-7777-4777-8777-777777777777',
    mode: 'INITIAL',
  },
});
```

Replace `shipmentId` with the Shipment you created. HTTP 202 from the import means the file was accepted for processing. Read the Operation before you treat the import as successful. The full sequence is in [Manifest Import](https://docs.eazecustoms.com/implementation/manifest-import.md) and [Examples](https://docs.eazecustoms.com/implementation/examples.md).

For a large file, hash and upload a stream of the same bytes. The fingerprint and `byteLength` must still describe the exact bytes you PUT.

> [tab] Python
>
> ```python theme={null}
> import hashlib
> from pathlib import Path
> import requests
>
> file_bytes = Path("manifest.csv").read_bytes()
> sha256 = hashlib.sha256(file_bytes).hexdigest()
> created = requests.post(
>     "https://staging.api.eazecustoms.com/public/v1/uploads",
>     headers={
>         "Authorization": f"Bearer {credential}",
>         "X-Eaze-Client-Ref": "ACME-AMS",
>         "Idempotency-Key": idempotency_key,
>     },
>     json={
>         "purpose": "shipment_manifest",
>         "filename": "manifest.csv",
>         "contentType": "text/csv",
>         "byteLength": len(file_bytes),
>         "sha256": sha256,
>     },
>     timeout=30,
> ).json()
> requests.put(
>     created["upload"]["url"],
>     headers=created["upload"]["requiredHeaders"],
>     data=file_bytes,
>     timeout=120,
> ).raise_for_status()
> ```

> [tab] C#
>
> ```csharp theme={null}
> var baseUrl = "https://staging.api.eazecustoms.com";
> var fileBytes = await File.ReadAllBytesAsync("manifest.csv");
> var sha256 = Convert.ToHexString(SHA256.HashData(fileBytes)).ToLowerInvariant();
> using var create = new HttpRequestMessage(HttpMethod.Post, $"{baseUrl}/public/v1/uploads");
> create.Headers.Authorization = new AuthenticationHeaderValue("Bearer", credential);
> create.Headers.Add("X-Eaze-Client-Ref", "ACME-AMS");
> create.Headers.Add("Idempotency-Key", Guid.NewGuid().ToString());
> create.Content = JsonContent.Create(new {
>     purpose = "shipment_manifest",
>     filename = "manifest.csv",
>     contentType = "text/csv",
>     byteLength = fileBytes.Length,
>     sha256
> });
> ```

A CSV file must be UTF-8 and must not contain NUL bytes. An Excel file must be a real `.xlsx` workbook. An NCTS goods file cannot contain more than 999 items in one house consignment. A Shipment manifest is checked against the Manifest Template later, during import.

## Statuses and errors

| Status | What it means | What happens next |
| - | - | - |
| `pending` | The upload URL was issued. | PUT the file, then call Complete Upload. |
| `quarantined` | The file is stored and waiting for the structure check. | Call Complete Upload, or read the upload again. |
| `available` | The file is verified and ready. | Use `uploadId` in one import. |
| `rejected` | The file failed verification. | Correct the file and create a new upload. `rejectionCode` explains the check that failed. |
| `expired` | The 15-minute session ended before completion. | Create a new upload. |
| `deleted` | The upload can no longer be used. | Create a new upload. |

Common failures:

| Situation | What to do |
| - | - |
| HTTP 409, upload already used | Create and complete a fresh upload. Use a new idempotency key for the new import. |
| Checksum, size, or content-type mismatch | The PUT bytes differ from the metadata. Create a new upload from the corrected bytes. |
| HTTP 413 | The file is larger than 20 MiB. |
| HTTP 415 | The content type or extension is not CSV or Excel. |
| HTTP 422 | Verification failed. Read `errors[].code`. Examples include `invalid_csv_encoding` and `upload_item_limit_exceeded`. |

`scanRequired` is a legacy field. It is true while checking is still pending and false after a successful completion. It does not describe an antivirus scan.

Optional local check, not an integration step: `wc -c manifest.csv` and `shasum -a 256 manifest.csv` show the same size and fingerprint your code should calculate.

Next: [Idempotency](https://docs.eazecustoms.com/implementation/idempotency.md), then [Shipments](https://docs.eazecustoms.com/implementation/shipments.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.