The Documents endpoints
The endpoints to deal with documents have this prefix:
https://api.mindthedoc.com/v0/documents
Creating a document
Now let's generate the invoice, in this case, the template has more and more complex parameters, but imagine what could be done.
from pathlib import Path
import requests
# The API token taken from the website
api_token = "123456"
base_url = "https://api.mindthedoc.com/v0"
template_id = response_data["id"]
documents_url = f"{base_url}/documents"
response = session.post(
documents_url,
json={
"template": template_id,
"data": {
"logo": "imgs/fussdinge.png",
"number": "INV-2023-0001",
"counterparties": {
"supplier": {
"name": "Fuß Dinge GmbH",
"address_line_1": "Wanderntraße 31",
"address_line_2": "76433 - Füssen",
"country": "Germany",
"details": {
"VAT-ID": "DE123456789",
"E-Mail": "info@fussdinge.de",
},
},
"customer": {
"name": "Mustermann GmbH",
"address_line_1": "Friedrichstraße 31",
"address_line_2": "09234 - Berlin",
"country": "Germany",
"details": {
"VAT-ID": "DE987654321",
"E-Mail": "max@mustermann.com",
"Customer number": 123,
"Issue date": "2023.01.31",
"Due date": "2023.02.28",
"Service period": "2023.01.01 - 2023.01.31",
},
},
},
"line_items": [
{
"concept": "Shoes"
"unit_price": "85,00 €",
"quantity": "100",
"total": "8500,00 €"
},
],
"totals": {
"netto": "8500,00 €",
"tax": "1615,00 €",
"brutto": "10115,00 €",
},
"notes": [
"Please pay within 30 days before the due date.",
],
"footer": {
"left_section": [
"Fuß Dinge GmbH",
"Wanderntraße 31",
"76433 - Füssen",
"Germany",
"Tel.: +49 123456789",
"E-Mail: info@fussdinge.de",
],
"right_section": [
"Bank: Sparkasse",
"IBAN: DE08 0123456 7890",
"BIC: SPARKXXX",
],
},
},
},
headers={"Content-Type": "application/json"},
)
result_data = response.json()
file_url = result_data["file_url"]
Note that a POST to the /documents endpoint needs 2 fields: template which indicates
which template you want to render, and data which contains all the parameters values
to interpolate the template correctly.
A successful result will return a 201 status code. The response contains the file_url
which is an URL that can be used to download the generated document.
pdf_document = Path("document.pdf")
response = requests.get(file_url)
pdf_document.write_bytes(response.content)