Skip to main content
Glama

Create invoice from data

well_create_invoice_from_data

Create an invoice in Well from data you extracted by reading an invoice (your own OCR) — you send the structured fields, not the file.

Well persists the invoice + its line items + payment means using the same pipeline as uploaded documents. Fill every field you can read from the document:

  • issuer / receiver: { name (required), company_id?, domain?, tax_id? }

  • A draft may be saved before it is complete: with status "draft", leave out the issuer, the receiver, issue_date, currency or line_items you do not know yet, and never invent one. On such a draft a party you do send carries its company_id, currency is required as soon as there is a line, and payment_means is left out. The answer's missing_fields names what the draft still lacks. Any other status needs every part

  • invoice_number (the invoice's own number, read from the document; leave it out for a draft, Well numbers drafts itself), reference_number? (a reference printed apart from the invoice number; never the invoice number itself; ignored on a draft), issue_date (YYYY-MM-DD), due_date? (YYYY-MM-DD; leave it out on a draft the person gave no due date: Well sets the customer's usual terms, else 30 days after the issue date), currency (ISO 4217)

  • line_items[]: { name, quantity?, unit_price, currency?, tax_rate? } — never send totals: Well computes them from the lines, each line held to the currency's minor units

  • printed_grand_total? — the grand total printed on a document you read. Well still stores the computed total; when the printed one differs by more than rounding, the answer carries printed_total_mismatch { printed_grand_total, computed_grand_total }: tell the user both figures

  • payment_means?[]: { type, iban?, bic?, scheme? }

  • status?: draft | issued | paid | canceled — create an invoice the user is still reviewing as "draft", then issue it with well_issue_invoice once the user confirms; issuing gives it the next invoice number and locks it

  • document_type_code?: "380" invoice | "381" credit note (state it: an invoice with no document type cannot post); corrects_invoice_id? — the issued invoice a credit note corrects, required for a credit note. An issued invoice cannot be edited: correct it with a credit note, then create a new invoice

ONE CALL IS THE WHOLE WRITE. This tool takes the invoice's status and both parties' company ids, so a create never needs a well_update_invoice after it:

  • The user asked to DRAFT an invoice → pass status: "draft" here.

  • You already found the company (well_query_records, well_get_entity) → pass its company_id on that party. Naming the party without its id re-resolves it, which can attach the invoice to the wrong company or create a duplicate one.

Creating and then patching the same invoice writes twice and shows the user two confirmations for one action. Put the intent in this call.

The answer carries the saved invoice's status, customer_name, currency, grand_total, issue_date, design_layout (null until a design is chosen) and lines. The card shows them, so the reply does not list them again.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
issuerNoThe company that issues the invoice. Leave it out only on a draft whose issuer is not known yet.
statusNoThe invoice's lifecycle status. Set it here when the user asked for one ("draft an invoice") — do NOT create and then call well_update_invoice to change it. Omitted, Well derives one only where the document type decides it; otherwise the invoice has no status.
currencyNoISO 4217 (3 letters). Required as soon as the invoice has a line; never guessed by Well.
due_dateNoISO 8601 YYYY-MM-DD.
receiverNoThe customer. Leave it out only on a draft whose customer is not known yet.
issue_dateNoISO 8601 YYYY-MM-DD. Leave it out only on a draft whose date is not set yet.
line_itemsNoThe lines. Leave them out only on a draft whose lines are not known yet.
workspace_idNoTarget workspace. Omit when the token authorizes one workspace. Required when it authorizes several — a write lands in exactly one workspace and this call would not say which.
payment_meansNo
invoice_numberNoThe invoice's own number, read from the document. Required unless the invoice is a draft or created to be issued: Well numbers those when they are issued. Never make one up.
conversation_idNoThe conversation id returned by the previous Well result, in its meta under well/conversation_id, in its structuredContent, or in its JSON text block. Pass it back on every call in the same conversation, including a call a card makes, so the chosen workspace and the earlier answers still apply. It decides the conversation on its own: nothing the host states about the session replaces it. Omit it only on the first call of a conversation.
idempotency_keyNoOptional client-supplied key. A retried write with the same key returns the original result instead of re-applying the operation.
workspace_scopeNoRestrict this call to the family: the token's primary workspace plus the company workspaces under it that you are a member of. Unrelated authorized workspaces drop out of the read; row reads merge across the family, while a per-workspace figure still reports exactly one workspace.
reference_numberNoA reference printed apart from the invoice's own number. Never the invoice number itself. Leave it out for a draft: Well names a draft by the number it will take when issued (DRAFT-061 while the next invoice number is INV-061) and ignores any value sent.
document_type_codeNo"380" is an invoice; "381" is a credit note that corrects an invoice already issued. Omitted, the invoice has no document type and cannot post. An issued invoice cannot be edited, so a correction is a credit note with its own number, then a new invoice.
corrects_invoice_idNoThe UUID of the issued invoice a credit note corrects. Required for a credit note (381); refused otherwise.
printed_grand_totalNoThe grand total printed on a document you read, as printed. Leave it out for an invoice Well drafts. Well still stores the total it computes from the lines; when the two differ by more than rounding, the answer carries printed_total_mismatch.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeNo
errorNo
linesNo
statusNo
sourcesNoThe tools that hold a copy of the invoice, highest source precedence first. Empty when no tool holds it.
successYes
currencyNo
invoice_idNo
issue_dateNo
grand_totalNo
source_countNoHow many tools hold the invoice; sources may list fewer.
customer_nameNo
design_layoutNo
payment_meansNo
missing_fieldsNo
conversation_idNoThe conversation this result belongs to. Pass it back as the conversation_id argument on every later Well call in the same conversation.
newly_connectedNoTools that connected to this workspace since the last result and that no session was told about yet, oldest first. Present only when at least one tool is new. The connected-line rule says when to tell an entry; when it does, one line per entry, in the person's language: "<name> is connected.". Never fold several entries into one sentence. Each entry comes back once, on one result only: never repeat its line later.
reference_numberNo
invoice_item_countNo
conversation_id_noteNoPresent only when the server opened a fresh lane, stating that no choice recorded earlier was read.
conversation_id_sourceNoWhere the conversation id came from: the host's own request meta, the caller's argument, or a fresh lane the server opened.
printed_total_mismatchNoThe document's printed grand total differs from the total Well computed from the lines and stored. Tell the user both figures; a document-level discount or charge belongs on its own line.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed2 schema fields changed
    • addedOutput schema / properties / source_count
      Added value: +{
      +  "description": "How many tools hold the invoice; sources may list fewer.",
      +  "maximum": 9007199254740991,
      +  "minimum": -9007199254740991,
      +  "type": "integer"
      +}
    • addedOutput schema / properties / sources
      Added value: +{
      +  "description": "The tools that hold a copy of the invoice, highest source precedence first. Empty when no tool holds it.",
      +  "items": {
      +    "additionalProperties": false,
      +    "properties": {
      +      "domain": {
      +        "anyOf": [
      +          {
      +            "type": "string"
      +          },
      +          {
      +            "type": "null"
      +          }
      +        ]
      +      },
      +      "kind": {
      +        "enum": [
      +          "accounting_tool",
      +          "connector",
      +          "mail_extraction"
      +        ],
      +        "type": "string"
      +      },
      +      "name": {
      +        "type": "string"
      +      },
      +      "service_id": {
      +        "type": "string"
      +      }
      +    },
      +    "required": [
      +      "kind",
      +      "service_id",
      +      "name"
      +    ],
      +    "type": "object"
      +  },
      +  "type": "array"
      +}
  2. Changed9 schema fields changed
    • changedInput schema / properties / currency / description
      Previous value: -"ISO 4217 (3 letters)."New value: +"ISO 4217 (3 letters). Required as soon as the invoice has a line; never guessed by Well."
    • changedInput schema / properties / issue_date / description
      Previous value: -"ISO 8601 YYYY-MM-DD."New value: +"ISO 8601 YYYY-MM-DD. Leave it out only on a draft whose date is not set yet."
    • addedInput schema / properties / issuer / description
      Added value: +"The company that issues the invoice. Leave it out only on a draft whose issuer is not known yet."
    • addedInput schema / properties / line_items / default
      Added value: +[]
    • addedInput schema / properties / line_items / description
      Added value: +"The lines. Leave them out only on a draft whose lines are not known yet."
    • removedInput schema / properties / line_items / minItems
      Removed value: -1
    • addedInput schema / properties / receiver / description
      Added value: +"The customer. Leave it out only on a draft whose customer is not known yet."
    • removedInput schema / required
      Removed value: -[
      -  "issuer",
      -  "receiver",
      -  "issue_date",
      -  "currency",
      -  "line_items"
      -]
    • addedOutput schema / properties / missing_fields
      Added value: +{
      +  "items": {
      +    "enum": [
      +      "customer_address",
      +      "due_date",
      +      "line_price",
      +      "issuer",
      +      "receiver",
      +      "line_items",
      +      "currency",
      +      "issue_date"
      +    ],
      +    "type": "string"
      +  },
      +  "type": "array"
      +}
  3. Changed1 schema field changed
    • changedOutput schema / properties / newly_connected / description
      Previous value: -"Tools that connected to this workspace since the last result and that no session was told about yet, oldest first. Present only when at least one tool is new. Start the reply with one line per entry, in the person's language: \"<name> is connected.\". Never fold several entries into one sentence. Each entry comes back once, on one result only: never repeat its line later."New value: +"Tools that connected to this workspace since the last result and that no session was told about yet, oldest first. Present only when at least one tool is new. The connected-line rule says when to tell an entry; when it does, one line per entry, in the person's language: \"<name> is connected.\". Never fold several entries into one sentence. Each entry comes back once, on one result only: never repeat its line later."
  4. Changed1 schema field changed
    • addedOutput schema / properties / code
      Added value: +{
      +  "type": "string"
      +}
  5. Changed3 schema fields changed
    • addedInput schema / properties / line_items / items / properties / unit_price / anyOf
      Added value: +[
      +  {
      +    "type": "number"
      +  },
      +  {
      +    "type": "null"
      +  }
      +]
    • changedInput schema / properties / line_items / items / properties / unit_price / description
      Previous value: -"Unit price (number, not string)."New value: +"Unit price (number, not string). null for a line with no price of its own, included in another line's price; never 0 for that, which bills the line at nothing."
    • removedInput schema / properties / line_items / items / properties / unit_price / type
      Removed value: -"number"
  6. Changed5 schema fields changed
    • addedInput schema / properties / printed_grand_total
      Added value: +{
      +  "description": "The grand total printed on a document you read, as printed. Leave it out for an invoice Well drafts. Well still stores the total it computes from the lines; when the two differ by more than rounding, the answer carries printed_total_mismatch.",
      +  "type": "number"
      +}
    • removedInput schema / properties / totals
      Removed value: -{
      -  "description": "The invoice's totals. grand_total is required; Well never computes it for you.",
      -  "properties": {
      -    "grand_total": {
      -      "description": "The invoice's total including tax, as printed.",
      -      "type": "number"
      -    },
      -    "items_total": {
      -      "type": "number"
      -    },
      -    "tax_total": {
      -      "type": "number"
      -    }
      -  },
      -  "required": [
      -    "grand_total"
      -  ],
      -  "type": "object"
      -}
    • addedInput schema / properties / workspace_scope
      Added value: +{
      +  "description": "Restrict this call to the family: the token's primary workspace plus the company workspaces under it that you are a member of. Unrelated authorized workspaces drop out of the read; row reads merge across the family, while a per-workspace figure still reports exactly one workspace.",
      +  "enum": [
      +    "family"
      +  ],
      +  "type": "string"
      +}
    • changedInput schema / required
      Previous value: -[
      -  "issuer",
      -  "receiver",
      -  "issue_date",
      -  "currency",
      -  "totals",
      -  "line_items"
      -]New value: +[
      +  "issuer",
      +  "receiver",
      +  "issue_date",
      +  "currency",
      +  "line_items"
      +]
    • addedOutput schema / properties / printed_total_mismatch
      Added value: +{
      +  "additionalProperties": false,
      +  "description": "The document's printed grand total differs from the total Well computed from the lines and stored. Tell the user both figures; a document-level discount or charge belongs on its own line.",
      +  "properties": {
      +    "computed_grand_total": {
      +      "type": "number"
      +    },
      +    "printed_grand_total": {
      +      "type": "number"
      +    }
      +  },
      +  "required": [
      +    "printed_grand_total",
      +    "computed_grand_total"
      +  ],
      +  "type": "object"
      +}
  7. Changed5 schema fields changed
    • changedInput schema / properties / document_type_code / description
      Previous value: -"\"380\" (the default) is an invoice; \"381\" is a credit note that corrects an invoice already issued. An issued invoice cannot be edited, so a correction is a credit note with its own number, then a new invoice."New value: +"\"380\" is an invoice; \"381\" is a credit note that corrects an invoice already issued. Omitted, the invoice has no document type and cannot post. An issued invoice cannot be edited, so a correction is a credit note with its own number, then a new invoice."
    • addedInput schema / properties / invoice_number
      Added value: +{
      +  "description": "The invoice's own number, read from the document. Required unless the invoice is a draft or created to be issued: Well numbers those when they are issued. Never make one up.",
      +  "maxLength": 255,
      +  "minLength": 1,
      +  "type": "string"
      +}
    • changedInput schema / properties / reference_number / description
      Previous value: -"The invoice's own number, read from the document. Leave it out for a draft: Well names a draft by the number it will take when issued (DRAFT-061 while the next invoice number is INV-061) and ignores any value sent. Never make one up."New value: +"A reference printed apart from the invoice's own number. Never the invoice number itself. Leave it out for a draft: Well names a draft by the number it will take when issued (DRAFT-061 while the next invoice number is INV-061) and ignores any value sent."
    • changedInput schema / properties / status / description
      Previous value: -"The invoice's lifecycle status. Set it here when the user asked for one (\"draft an invoice\") — do NOT create and then call well_update_invoice to change it. Omitted, the status is derived from the document type."New value: +"The invoice's lifecycle status. Set it here when the user asked for one (\"draft an invoice\") — do NOT create and then call well_update_invoice to change it. Omitted, Well derives one only where the document type decides it; otherwise the invoice has no status."
    • addedOutput schema / properties / newly_connected
      Added value: +{
      +  "description": "Tools that connected to this workspace since the last result and that no session was told about yet, oldest first. Present only when at least one tool is new. Start the reply with one line per entry, in the person's language: \"<name> is connected.\". Never fold several entries into one sentence. Each entry comes back once, on one result only: never repeat its line later.",
      +  "items": {
      +    "additionalProperties": false,
      +    "properties": {
      +      "name": {
      +        "type": "string"
      +      },
      +      "service_id": {
      +        "type": "string"
      +      }
      +    },
      +    "required": [
      +      "name",
      +      "service_id"
      +    ],
      +    "type": "object"
      +  },
      +  "type": "array"
      +}
  8. Changed1 schema field changed
    • addedOutput schema / properties / lines / items / properties / line_kind
      Added value: +{
      +  "description": "Whether the line is charged. Only a billed line counts toward grand_total; an optional or alternative line is printed with its price but not charged. Its line_id still names it in an edit.",
      +  "enum": [
      +    "billed",
      +    "optional",
      +    "alternative"
      +  ],
      +  "type": "string"
      +}
  9. Changed14 schema fields changed
    • addedInput schema / properties / corrects_invoice_id
      Added value: +{
      +  "description": "The UUID of the issued invoice a credit note corrects. Required for a credit note (381); refused otherwise.",
      +  "format": "uuid",
      +  "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$",
      +  "type": "string"
      +}
    • addedInput schema / properties / document_type_code
      Added value: +{
      +  "description": "\"380\" (the default) is an invoice; \"381\" is a credit note that corrects an invoice already issued. An issued invoice cannot be edited, so a correction is a credit note with its own number, then a new invoice.",
      +  "enum": [
      +    "380",
      +    "381"
      +  ],
      +  "type": "string"
      +}
    • addedInput schema / properties / reference_number / description
      Added value: +"The invoice's own number, read from the document. Leave it out for a draft: Well names a draft by the number it will take when issued (DRAFT-061 while the next invoice number is INV-061) and ignores any value sent. Never make one up."
    • addedInput schema / properties / totals / description
      Added value: +"The invoice's totals. grand_total is required; Well never computes it for you."
    • addedInput schema / properties / totals / properties / grand_total / description
      Added value: +"The invoice's total including tax, as printed."
    • changedInput schema / required
      Previous value: -[
      -  "issuer",
      -  "receiver",
      -  "reference_number",
      -  "issue_date",
      -  "currency",
      -  "line_items"
      -]New value: +[
      +  "issuer",
      +  "receiver",
      +  "issue_date",
      +  "currency",
      +  "totals",
      +  "line_items"
      +]
    • addedOutput schema / properties / currency
      Added value: +{
      +  "anyOf": [
      +    {
      +      "type": "string"
      +    },
      +    {
      +      "type": "null"
      +    }
      +  ]
      +}
    • addedOutput schema / properties / customer_name
      Added value: +{
      +  "type": "string"
      +}
    • addedOutput schema / properties / design_layout
      Added value: +{
      +  "anyOf": [
      +    {
      +      "type": "string"
      +    },
      +    {
      +      "type": "null"
      +    }
      +  ]
      +}
    • removedOutput schema / properties / document_id
      Removed value: -{
      -  "type": "string"
      -}
    • addedOutput schema / properties / grand_total
      Added value: +{
      +  "anyOf": [
      +    {
      +      "type": "number"
      +    },
      +    {
      +      "type": "null"
      +    }
      +  ]
      +}
    • addedOutput schema / properties / issue_date
      Added value: +{
      +  "anyOf": [
      +    {
      +      "type": "string"
      +    },
      +    {
      +      "type": "null"
      +    }
      +  ]
      +}
    • addedOutput schema / properties / lines
      Added value: +{
      +  "items": {
      +    "additionalProperties": false,
      +    "properties": {
      +      "line_id": {
      +        "type": "string"
      +      },
      +      "name": {
      +        "type": "string"
      +      },
      +      "quantity": {
      +        "anyOf": [
      +          {
      +            "type": "number"
      +          },
      +          {
      +            "type": "null"
      +          }
      +        ]
      +      },
      +      "tax_rate": {
      +        "anyOf": [
      +          {
      +            "type": "number"
      +          },
      +          {
      +            "type": "null"
      +          }
      +        ]
      +      },
      +      "unit_price": {
      +        "anyOf": [
      +          {
      +            "type": "number"
      +          },
      +          {
      +            "type": "null"
      +          }
      +        ]
      +      }
      +    },
      +    "required": [
      +      "name",
      +      "quantity",
      +      "unit_price",
      +      "tax_rate"
      +    ],
      +    "type": "object"
      +  },
      +  "type": "array"
      +}
    • addedOutput schema / properties / status
      Added value: +{
      +  "anyOf": [
      +    {
      +      "type": "string"
      +    },
      +    {
      +      "type": "null"
      +    }
      +  ]
      +}
  10. Changed4 schema fields changed
    • addedInput schema / properties / conversation_id
      Added value: +{
      +  "description": "The conversation id returned by the previous Well result, in its meta under well/conversation_id, in its structuredContent, or in its JSON text block. Pass it back on every call in the same conversation, including a call a card makes, so the chosen workspace and the earlier answers still apply. It decides the conversation on its own: nothing the host states about the session replaces it. Omit it only on the first call of a conversation.",
      +  "type": "string"
      +}
    • addedOutput schema / properties / conversation_id
      Added value: +{
      +  "description": "The conversation this result belongs to. Pass it back as the conversation_id argument on every later Well call in the same conversation.",
      +  "type": "string"
      +}
    • addedOutput schema / properties / conversation_id_note
      Added value: +{
      +  "description": "Present only when the server opened a fresh lane, stating that no choice recorded earlier was read.",
      +  "type": "string"
      +}
    • addedOutput schema / properties / conversation_id_source
      Added value: +{
      +  "description": "Where the conversation id came from: the host's own request meta, the caller's argument, or a fresh lane the server opened.",
      +  "enum": [
      +    "host_meta",
      +    "argument",
      +    "minted"
      +  ],
      +  "type": "string"
      +}
  11. Changed4 schema fields changed
    • addedInput schema / properties / issuer / properties / name / maxLength
      Added value: +255
    • addedInput schema / properties / line_items / items / properties / name / maxLength
      Added value: +255
    • addedInput schema / properties / receiver / properties / name / maxLength
      Added value: +255
    • addedInput schema / properties / reference_number / maxLength
      Added value: +100
  12. Changed1 schema field changed
    • changedInput schema / properties / workspace_id / description
      Previous value: -"Target workspace. Omit to use the only authorized workspace, or (for read tools) to query all authorized workspaces grouped by workspace. Required for write tools when the token authorizes more than one workspace."New value: +"Target workspace. Omit when the token authorizes one workspace. Required when it authorizes several — a write lands in exactly one workspace and this call would not say which."
  13. Changed3 schema fields changed
    • addedInput schema / properties / issuer / properties / company_id
      Added value: +{
      +  "description": "An existing company in the workspace, bound directly — ALWAYS send this when you already know the company (e.g. you found it with well_query_records). Without it the party is re-resolved from name/domain/tax_id, which can attach the invoice to a different company or mint a duplicate.",
      +  "format": "uuid",
      +  "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$",
      +  "type": "string"
      +}
    • addedInput schema / properties / receiver / properties / company_id
      Added value: +{
      +  "description": "An existing company in the workspace, bound directly — ALWAYS send this when you already know the company (e.g. you found it with well_query_records). Without it the party is re-resolved from name/domain/tax_id, which can attach the invoice to a different company or mint a duplicate.",
      +  "format": "uuid",
      +  "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$",
      +  "type": "string"
      +}
    • addedInput schema / properties / status
      Added value: +{
      +  "description": "The invoice's lifecycle status. Set it here when the user asked for one (\"draft an invoice\") — do NOT create and then call well_update_invoice to change it. Omitted, the status is derived from the document type.",
      +  "enum": [
      +    "draft",
      +    "issued",
      +    "paid",
      +    "canceled"
      +  ],
      +  "type": "string"
      +}
  14. First observed

TDQS

Score is being calculated.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.

Resources