> For the complete documentation index, see [llms.txt](https://developer.younium.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.younium.com/documentation/invoice-operations.md).

# Invoice operations

## Invoice operations <a href="#dy1q4" id="dy1q4"></a>

Some Invoice endpoints return an operation response that deals with the outcome in a different manner. Where most endpoints return a status code of 400 “Bad Request” if the call was not successful, the operation response returns a successful 2xx with a `message` or `successful` field indicating the result of the operation. Validation errors or similar errors in the request will still return a 400 bad request.

The operation response contains the following fields in its basic form

```
{ 
  id: "3078377a-f369-4176-acf9-08d751485f0b", 
  message: "Invoice was successfully cancelled",  
  successful: true 
}
```

The `id` contains the affected entity eg. a generated invoice. The field may be null and excluded if no id is present to return. The `successful` field whether the operation was successful and the `message` should always be included with further details on the outcome of the operation.

## Generation invoices <a href="#cijes" id="cijes"></a>

Generating invoices provides the possibility to both generate a draft and post the invoice in a single call. This is defined in the request field `invoiceAction` with some different option values:

* `CreateDraft` (default value) will generate a draft invoice.
* `CreateDraftAndPostInvoice` will generate a draft and then try to post the invoice. A draft is created even if the invoice fails to be posted. The response field `successful` is only true if the invoice is posted successfully.
* `CancelDraftIfPostFail` will generate a draft and then try to post the invoice. If the invoice fails to be posted the draft will be cancelled. The response field `successful` is only true if the invoice is posted successfully. The message will indicate that the draft was successfully canceled and why posting the invoice failed.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developer.younium.com/documentation/invoice-operations.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
