Portugal (ATCUD and SAF-T)
Portuguese invoices carry an ATCUD code from a series registered with AT, the Portuguese tax authority, and must be exportable as SAF-T PT. Space Invoices handles both once you set up your entity and series.
What Space Invoices handles
- We number each document within your registered ATCUD series.
- We print the ATCUD and QR code on the invoice PDF.
- We generate the SAF-T PT file for a month or a full year.
- We add the standard legal wording for AT VAT exemption codes.
- We report foreign-currency documents in EUR.
- We validate credit notes against the original invoice.
Space Invoices does not decide whether a transaction qualifies for a VAT exemption. That stays with you and your accountant.
Not supported:
- FS simplified invoices, delivery notes, self-billing and third-party invoicing.
- Cash-accounting VAT.
- Drafts, editing issued documents, document email and e-invoicing.
- Direct payments on credit notes, applying an advance invoice to a final invoice, and correcting advance invoices.
- Recurring invoices. Existing schedules for a Portugal entity are paused on their next run.
Each entity’s country_rules.capabilities lists what is available.
Laws and standards
| Name | What it is |
|---|---|
| Decreto-Lei n.º 28/2019 | Portuguese law that introduced the ATCUD on invoices. |
| ATCUD (Código Único de Documento) | Unique document code built from your series validation code and the document number. |
| Série (series registration) | You register each document series with AT and receive its validation code. |
| SAF-T (PT) | The standard audit file of invoicing and accounting data you export for AT. |
| QR code | Fiscal QR code printed on every invoice. |
| Portal das Finanças | The AT portal where you register series. |
Before you start
| You need | Where you get it |
|---|---|
| Portuguese NIF | Your tax number, set on the entity. |
| ATCUD validation code for each series | Register the series on the Portal das Finanças. Sandbox entities accept codes starting with AA. |
Setup
Do this once per entity. You can also do it in the Space Invoices app under Portugal settings.
1. Create the entity
Set country_code: "PT", the NIF, address and settings.legal_details.legal_form. Companies other than sole traders also need registration_office and company_number. Limited and public companies need starting_capital as well.
const _entity = await sdk.entities.create({
name: "João Silva",
country: "Portugal",
country_code: "PT",
tax_number: "200000004",
currency_code: "EUR",
locale: "pt-PT",
address: "Avenida da Liberdade 10",
city: "Lisboa",
post_code: "1000-001",
settings: {
legal_details: {
legal_form: "sole_trader",
},
},
});2. Create the ATCUD series
Create an active series for each document family you issue (invoices and advance invoices share one, credit notes have their own). Use the validation code AT returned: in production, at least eight uppercase consonants or digits 2-9; in sandbox, a code starting with AA. We check the format only, not that AT registered it.
const _series = await sdk.ptAtcudSeries.create({
document_type: "invoice",
series_code: "FT2026A",
validation_code: "AABC2345",
first_number: "FT FT2026A/00001",
start_date: "2026-01-01",
is_manual: false,
initial_sequence: 1,
});Issue a compliant invoice
Create invoices as usual with the standard endpoints (not /custom). On top of the standard invoice fields, add:
Business customers (B2B)
| Field | When |
|---|---|
customer.tax_number | Always. The buyer’s NIF. |
customer.address, customer.city, customer.post_code | Always. Postal code in the format 0000-000. |
items[].classification | Always. product or service on every line, or save it on the item. |
The active series for the document family is used automatically. Set pt.series_id only to pick a specific series. Leave date out: Portuguese documents must be issued with today’s date in Europe/Lisbon.
const _invoice = await sdk.invoices.create({
customer: {
name: "Porto Payloads Lda",
country_code: "PT",
tax_number: "516403125", // Portugal: buyer NIF, required for businesses
address: "Rua de Santa Catarina 100", // Portugal: required for businesses
city: "Porto", // Portugal: required
post_code: "4000-442", // Portugal: format 0000-000
},
items: [
{
name: "Consulting",
quantity: 1,
price: 100,
classification: "service", // Portugal: required on every line
taxes: [{ rate: 23 }],
},
],
});Consumers (B2C)
| Field | When |
|---|---|
customer.is_end_consumer: true | Always. NIF and address become optional. |
items[].classification | Always. product or service on every line, or save it on the item. |
Without a NIF, the QR code and SAF-T use the consumer placeholder 999999990. This is still an ordinary invoice, not an FS simplified invoice.
const _invoice = await sdk.invoices.create({
customer: {
name: "Consumidor final",
country_code: "PT",
is_end_consumer: true, // Portugal: consumer sale, NIF and address optional
},
items: [
{
name: "Consulting",
quantity: 1,
price: 100,
classification: "service", // Portugal: required on every line
taxes: [{ rate: 23 }],
},
],
});VAT-exempt lines
| Field | When |
|---|---|
taxes[].pt_exemption_code | On every zero-rate line. For example M07. |
taxes[].pt_exemption_reason | Always for M19. Optional for other codes. Up to 60 characters. |
We add the standard legal wording for each code (M07 becomes Isento artigo 9.º do CIVA). Send pt_exemption_reason to use your own wording. You can also save the code and reason on a reusable tax. Taxed lines must not carry exemption fields.
const _invoice = await sdk.invoices.create({
customer: {
name: "Porto Payloads Lda",
country_code: "PT",
tax_number: "516403125",
address: "Rua de Santa Catarina 100",
city: "Porto",
post_code: "4000-442",
},
items: [
{
name: "Training",
quantity: 1,
price: 50,
classification: "service", // Portugal: required on every line
taxes: [
{ rate: 0, pt_exemption_code: "M07" }, // Portugal: AT exemption code
],
},
],
});Credit notes
| Field | When |
|---|---|
linked_documents | Always. The issued invoice (inv_...) of the same entity. |
items[].classification | Always. product or service on every line. |
pt.correction_reason | Always. Up to 50 characters. |
The credit note keeps the original customer and currency. Partial credit notes are allowed, up to the original amounts. Call invoices.getCreditOptions(id) to get each line’s remaining_quantity.
const _creditNote = await sdk.creditNotes.create({
customer: {
name: "Porto Payloads Lda",
country_code: "PT",
tax_number: "516403125",
address: "Rua de Santa Catarina 100",
city: "Porto",
post_code: "4000-442",
}, // Portugal: same customer as the original invoice
items: [
{
name: "Consulting",
quantity: 1,
price: 100,
classification: "service", // Portugal: required on every line
taxes: [{ rate: 23 }],
},
], // Portugal: original line details
linked_documents: [invoice.id], // Portugal: the invoice being corrected
pt: {
correction_reason: "Devolução de mercadoria", // Portugal: up to 50 chars
},
});What you get back
| Output | Meaning |
|---|---|
| ATCUD and QR code | Printed on the invoice PDF. |
| SAF-T PT XML | From GET /fiscalization/pt/saft/report. |
Export SAF-T
The default monthly export covers from to to within one calendar month, ending no later than today. audit covers a full year (up to today for the current year). The file is Windows-1252 XML: save the bytes as they are, without converting to UTF-8.
const _xml = await sdk.ptSafT.generateReport({
from: "2026-01-01",
to: "2026-01-31",
});
const _auditXml = await sdk.ptSafT.generateReport({
mode: "audit",
from: "2026-01-01",
});Special cases
- Operator. Optional
pt.operator_id(up to 30 characters) is stored as the SAF-TSourceID. It defaults to the authenticated user or API key. If staff share one API key, send a stable staff identifier. Never use a name or NIF. - Dates. Send date-only values such as
2026-09-10, nottoISOString().slice(0, 10), which uses UTC. Usedate_servicefor the service date. - Discounts. Use each line’s
discounts, for example{ "type": "percent", "value": 50 }for 50%. - Credit notes. A credit note does not refund money. Cancelling an invoice voids it in place, but only while no active credit note references it.
- Retiring a series. Retire it in Portugal settings or with
POST /fiscalization/pt/atcud-series/{id}/retire. Retired series cannot issue documents or be reopened, and AT is not notified. Finalize the series with AT yourself. - Registry office. Registry office, a space and company number must fit 50 characters together (the SAF-T
CompanyIDlimit). Use an abbreviation such asC.R.C. Lisboa. - Paper documents. Documents issued on paper while your system was down are recorded afterwards with
pt.manual: true, an active manual series,pt.manual_series_codeandpt.manual_sequential_number. Keep each document’s real issue date and recover in date order within each series. This is not a way to backdate invoices or import from another system. - PDF archive. Use
POST /documents/export/pdffor a ZIP of PDFs, then pollGET /documents/export/pdf/{id}untilstatusiscompleted.
Common errors
| Error | Fix |
|---|---|
422 PT documents must be issued with today's date | Leave date out or send today’s date in Europe/Lisbon. |
422 PT document item classification is required | Set classification to product or service on every line. |
422 PT customer tax number is not valid | Send a valid NIF. Placeholder numbers are rejected for business customers. |
422 PT customer address is required (same for city, post code, name) | Business customers need a full address, or set is_end_consumer: true. |
422 PT zero-rate items require a supported exemption code and a legal exemption reason | Add pt_exemption_code, and pt_exemption_reason for M19. |
422 No active PT ATCUD series found | Create or reactivate a series for that document family. |
422 PT credit notes must reference an original invoice in linked_documents | Link the issued invoice. |
422 on a /custom endpoint | Use the standard create endpoints. |