create-datahub-invoice-import
dci create-datahub-invoice-import [body]
Uploads one PDF invoice and imports it into a DataHub dataset in a single call; there is no confirm step. The call returns 202 with an import id straight away. Extraction and import continue in the background and usually finish within a minute: poll getDatahubInvoiceImport with the id until status is no longer processing.
Send the PDF either as multipart/form-data (file part) or as application/json (fileName plus contentBase64, the file bytes in standard base64). Both forms accept the same options and behave identically. The decoded file must be a PDF of at most 4,718,592 bytes (4.5 MB) and 20 pages.
Dataset choice: send dataset to import into an existing dataset, or newDatasetName to create one; the two are mutually exclusive. With neither, the suggested existing dataset is used if there is one, otherwise a dataset named after the vendor is created. costDating chooses one record per line per day over the service period (daily) or one record per line on the invoice date (invoiceDate). When omitted, daily is used if the invoice states a billing period, otherwise invoiceDate.
An identical file is refused with 409 duplicate_invoice unless force is true. A different file with the same vendor and invoice number as an earlier import is accepted with 202, and the import then ends with status duplicate unless force is true. force replaces the earlier import, but DataHub only allows that 90 minutes after the earlier import; before that the import ends as failed with errorCode replace_not_yet_available and retryAfter set to the time it becomes available.
Because no person reviews an API import, automatic checks are its only guard: when the extracted lines do not add up to the invoice total, no exchange rate exists for the invoice currency and date, the vendor, invoice date, currency or total was read with low confidence, or a line amount is more than ten times the invoice total (often a quantity read as money), nothing is written and the import ends as needsReview. A DataHub Admin can fix and import it from the Invoice imports list in the DoiT console.
Requires the DataHub Admin permission and a customer entitled to DataHub. At most 50 invoices per customer per day are accepted.
Every error response has code (stable, machine-readable) and error (a message). Error codes and what to do:
invalid_request(400): the body is malformed,datasetandnewDatasetNamewere both sent,costDatingis notdailyorinvoiceDate,forceis not a boolean, or the file is missing or empty. Fix the request named inerrorand resend.file_too_large(400): the decoded file is over 4,718,592 bytes. Send a smaller PDF.not_a_pdf(400): the file is not a PDF. Send a PDF file.invalid_dataset_name(400):newDatasetNameis not a valid dataset name. Use letters, digits, underscores, dashes and single spaces, and avoid names reserved for built-in providers, such asgoogle-cloud. Adatasetthat does not exist is only detected after extraction and ends the import asneedsReview; seegetDatahubInvoiceImport.unsupported_media_type(415): theContent-Typeis notmultipart/form-dataorapplication/json. Resend as one of them.duplicate_invoice(409): this exact file was already uploaded, and that import is imported, still processing or awaiting review;existingImportIdnames it anderrorsays which. Read it withgetDatahubInvoiceImport, or resend withforceset totrueto replace it.daily_limit_reached(429): the daily limit of 50 invoices per customer was reached. Retry the next day (UTC).
Pass the request body as name: value arguments or pipe JSON on stdin — see Command structure.
Request
Content-Type: application/json
| Field | Type | Required | Description |
|---|---|---|---|
fileName | string | Name of the file, for display in the DoiT console. Defaults to invoice.pdf. | |
contentBase64 | string (byte) | yes | The PDF bytes in standard base64. The decoded file must be at most 4,718,592 bytes. |
dataset | string | Import into this existing dataset. Mutually exclusive with newDatasetName; sending both returns 400 invalid_request. | |
newDatasetName | string | Create a dataset with this name and import into it. Mutually exclusive with dataset. | |
costDating | string | daily writes one record per line per day of the service period; invoiceDate writes one record per line on the invoice date. When omitted, daily is used if the invoice states a billing period, otherwise invoiceDate. One of: "daily", "invoiceDate". | |
force | boolean | Replace an earlier import of the same invoice. Allowed only 90 minutes after that import; sooner, the import ends as failed with errorCode replace_not_yet_available. Default: false. |
Example body (JSON)
{
"fileName": "invoice-INV-1042.pdf",
"contentBase64": "JVBERi0xLjQKJSVFT0YK",
"newDatasetName": "Example Vendor",
"costDating": "invoiceDate"
}
Raw JSON schema
{
"type": "object",
"required": [
"contentBase64"
],
"not": {
"required": [
"dataset",
"newDatasetName"
]
},
"properties": {
"fileName": {
"type": "string",
"description": "Name of the file, for display in the DoiT console. Defaults to `invoice.pdf`.",
"example": "invoice-INV-1042.pdf"
},
"contentBase64": {
"type": "string",
"format": "byte",
"description": "The PDF bytes in standard base64. The decoded file must be at most 4,718,592 bytes."
},
"dataset": {
"type": "string",
"description": "Import into this existing dataset. Mutually exclusive with `newDatasetName`; sending both returns `400` `invalid_request`.",
"example": "Example Vendor"
},
"newDatasetName": {
"type": "string",
"description": "Create a dataset with this name and import into it. Mutually exclusive with `dataset`.",
"example": "Example Vendor"
},
"costDating": {
"type": "string",
"enum": [
"daily",
"invoiceDate"
],
"description": "`daily` writes one record per line per day of the service period; `invoiceDate` writes one record per line on the invoice date. When omitted, `daily` is used if the invoice states a billing period, otherwise `invoiceDate`."
},
"force": {
"type": "boolean",
"default": false,
"description": "Replace an earlier import of the same invoice. Allowed only 90 minutes after that import; sooner, the import ends as `failed` with `errorCode` `replace_not_yet_available`."
}
}
}
Output
Accepted - The PDF was stored and extraction has started. Poll getDatahubInvoiceImport with id.
By default dci renders the result as a table. Use --output json to get the full structure described below — see Output formats.
| Field | Type | Description |
|---|---|---|
id | string | The import id. Pass it to getDatahubInvoiceImport. |
status | string | Always processing on creation. One of: "processing". |
Example response (--output json)
{
"id": "8f2c1a7e4b9d",
"status": "processing"
}
Raw JSON schema
{
"type": "object",
"required": [
"id",
"status"
],
"properties": {
"id": {
"type": "string",
"description": "The import id. Pass it to `getDatahubInvoiceImport`.",
"example": "8f2c1a7e4b9d"
},
"status": {
"type": "string",
"enum": [
"processing"
],
"description": "Always `processing` on creation."
}
}
}
Errors
On failure, dci prints a single error message — with a hint when one is available — and exits with a typed code your scripts can branch on. See Errors and exit codes for the full contract.
HTTP status to exit code mapping
| HTTP status | Exit code | Error code | Meaning |
|---|---|---|---|
| 400 | 30 | VALIDATION_ERROR | The arguments or request body were rejected. Review the command's flags and payload. |
| 401 | 10 | AUTHENTICATION_FAILED | Not signed in, or the API token is invalid. Run dci login or check DCI_API_KEY. |
| 403 | 11 | PERMISSION_DENIED | The DoiT user or the active customer context does not have access. |
| 409 | 21 | RESOURCE_CONFLICT | The operation conflicts with the resource's current state. |
| 415 | 1 | API_ERROR | The request failed; the printed error message has details. |
| 429 | 50 | RATE_LIMITED | Too many requests. Retryable — the CLI reports the server-provided delay. |
| 500 | 40 | API_SERVER_ERROR | The API failed to process the request. Retryable; contact DoiT support if it persists. |
Related
- create-datahub-dataset — Create dataset
- delete-datahub-dataset — Delete a dataset
- delete-datahub-datasets — Delete datasets
- delete-datahub-events-by-filter — Delete specific events
- export-datahub-dataset-records — Export dataset records
- get-datahub-dataset — Retrieve a dataset
- get-datahub-invoice-import — Retrieve an invoice import
- import-datahub-provider-records — Import provider-native records
- ingest-datahub-events — Ingest JSON
- ingest-datahub-events-csv — Ingest CSV file
- list-datahub-datasets — List datasets
- list-datahub-invoice-imports — List invoice imports
- update-datahub-dataset — Update dataset
- API reference: POST /datahub/v1/invoice-imports
Aliases: createdatahubinvoiceimport