-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.py
More file actions
66 lines (59 loc) · 2.02 KB
/
Copy pathcreate.py
File metadata and controls
66 lines (59 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Create a UN/CEFACT Cross Industry Invoice (CII D16B) using the InvoiceXML API.
# Sends a JSON invoice model and receives the CII XML.
#
# Get API key: https://www.invoicexml.com/account/authentication
# Docs: https://www.invoicexml.com/docs/api/create/cii
#
# Dependency: pip install requests
import requests
import sys
# Raw key only, without the "Bearer " prefix (it is added below).
api_key = "YOUR_API_KEY"
# Totals and the VAT breakdown are calculated from the line items.
payload = {
"invoice": {
"invoiceNumber": "CII-2026-001",
"issueDate": "2026-05-18",
"currency": "EUR",
"seller": {
"name": "Acme GmbH",
"vatIdentifier": "DE123456789",
"legalRegistration": {"identifier": "HRB 12345"},
"postalAddress": {
"line1": "Hauptstraße 12",
"city": "Berlin",
"postCode": "10115",
"country": "DE",
},
},
"buyer": {
"name": "Globex SAS",
"postalAddress": {
"line1": "15 rue de Rivoli",
"city": "Paris",
"postCode": "75001",
"country": "FR",
},
},
"paymentDetails": {"paymentAccountIdentifier": "DE89370400440532013000"},
"lines": [
{
"quantity": 10,
"priceDetails": {"netPrice": 150.00},
"vatInformation": {"rate": 19.00},
"item": {"name": "Senior consulting"},
},
],
},
}
response = requests.post(
"https://api.invoicexml.com/v1/create/cii",
headers={"Authorization": f"Bearer {api_key}"},
json=payload,
)
if not response.ok:
sys.stderr.write(f"InvoiceXML API error {response.status_code}: {response.text}\n")
sys.exit(1)
with open("invoice-cii.xml", "w", encoding="utf-8") as f:
f.write(response.text)
print(f"Saved invoice-cii.xml ({len(response.text)} chars)")