Resources

Invoices

Find, create, and edit invoices, including their sections and lines. Find the project first with GET /v1/opportunities, then work with the invoices on it.

What the API can do

You can search invoices, read one, create one (blank or copied from an estimate), and add, edit, and delete the sections and lines of a draft. A key acts as the workspace member who generated it, so that member needs invoices.view to read, invoices.create to create, and invoices.editfor every other write. Every write is recorded in the workspace's audit log against that member.

What the API cannot do

It never sends, voids, pays, archives, or deletes an invoice. Do those in Coastline.

It cannot change an invoice that has been sent. Every write to an invoice that is not a draft answers 409 conflict.

New sections and lines always go on the end. There is no way to reorder them through the API.

Drafts only

An invoice can be edited through the API while it is a draft with no payment applied. Anything else answers 409 conflict with one of three messages:

SituationTypeDescription
sent, partial, paid, refunded or void409Only draft invoices can be edited through the API. This invoice is sent.
a payment is applied409This invoice has a payment applied and can no longer be edited.
archived409This invoice is archived and cannot be edited.

Reads work in every status. The note about a payment applied is not the same as the status: a draft can carry a deposit, and that invoice has been live on the customer's pay page even though its status still reads draft.

Money and quantities

Amounts are in dollars. total is the stored grand total, subtotal and tax are computed from the lines, and balance_due is total - amount_paid. Invoice list rows carry total and balance_due too, because the total is stored rather than summed per request.

Copying an estimate? Read this

On an estimate a line's unit_cost is your cost, and its price is what the customer sees. On an invoice unit_costis the billed price itself. An invoice has no markup. If you carry lines across by hand, send the estimate's price as the invoice's unit_cost. Sending the estimate's unit_cost bills your cost to the customer.

Easier: pass estimate_id when you create the invoice and Coastline copies the sections and lines for you, flattening the markup correctly.

quantity is the final quantity. Invoice sections carry no margin, so margin is refused with its own message rather than ignored. The API does not accept or return waste_pct; apply waste before you send the quantity.

Dates

issue_date and due_dateare calendar dates in the workspace's timezone. Setting payment_terms to a Net term recomputes due_date from issue_date; setting due_date alone implies on_specific_date; moving issue_date under a scheduled term moves due_date with it.

GET/v1/invoices

Find an invoice

All filters are optional and combine. Results are newest first. Archived invoices are hidden unless you ask for them. The response carries has_more rather than a count.

Query parameterTypeDescription
project_iduuidOnly invoices on this project.
statusenumOne of: draft, sent, partial, paid, refunded, void. Overdue is not a status: it is a due date in the past with a balance remaining.
contact_iduuidOnly invoices addressed to this contact.
qstringCase-insensitive match on the invoice name.
updated_sinceISO timestampOnly invoices changed at or after this time.
include_archivedbooleanDefault false. true includes archived invoices.
limitintegerDefault 25, maximum 100.
offsetintegerDefault 0.
GET/v1/invoices/{id}

Read an invoice

Returns the invoice with its sections in order and each section's lines in order, plus subtotal, tax, total, balance_due and a customer-facing reference such as INV-1042-3. tax_rate is a fraction: 0.0825 is 8.25%.

This works in every status, so you can confirm what a sent invoice says without changing it.

POST/v1/invoices

Create an invoice

Creates a draft with one section named Invoice and no lines, or with the sections and lines of an estimate when you pass estimate_id. The tax rate comes from the estimate, then the project's location, then the workspace default; payment terms and the due date come from the workspace default; the contact and bill-to are copied from the project.

FieldTypeDescription
project_iduuidRequired. The project the invoice belongs to.
namestringRequired, up to 200 characters.
estimate_iduuidOptional. Copies that estimate's sections and lines in, flattening its margin into the billed price.
iduuidOptional. Your own id for the invoice, so a retry is safe. See Safe retries.
PATCH/v1/invoices/{id}

Edit a draft's header

Send only the fields you want to change. Every field is optional, and at least one is required.

FieldTypeDescription
namestringUp to 200 characters.
notesstringUp to 10,000 characters. Null clears it.
tax_ratenumberA fraction from 0 to 1. Changing it moves the stored total.
issue_datedateYYYY-MM-DD.
due_datedateYYYY-MM-DD. Sending this alone sets payment_terms to on_specific_date.
payment_termsenumdue_on_receipt, net_7, net_15, net_30, net_45, net_60, or on_specific_date.
contact_iduuidA contact in your workspace. Null clears it.
project_manager_iduuidA member of your workspace. Null clears it.
allow_cardbooleanWhether the pay page offers card. Takes effect when the invoice is sent.
allow_bankbooleanWhether the pay page offers bank transfer. Takes effect when the invoice is sent.

status is refused with a message saying those changes stay in Coastline. amount_paid, amount_total, invoice_number, account_id and every payment-processor field are unknown fields. The bill-to is copied from the project when the invoice is created and does not change afterwards.

POST/v1/invoices/{id}/sections

Add a section

Appends a section after the last one. A new section has no lines: unlike the builder, the API does not seed a blank one, so a section you add is empty until you add lines to it.

FieldTypeDescription
namestringUp to 200 characters. Defaults to Invoice.
taxablebooleanDefaults to true.
iduuidOptional. Your own id, so a retry is safe.
PATCH/v1/invoices/{id}/sections/{sectionId}

Rename a section

name and taxable only. marginis refused: invoice sections do not carry a margin, so send the price you want as each line's unit_cost.

DELETE/v1/invoices/{id}/sections/{sectionId}

Delete a section

Deletes the section and every line in it. There is no way to delete the lines and keep the section. Coastline reads the section as it stands at that moment and deletes exactly what it found, so a line added while your request was in flight makes the delete answer 409 conflict instead of silently removing something you never saw.

POST/v1/invoices/{id}/items

Add lines

Add one line, or up to 200 in a single request. A batch is one write: it lands whole or not at all, so you never end up with half a section. Lines append after the section's last line.

FieldTypeDescription
section_iduuidRequired. The section to add to.
itemsarrayOptional. 1 to 200 lines. Send either items or a single line, never both.
namestringRequired on each line, up to 500 characters.
descriptionstringUp to 5,000 characters. Null clears it.
quantitynumberThe final quantity. Defaults to 1.
unitstringUp to 20 characters, for example ea, hr, sf. Defaults to ea.
unit_costnumberThe billed price per unit. Defaults to 0. There is no markup on an invoice.
catalog_item_iduuidOptional link to an item in your catalog. The price still comes from unit_cost.
iduuidOptional on each line, so a retry is safe. Send an id on every line or on none.
PATCH/v1/invoices/{id}/items/{itemId}

Edit a line

Any of name, description, quantity, unit, unit_cost and catalog_item_id. Once you change a quantity, the line's calc is cleared, because the stored formula no longer explains the number.

You cannot move a line to another section or change its position. Delete it and add it where you want it.

DELETE/v1/invoices/{id}/items/{itemId}

Delete a line

Removes one line. The rest of the section is untouched.

Safe retries

When a request times out you cannot tell whether it landed, and sending it again could create a second invoice. So every create takes an id you choose. Send the same id again and you get the first result back with 200 and nothing new is written. An id already used by something else answers 409 and does not say whose it is.

A retry that arrives while the first attempt is still finishing answers 409 with a message saying the invoice is still being created. Wait a moment and send it again.

Errors

StatusTypeDescription
400validation_errorA malformed field, an unknown field, a status field, calc, waste_pct or a section margin, a batch of items mixed with single-line fields, an id on some lines but not others, or a date that is not YYYY-MM-DD.
401unauthorizedThe API key is missing or invalid.
403forbiddenThe key owner is missing the invoices.view, invoices.create or invoices.edit permission named in the message.
404not_foundThe invoice, section, line, project, estimate, contact, member or catalog item does not exist in your workspace. One in another workspace answers 404, never 403.
409conflictNot a draft, a payment applied, archived, an id already in use, a section that changed under a delete, or a total that would drop below the amount paid.
500internal_errorSomething went wrong on our end. Retry safe.