Skip to content

Set the invoice that sold an order

POST
/orders/{id}/source-invoice
Code sample: Shell / cURL
curl --request POST \
--url https://example.com/api/v1/orders/example/source-invoice \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{ "invoiceId": "example" }'

Makes an uncancelled invoice of the order’s company the order’s source invoice and gives back the hours or tokens the order lost when its previous source was cancelled or deleted. Only an order with no source invoice takes one, and the invoice must sell no other order. Requires the orders.edit and invoices.manage permissions, an order the caller reaches and an invoice within their invoice scope. A refusal carries a reason: ORDER_NOT_FOUND and INVOICE_NOT_FOUND (404); ORDER_HAS_SOURCE_INVOICE and INVOICE_SELLS_ANOTHER_ORDER (409); ORDER_CLIENT_MISMATCH and INVOICE_NOT_LINKABLE (422).

id
required

Resource identifier (CUID2).

string
>= 1 characters

Resource identifier (CUID2).

Media typeapplication/json
object
invoiceId
required

An uncancelled invoice of the order’s company that sells no other order and, for an order counted in hours, sells hours (a line of a service or package that defines hours, or a line without a service). It becomes the order’s source invoice and gives back the hours or tokens the order lost when its previous source was cancelled or deleted.

string
>= 1 characters

Example generated

{
"invoiceId": "example"
}

The invoice that now sources the order and what the order got back.

Media typeapplication/json
object
data
required

The invoice that now sources the order and what the order got back.

object
invoiceId
required
string
invoiceNumber
required
string
orderId
required
string
restoredHours
required

Hours the order got back; 0 when it had lost none.

number
restoredTokens
required

Tokens the order got back; 0 when it had lost none.

integer
>= -9007199254740991 <= 9007199254740991

Example generated

{
"data": {
"invoiceId": "example",
"invoiceNumber": "example",
"orderId": "example",
"restoredHours": 1,
"restoredTokens": 1
}
}

Validation error. Parse failures include field paths and expectations.

Media typeapplication/json

Validation error with safe field paths and expected values; submitted values are never returned.

object
error
required
object
code
required

Stable machine-readable error code.

string
issues
Array<object>
object
expected
required
string
message
required
string
path
required
Array<string | number>
message
required

Human-readable error message.

string
status
required

HTTP status code, mirrored in the body.

integer
>= -9007199254740991 <= 9007199254740991

Example

{
"error": {
"code": "UNAUTHORIZED"
}
}

Unauthorized.

Media typeapplication/json

Standard error envelope.

object
error
required
object
code
required

Stable machine-readable error code.

string
message
required

Human-readable error message.

string
status
required

HTTP status code, mirrored in the body.

integer
>= -9007199254740991 <= 9007199254740991

Example

{
"error": {
"code": "UNAUTHORIZED"
}
}

Forbidden.

Media typeapplication/json

Standard error envelope.

object
error
required
object
code
required

Stable machine-readable error code.

string
message
required

Human-readable error message.

string
status
required

HTTP status code, mirrored in the body.

integer
>= -9007199254740991 <= 9007199254740991

Example

{
"error": {
"code": "UNAUTHORIZED"
}
}

The order or the invoice does not exist or is out of reach.

Media typeapplication/json

Standard error envelope.

object
error
required
object
code
required

Stable machine-readable error code.

string
message
required

Human-readable error message.

string
status
required

HTTP status code, mirrored in the body.

integer
>= -9007199254740991 <= 9007199254740991

Example

{
"error": {
"code": "UNAUTHORIZED"
}
}

The order already has a source invoice (ORDER_HAS_SOURCE_INVOICE) or the invoice sells another order (INVOICE_SELLS_ANOTHER_ORDER).

Media typeapplication/json

Standard error envelope.

object
error
required
object
code
required

Stable machine-readable error code.

string
message
required

Human-readable error message.

string
status
required

HTTP status code, mirrored in the body.

integer
>= -9007199254740991 <= 9007199254740991

Example

{
"error": {
"code": "UNAUTHORIZED"
}
}

The invoice is of another company (ORDER_CLIENT_MISMATCH) or cannot be linked (INVOICE_NOT_LINKABLE).

Media typeapplication/json

Standard error envelope.

object
error
required
object
code
required

Stable machine-readable error code.

string
message
required

Human-readable error message.

string
status
required

HTTP status code, mirrored in the body.

integer
>= -9007199254740991 <= 9007199254740991

Example

{
"error": {
"code": "UNAUTHORIZED"
}
}

Rate limit exceeded. Wait for Retry-After before retrying.

Media typeapplication/json

Standard error envelope.

object
error
required
object
code
required

Stable machine-readable error code.

string
message
required

Human-readable error message.

string
status
required

HTTP status code, mirrored in the body.

integer
>= -9007199254740991 <= 9007199254740991

Example

{
"error": {
"code": "UNAUTHORIZED"
}
}
RateLimit-Limit
string
/^\d+$/

Maximum requests in the current quota window.

RateLimit-Policy
string

Quota policy in requests and window seconds, for example 60;w=60.

RateLimit-Remaining
string
/^\d+$/

Requests left in this quota window (zero when blocked).

RateLimit-Reset
string
/^\d+$/

Seconds until the current quota window resets, when available from the rate-limit store.

Retry-After
string
/^\d+$/

Seconds until another request may be attempted.