Skip to content

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

NameWhat it is
Decreto-Lei n.º 28/2019Portuguese 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 codeFiscal QR code printed on every invoice.
Portal das FinançasThe AT portal where you register series.

Before you start

You needWhere you get it
Portuguese NIFYour tax number, set on the entity.
ATCUD validation code for each seriesRegister 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.

Create Portugal entitytypescript
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.

Create sandbox ATCUD seriestypescript
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)

FieldWhen
customer.tax_numberAlways. The buyer’s NIF.
customer.address, customer.city, customer.post_codeAlways. Postal code in the format 0000-000.
items[].classificationAlways. 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.

Issue an invoice to a Portuguese businesstypescript
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)

FieldWhen
customer.is_end_consumer: trueAlways. NIF and address become optional.
items[].classificationAlways. 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.

Issue an invoice to a consumer (consumidor final)typescript
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

FieldWhen
taxes[].pt_exemption_codeOn every zero-rate line. For example M07.
taxes[].pt_exemption_reasonAlways 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.

Issue an invoice with a VAT-exempt linetypescript
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

FieldWhen
linked_documentsAlways. The issued invoice (inv_...) of the same entity.
items[].classificationAlways. product or service on every line.
pt.correction_reasonAlways. 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.

Issue a credit note for an invoicetypescript
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

OutputMeaning
ATCUD and QR codePrinted on the invoice PDF.
SAF-T PT XMLFrom 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.

Export SAF-Ttypescript
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-T SourceID. 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, not toISOString().slice(0, 10), which uses UTC. Use date_service for 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 CompanyID limit). Use an abbreviation such as C.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_code and pt.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/pdf for a ZIP of PDFs, then poll GET /documents/export/pdf/{id} until status is completed.

Common errors

ErrorFix
422 PT documents must be issued with today's dateLeave date out or send today’s date in Europe/Lisbon.
422 PT document item classification is requiredSet classification to product or service on every line.
422 PT customer tax number is not validSend 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 reasonAdd pt_exemption_code, and pt_exemption_reason for M19.
422 No active PT ATCUD series foundCreate or reactivate a series for that document family.
422 PT credit notes must reference an original invoice in linked_documentsLink the issued invoice.
422 on a /custom endpointUse the standard create endpoints.

Invoices · Credit notes · PT ATCUD series · PT SAF-T