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)
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
nif | string | ✅ Yes | , | Taxpayer NIF (e.g. "5000537039") |
privateKey | string | ✅ Yes | , | Taxpayer RSA private key in PEM format |
seriesYear | string \| number | ✅ Yes | , | Issue year (e.g. "2026") |
documentType | string | ✅ Yes | , | Document type: FT, FR, NC, ND, RC, etc. |
establishmentNumber | string | No | "SEDE" | Establishment code. In sandbox use "SEDE" |
seriesContingencyIndicator | string | No | "N" | "N" = Normal, "C" = Contingency |
Response
Success (200 OK)
{
"success": true,
"serie": {
"codigo": "FT3926S9043N",
"quantidadeAutorizada": "999999999999",
"primeiroDocumento": "1",
"ultimoDocumento": "999999999999"
}
} Response Fields
| Field | Type | Description |
|---|---|---|
success | boolean | true, series created successfully |
serie.codigo | string | Unique series code (e.g. FT3926S9043N) |
serie.quantidadeAutorizada | string | Maximum number of documents authorized in this series |
serie.primeiroDocumento | string | First document number ("1") |
serie.ultimoDocumento | string | Last 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
| HTTP | code | Message | Cause |
|---|---|---|---|
| 401 | UNAUTHORIZED | Not authorized. | API Key was not sent |
| 401 | UNAUTHORIZED | Invalid API Key. | API Key does not exist or was revoked |
| 403 | FORBIDDEN | Insufficient scope. | The key does not have the facturas:emitir scope |
Validation Errors
| HTTP | code | Message | Cause |
|---|---|---|---|
| 400 | INVALID_JSON | Invalid JSON body. | The request body is not valid JSON |
| 400 | VALIDATION_ERROR | Invalid payload. Check documentation. | Required fields missing |
| 400 | VALIDATION_ERROR | Invalid option: expected one of “FT”|“FR”|… | Invalid documentType |
| 400 | VALIDATION_ERROR | Invalid option: expected one of “N”|“C” | Invalid seriesContingencyIndicator |
AGT Errors
| HTTP | code | erros[].codigo | Description |
|---|---|---|---|
| 400 | AGT_ERROR | E99 | Establishment not registered for this NIF |
| 400 | AGT_ERROR | E06 | Taxpayer did not join electronic invoicing |
| 400 | AGT_ERROR | E30 | Taxpayer without registered activity |
| 400 | AGT_ERROR | E31 | Series code already in use |
| 400 | AGT_ERROR | E33 | Issue year does not match system year |
| 400 | AGT_ERROR | E48 | Unknown establishment |
| 502 | AGT_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
| Value | Meaning | When to use |
|---|---|---|
N | Normal | Online issuance, document sent in real time to AGT |
C | Contingency | Offline issuance, for when there is no connection to AGT |
Document Types
| Code | Name | Code | Name |
|---|---|---|---|
FT | Invoice | NC | Credit Note |
FR | Invoice/Receipt | ND | Debit Note |
FA | Advance Invoice | RC | Issued Receipt |
FG | Global Invoice | RG | General Receipt |
GF | Generic Invoice | AR | Collection Notice/Receipt |