メインコンテンツへスキップ

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, dataset and newDatasetName were both sent, costDating is not daily or invoiceDate, force is not a boolean, or the file is missing or empty. Fix the request named in error and 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): newDatasetName is not a valid dataset name. Use letters, digits, underscores, dashes and single spaces, and avoid names reserved for built-in providers, such as google-cloud. A dataset that does not exist is only detected after extraction and ends the import as needsReview; see getDatahubInvoiceImport.
  • unsupported_media_type (415): the Content-Type is not multipart/form-data or application/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; existingImportId names it and error says which. Read it with getDatahubInvoiceImport, or resend with force set to true to 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

FieldTypeRequiredDescription
fileNamestringName of the file, for display in the DoiT console. Defaults to invoice.pdf.
contentBase64string (byte)yesThe PDF bytes in standard base64. The decoded file must be at most 4,718,592 bytes.
datasetstringImport into this existing dataset. Mutually exclusive with newDatasetName; sending both returns 400 invalid_request.
newDatasetNamestringCreate a dataset with this name and import into it. Mutually exclusive with dataset.
costDatingstringdaily 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".
forcebooleanReplace 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.

FieldTypeDescription
idstringThe import id. Pass it to getDatahubInvoiceImport.
statusstringAlways 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 statusExit codeError codeMeaning
40030VALIDATION_ERRORThe arguments or request body were rejected. Review the command's flags and payload.
40110AUTHENTICATION_FAILEDNot signed in, or the API token is invalid. Run dci login or check DCI_API_KEY.
40311PERMISSION_DENIEDThe DoiT user or the active customer context does not have access.
40921RESOURCE_CONFLICTThe operation conflicts with the resource's current state.
4151API_ERRORThe request failed; the printed error message has details.
42950RATE_LIMITEDToo many requests. Retryable — the CLI reports the server-provided delay.
50040API_SERVER_ERRORThe API failed to process the request. Retryable; contact DoiT support if it persists.

Aliases: createdatahubinvoiceimport