Skip to main content

Generating Invoices from Contracts via API

How to generate invoices from contracts via REST API?

Written by Lenka Haringerová

Via the REST API — just like via the web interface — you can generate invoices from contracts, either for all of them or for a single specific one. This is done with a simple call using the PUT or POST method.


Building the URL

Address

What it does

/c/{firma}/smlouva/generovani-faktur.xml

Generates issued invoices for all customer contracts.

/c/{firma}/smlouva/1/generovani-faktur.xml

Generates issued invoices for the customer contract with ID 1.

/c/{firma}/dodavatelska-smlouva/generovani-faktur.xml

Similarly generates received invoices from vendor contracts.

PUT https://demo.flexibee.eu/c/demo/smlouva/generovani-faktur.xml
PUT https://demo.flexibee.eu/c/demo/dodavatelska-smlouva/generovani-faktur.xml

🚨 The call does not respect the dry run parameter ?dry-run=true — invoices are created even with it set. Therefore, do not try out generation in "test mode" in a production company.


Parameters

The request can be supplemented with the optional datumGenerovani parameter in ISO 8601 format (YYYY-MM-DD); the default value is the current date.

PUT https://demo.flexibee.eu/c/demo/smlouva/generovani-faktur.xml?datumGenerovani=2023-03-01

⚠️ A date in a format other than the one stated will not result in a 400 error, but in 500 with the message Text 'nesmysl' could not be parsed at index 0. Therefore, verify the format on the integration side.


Result

The XML response has the following form — it contains links to the created documents, a single summary message, and any error messages:

<?xml version="1.0"?>
<winstrom version="1.0">
<operation>Generování faktur</operation>
<success>ok</success>
<results>
<result>
<ref>/c/demo/faktura-vydana/1503</ref>
</result>
</results>
<messages>
<message>Počet úspěšně vygenerovaných faktur: 1</message>
</messages>
<errors></errors>
</winstrom>

The success element can take on the following values:

ok

Invoice generation completed successfully. No invoices needed to be created if none were required — in that case the messages message reads No new invoice was generated.

partial

Generation completed successfully for some contracts, while errors occurred for others.

failed

No invoices were generated, and errors occurred for some contracts.

unknown

Should never occur.

⚠️ The HTTP status is 200 even for partial and failed — so success can only be determined from the success element, not from the status.


Links to created documents and errors

The result elements contain links to the created documents, message is the summary success message (at most one), and error are error messages — one for each contract where an error occurred. Each error carries a messageCode and is prefixed with the contract code:

<errors>
<error messageCode="polDoklNeniDostVyrobnichCisel">211&gt; - Není zadáno odpovídající množství výrobních čísel (0/64).</error>
<error messageCode="validace.neplatnyCiselnik">TEST_01 - Pole 'Kód z ceníku' obsahuje neplatnou položku číselníku.</error>
</errors>

An error on one contract does not stop generation for the others — this is why the overall result can end up as partial.


Contract journal

Every generation — whether manual or automatic — is recorded in a journal, which is available via the API at the smlouva-zurnal endpoint:

GET https://demo.flexibee.eu/c/demo/smlouva-zurnal.xml?detail=full
<winstrom version="1.0">
<smlouva-zurnal>
<id>2</id>
<datCas>2019-11-18T09:20:57.413+01:00</datCas>
<transakceK showAs="Ruční generace">operaceZurnalSmlouvy.manualGenerace</transakceK>
<pocetOk>1</pocetOk>
<pocetErr>0</pocetErr>
<chyby></chyby>
<uzivatel>code:admin</uzivatel>
</smlouva-zurnal>
</winstrom>

The transakceK property distinguishes between operaceZurnalSmlouvy.manualGenerace (Manual generation) and operaceZurnalSmlouvy.autoGenerace (Automatic generation); generation via the REST API is recorded in the journal as manual.


Related

Did this answer your question?