auto_write
finance

Create, save or discard a sales invoice draft, or start a credit note

Changed on

action: save without invoice_id creates a draft (fin_sales_invoice_save) and answers its id; with invoice_id it replaces that draft's lines and fields with the ones sent — send them all, as the Books screen does (a field left out is saved empty). With credits_invoice_id and no invoice_id the new draft is a credit note for that issued invoice. action: credit_note starts a credit note draft for the issued invoice invoice_id with its lines copied, to trim before a person issues it. action: discard discards the draft invoice_id. A draft has no number and books nothing; numbering and booking happen when a person issues it. A create has no natural key: a retry with the same Idempotency-Key answers the first draft's id. A write: needs finance:write and an app Magistry has reviewed for finance, the book capability on the entity (Postgres asks the granting person's role and the app's grant), and the platform switch api_sales_book; until it is on this answers 403 finance_feature_off and writes nothing. A write the books refuse in their current state — a closed or filed period (fin.period_closed), an invoice no longer a draft — answers 409 sales_conflict with the SQL's reason. Issuing an invoice and sending anything stay a person's, in Books → Sales. Costs 3 rate credits. Requires an Idempotency-Key header (or idempotency_key, 8 to 255 characters, the same one if both are sent): without one this answers 400 idempotency_required and writes nothing. A retry with the same key and the same arguments answers the first result without writing again; the same key with other arguments is 409 idempotency_conflict, while the first request is still running 409 idempotency_in_flight, and once a first request that never finished is past its window 409 idempotency_outcome_unknown (read the books, then a new key).

post/api/v1/finance/sales-invoices/draft

Request

  • Base URL
    https://app.magistry.io
  • Auth
    • HTTP bearer
    • or OAuth 2
      Authorization codehttps://app.magistry.io/api/oauth/authorize
      Token URLhttps://app.magistry.io/api/oauth/token
      Scopesfinance:write

Headers

Idempotency-Key, string

Required, here or as idempotency_key in the body. A unique string you choose for this request; send the SAME key when retrying and the first answer is returned instead of writing twice (idempotent-replayed: true). The same key with other arguments is 409 idempotency_conflict. If the header and idempotency_key are both sent they must be equal.

Request body

object required
entity_id, string uuid required

The entity, one of those this app was granted (GET /api/v1/finance/entities lists them).

action, 'save' | 'discard' | 'credit_note' required

What to do.

invoice_id, string uuid

The draft to save or discard, or the issued invoice to credit.

credits_invoice_id, string uuid

Save only, on a create: the issued invoice this new draft credits.

contact_id, string uuid

The customer.

series_id, string uuid

The number series the invoice will be numbered in when issued.

issue_date, string date

Planned issue date.

supply_date, string date

Date of supply.

due_date, string date

Due date.

buyer_reference, string

The buyer's reference.

order_reference, string

The order reference.

note, string

A note printed on the invoice.

lines, object[]

Save only: the invoice lines, 0 to 500.

idempotency_key, string required

Same as the Idempotency-Key header; give one of the two.

Response

Result

object required
ok, boolean required
result, unknown required

Changes

    • warning

      added the new method_not_allowed enum value to the error response property for the response status

    • warning

      added the new method_not_allowed enum value to the error response property for the response status

    • warning

      added the new method_not_allowed enum value to the error response property for the response status

    11 more changes in this revision