Request Series Creation

POST /v2/series/solicitar

Requests AGT to create a new numbering series for electronic invoicing. Each series defines a range of numbers that can be used to issue documents of a given type.

Why use this endpoint? Before issuing the first document of a new type or year, you need to create a series. For example, to issue invoices in 2026, first create an FT series for 2026, which returns the code FT3926S9043N. Then use that code to compose the document number: FT FT3926S9043N/1.


Request

Authentication

Include your API Key in one of these headers:

Authorization: Bearer feak_...

or

x-api-key: feak_...

Required scope: facturas:emitir or *

Body (JSON)

FieldTypeRequiredDefaultDescription
nifstring✅ Yes,Taxpayer NIF (e.g. "5000537039")
privateKeystring✅ Yes,Taxpayer RSA private key in PEM format
seriesYearstring \| number✅ Yes,Issue year (e.g. "2026")
documentTypestring✅ Yes,Document type: FT, FR, NC, ND, RC, etc.
establishmentNumberstringNo"SEDE"Establishment code. In sandbox use "SEDE"
seriesContingencyIndicatorstringNo"N""N" = Normal, "C" = Contingency

Response

Success (200 OK)

{
  "success": true,
  "serie": {
    "codigo": "FT3926S9043N",
    "quantidadeAutorizada": "999999999999",
    "primeiroDocumento": "1",
    "ultimoDocumento": "999999999999"
  }
}

Response Fields

FieldTypeDescription
successbooleantrue, series created successfully
serie.codigostringUnique series code (e.g. FT3926S9043N)
serie.quantidadeAutorizadastringMaximum number of documents authorized in this series
serie.primeiroDocumentostringFirst document number ("1")
serie.ultimoDocumentostringLast document number

Note: The document number to issue is formed as TYPE CODE/SEQ. Example: FT FT3926S9043N/1.

AGT Error with Details (400)

When AGT rejects the request but returns specific errors:

{
  "success": false,
  "error": "The establishment with code 99999 is not registered...",
  "code": "AGT_ERROR",
  "erros": [
    {
      "codigo": "E99",
      "descricao": "O estabelecimento com o código 99999 não se encontra registado para o contribuinte identificado pelo NIF 5000537039"
    }
  ]
}

Errors

Authentication Errors

HTTPcodeMessageCause
401UNAUTHORIZEDNot authorized.API Key was not sent
401UNAUTHORIZEDInvalid API Key.API Key does not exist or was revoked
403FORBIDDENInsufficient scope.The key does not have the facturas:emitir scope

Validation Errors

HTTPcodeMessageCause
400INVALID_JSONInvalid JSON body.The request body is not valid JSON
400VALIDATION_ERRORInvalid payload. Check documentation.Required fields missing
400VALIDATION_ERRORInvalid option: expected one of “FT”|“FR”|…Invalid documentType
400VALIDATION_ERRORInvalid option: expected one of “N”|“C”Invalid seriesContingencyIndicator

AGT Errors

HTTPcodeerros[].codigoDescription
400AGT_ERRORE99Establishment not registered for this NIF
400AGT_ERRORE06Taxpayer did not join electronic invoicing
400AGT_ERRORE30Taxpayer without registered activity
400AGT_ERRORE31Series code already in use
400AGT_ERRORE33Issue year does not match system year
400AGT_ERRORE48Unknown establishment
502AGT_ERROR,Communication error with AGT

Code Examples

TypeScript / Node.js

const API_KEY = "feak_bfc76ba48c0c286c9ce4bb2fcd7e178a399e329c59e529776bb5e01b0bfe8712";
const GATEWAY_URL = "https://connect.factflexi.com";

async function solicitarSerie(
  nif: string,
  privateKey: string,
  tipo: string,
  ano: string,
) {
  const response = await fetch(`${GATEWAY_URL}/v2/series/solicitar`, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "x-api-key": API_KEY,
    },
    body: JSON.stringify({
      nif,
      privateKey,
      seriesYear: ano,
      documentType: tipo,
      establishmentNumber: "SEDE",
      seriesContingencyIndicator: "N",
    }),
  });

  const data = await response.json();

  if (!data.success) {
    const detalhes = data.erros
      ? data.erros.map((e: any) => `  [${e.codigo}] ${e.descricao}`).join("\n")
      : "";
    throw new Error(`${data.code}: ${data.error}\n${detalhes}`);
  }

  console.log(`Series created: ${data.serie.codigo}`);
  console.log(`First document: ${data.serie.primeiroDocumento}`);
  console.log(`Last document: ${data.serie.ultimoDocumento}`);

  return data.serie;
}

// Usage, create FT series for 2026
const serieFT = await solicitarSerie(
  "5000537039",
  "-----BEGIN PRIVATE KEY-----\n...",
  "FT",
  "2026",
);

Python

import requests

API_KEY = "feak_bfc76ba48c0c286c9ce4bb2fcd7e178a399e329c59e529776bb5e01b0bfe8712"
GATEWAY_URL = "https://connect.factflexi.com"

def solicitar_serie(nif: str, private_key: str, tipo: str, ano: str):
    response = requests.post(
        f"{GATEWAY_URL}/v2/series/solicitar",
        json={
            "nif": nif,
            "privateKey": private_key,
            "seriesYear": ano,
            "documentType": tipo,
            "establishmentNumber": "SEDE",
            "seriesContingencyIndicator": "N",
        },
        headers={
            "Content-Type": "application/json",
            "x-api-key": API_KEY,
        },
    )
    data = response.json()

    if not data.get("success"):
        detalhes = "\n".join(
            f"  [{e['codigo']}] {e['descricao']}"
            for e in data.get("erros", [])
        )
        raise Exception(f"{data.get('code')}: {data.get('error')}\n{detalhes}")

    serie = data["serie"]
    print(f"Series created: {serie['codigo']}")
    print(f"First document: {serie['primeiroDocumento']}")
    return serie

# Usage
serie_ft = solicitar_serie("5000537039", "-----BEGIN PRIVATE KEY-----\n...", "FT", "2026")

PHP

<?php
define('API_KEY', 'feak_bfc76ba48c0c286c9ce4bb2fcd7e178a399e329c59e529776bb5e01b0bfe8712');
define('GATEWAY_URL', 'https://connect.factflexi.com');

function solicitarSerie(
    string $nif,
    string $privateKey,
    string $tipo,
    string $ano
): array {
    $ch = curl_init(GATEWAY_URL . '/v2/series/solicitar');
    curl_setopt_array($ch, [
        CURLOPT_POST => true,
        CURLOPT_HTTPHEADER => [
            'Content-Type: application/json',
            'x-api-key: ' . API_KEY,
        ],
        CURLOPT_POSTFIELDS => json_encode([
            'nif' => $nif,
            'privateKey' => $privateKey,
            'seriesYear' => $ano,
            'documentType' => $tipo,
            'establishmentNumber' => 'SEDE',
            'seriesContingencyIndicator' => 'N',
        ]),
        CURLOPT_RETURNTRANSFER => true,
    ]);

    $response = curl_exec($ch);
    curl_close($ch);
    $data = json_decode($response, true);

    if (!$data['success']) {
        $detalhes = '';
        if (!empty($data['erros'])) {
            foreach ($data['erros'] as $e) {
                $detalhes .= "  [{$e['codigo']}] {$e['descricao']}\n";
            }
        }
        throw new Exception("{$data['code']}: {$data['error']}\n{$detalhes}");
    }

    $serie = $data['serie'];
    echo "Series created: {$serie['codigo']}\n";
    return $serie;
}

// Usage
$serieFT = solicitarSerie(
    '5000537039',
    "-----BEGIN PRIVATE KEY-----\n...",
    'FT',
    '2026'
);

Contingency Indicator

ValueMeaningWhen to use
NNormalOnline issuance, document sent in real time to AGT
CContingencyOffline issuance, for when there is no connection to AGT

Document Types

CodeNameCodeName
FTInvoiceNCCredit Note
FRInvoice/ReceiptNDDebit Note
FAAdvance InvoiceRCIssued Receipt
FGGlobal InvoiceRGGeneral Receipt
GFGeneric InvoiceARCollection Notice/Receipt