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 (as well as through the web interface), you can generate invoices from contracts (either all contracts or a specific one). This is a simple call using PUT or POST:

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

Generates invoices for all contracts

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

Generates invoices for the contract with ID 1

Similarly, it is possible to generate received invoices from supplier contracts:

PUT /c/firma/odberatelska-smlouva/generovani-faktur.xml

Parameters

Requests can be supplemented with an optional query parameter datumGenerovani in ISO 8601 format (YYYY-MM-DD), with the current date as the default value.

For example:

PUT /c/firma/smlouva/generovani-faktur.xml?datumGenerovani=2023-03-01

Result

When calling via the REST API, the response (in XML format) has the following structure:

<?xml version="1.0"?>
<winstrom version="1.0">
<operation>Generov&#xE1;n&#xED; faktur</operation>
<success>ok</success>
<messages>
<message>Počet úspěšně vygenerovaných faktur: 1</message>
</messages>
<errors>
<error>...</error>
</errors>
</winstrom>

The success element can have the values ok, partial, failed and unknown:

ok

Invoice generation completed successfully (though no invoices may have been generated if none were required)

partial

Invoice generation completed successfully for some contracts, but errors occurred for others

failed

No invoices were generated; errors occurred for some contracts

unknown

Should never occur

The result elements contain links to the created documents, message contains success messages (at most one), and error contains error messages (one for each contract where an error occurred).

Response

Generating invoices from contracts returns links to the created invoices in the result. The response may look like this, for example:

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

Contract Journal

After generating invoices from contracts, you can also monitor the generation journal via the API. It is available at the /smlouva-zurnal endpoint — for example, using the URL https://demo.flexibee.eu/c/demo/smlouva-zurnal.xml?detail=full.

The result is an XML file such as the following:

<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>
Did this answer your question?