POST
/api/nfce/create开具 NFC-e
开具 NFC-e(模型 65,始终为州内出库,无运输)。与 NFe 端点的主要区别:消费者对象名为 client(不是 cliente);地址号为 client.number;消费者为可选;不存在 impostos.ipi、shipping_address、delivery_address 或 transportation。pag_info 中的金额字段名为 amount。
必需请求头
tokenstring | string | NFC-e 企业 token |
signstring | string | MD5 签名:MD5(token + path + body + timestamp) |
timestampstring | string | Unix 时间戳(秒,5 分钟窗口) |
Body(根)
nature_*string | string | 操作性质(如 "商品销售") |
issuance_*string | string | 开具类型:请传 "1"(正常)。税务局无响应时会自动启用离线应急;传 "9" 会以 tpEmis=9 把发票发往税务局但不带应急数据,通常会被拒绝 |
ambiente*string | string | "1" 生产、"2" 测试环境(homologação)。 测试环境下发票总会带收货方:不传 client 时使用 CPF 12345678909 和测试环境标准名称;传了 client 时只替换名称 |
products*array | array | 商品列表(详见下文) |
name*string | string | 商品名称(xProd)。只保留不带重音的字母、数字、空格、 - 和 /:带重音的字母、标点和 CJK 字符都会被删除(例:"Pão de Açúcar" → "Po de Acar")。测试环境下名称会被替换为标准文本 "NOTA FISCAL EMITIDA EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL" |
ncm*string | string | NCM(8 位) |
count*decimal | decimal | 数量 |
unit*string | string | 商业单位(如 "UN"、"KG") |
unit_*decimal | decimal | 单价 |
total_*decimal | decimal | 商品行总额。 必填,但不做校验:XML 中的 vProd 始终为 unit_price × count |
origem*int | int | 商品原产地(0..8) |
indicador_*int | int | 1 = 计入发票总额;0 = 不计入 |
category_string | string | NFC-e 税务类别 ID(未发送 impostos 时必填)。请核对 ID:只有一个都找不到时才会报 "Categoria fiscal NFC-e não encontrada";只找到部分时(或与 impostos 混用时),没有类别的商品行缺少 ICMS 组,开票会在 schema 校验时失败,不会发送到税务局 |
impostosobject | object | 手动税(category_id 的替代,无 IPI)。NFC-e 只读取: icms.codigo_cfop 和 icms.situacao_tributaria(没有内联 ICMS 税率 — 请使用不单独列示税额的 CSOSN/CST,如 102、500、60)、pis/cofins(situacao_tributaria、aliquota)以及 ibs_cbs(situacao_tributaria、classificacao_tributaria、p_ibs_uf、p_ibs_mun、p_cbs、p_red_aliq、p_dif、p_red_bc)。is 以及 221/620/830 的字段会被忽略 — 这些情况请使用 category_id。不要在同一张发票中混用 category_id 和 impostos:只要有一项是内联的,其余项的类别就不会加载。Simples 企业用 CSOSN(如 102、500),一般纳税企业用 CST(如 40、60)——与企业 CRT 不符会在提交税务局前被拒绝(拒绝 590/591);codigo_cfop 为空时取 5102 NFC-e 不输出选择性消费税(is),无论内联还是通过类别。只有当发票所有商品行都有 IBS/CBS 时才输出合计 IBSCBSTot。 |
codigo*string | string | 内部商品代码(cProd)。必填 — 缺少时开票会以内部错误失败 |
ceststring | string | CEST |
gtinstring | string | 商业 GTIN/EAN |
gtin_string | string | 应税 GTIN |
discount_decimal | decimal | 商品行折扣 |
nItemPedint | int | 采购订单行号 (I61)。 从根 id 取得的 xPed 所引用订单内的商品行序号。有效范围: 1–999999。默认: 省略。也接受别名 n_item_ped。 |
desconta_boolean | boolean | 算 PIS/COFINS 前先减去本行 ICMS,按(金额 − ICMS)计税,最低为 0(最高法院 Tema 69); 默认 false 不减,税额会偏高。与类别上的同名标志按"或"组合:任一为 true 即生效 |
desconta_boolean | boolean | 按 RFB 官方公式(常规制度计算器的统一税基)计算 IBS/CBS 税基:本行金额(商品 + 运费 + 保险 + 其他费用 − 折扣)+ II − ICMS − FCP − 单一环节 ICMS − 目的州 DIFAL 和 FCP − ISSQN − PIS − COFINS,最低为 0(PIS、COFINS 仅 2026 年扣除); 若 desconta_icms_pis_cofins 也为 true,则用扣减后的 PIS/COFINS;默认 false。与类别上的同名标志按"或"组合:任一为 true 即生效 |
idstring | string | 外部标识——写入 xPed,去掉空格并截断为 15 个字符。NFC-e 不去重:重复提交同一个 id 会再开一张票 |
ind_string | string | 购买者在场方式:"1" 现场(默认)或 "4" 送货上门——模型 65 下税务局接受的值("5" 场外现场,视州而定)。"0"、"2"、"3"、"9" 会原样提交并被税务局拒绝;其他任何值会被静默改为 "1" |
ind_string | string | 请使用 "0"(无中介)。没有 infIntermed 组(中介 CNPJ)对应的字段,而传 "1" 时税务局要求该组 |
total_decimal | decimal | 发票总折扣。 注意:只填写合计 vDesc,不会分摊到各商品项,会导致拒绝。建议使用 products[].discount_price 并省略此字段 |
trocodecimal | decimal | 找零金额(vTroco)。税务局要求 找零 = 各 amount 之和 − 发票总额,因此现金的 amount 应包含找零 |
segurodecimal | decimal | 保险金额——按各商品数量(而非金额)比例分摊并逐项四舍五入,合计可能与传入值相差几分 |
outras_decimal | decimal | 其他附加费用——按各商品数量(而非金额)比例分摊并逐项四舍五入,合计可能与传入值相差几分 |
informacoes_string | string | 给消费者的补充信息 |
informacoes_string | string | 给税务机关的信息 |
clientobject | object | 消费者数据(可选 — 见表格) 仅在消费者已识别时填写。CPF 或 CNPJ 仅传数字。 |
cpfstring | string | CPF(设定为自然人) |
cnpjstring | string | CNPJ(法人) |
iestring | string | 州登记号 — NFC-e 中忽略(indIEDest 始终为 9) |
namestring | string | 姓名 / 法人名称 |
enderecostring | string | 街道 |
numberstring | string | 地址号 (注意:与 NFe 不同,NFe 使用 numero) |
complementostring | string | 补充 |
bairrostring | string | 街区 |
citystring | string | 城市 |
ufstring | string | 州(传了 CEP 时会被 CEP 对应的州替换) |
cepstring | string | 邮政编码(仅数字)。 只有在 ind_pres="4" 且填写了 CEP 时,消费者地址才会写入 XML |
telefonestring | string | 电话 |
emailstring | string | 电子邮箱 |
pag_array | array | 付款(默认:现金、即时付款 — 见表格) |
payment_*string | string | "0" 现付、"1" 赊账 |
payment_*string | string | 付款方式(01=现金、03=信用卡、04=借记卡、17=PIX、99=其他 等)。 避免使用 "99":NFC-e 目前不发送说明(xPag),税务局会拒绝(441)。请始终传 2 位代码("01"、"03"、"17"…):NFC-e 下 API 不校验该值,传 "1" 或 "3" 会在生成 XML 时失败(success:false),不会发送到税务局 |
amountdecimal | decimal | 此方式支付的金额(如有找零则包含找零)。 省略时该方式取发票总额 — 有多种付款方式时,请每种都填写 |
card_object | object | |
integration_string | string | "1" 集成,"2" 非集成。可选;传了 card_info 时,此字段和 brand_code 必填。目前 card_info 的数据不会写入 XML:卡、PIX 及其他电子支付方式(除 01、02、14、15、16、90、91、99 外的所有方式)的 card 组都以 tpIntegra=2 输出,不含卡组织、CNPJ 和授权码 |
brand_string | string | 卡组织(传了 card_info 时必填;不会输出——见上文) |
acquirer_string | string | 收单方 CNPJ |
authorization_string | string | 授权代码 |
* 必填字段。category_id 或 impostos 二选一,必填。
返回字段(data)
uuidstring | string | NFC-e 内部标识符。 用于后续调用( /api/nfce/get_detail、/api/nfce/get_danfe) |
statusstring | string | 状态:"Success"(已授权)、"Failed"(被拒/失败)、"Contingencia"(离线应急开具,待传输) |
motivostring | string | 税务机关针对 cStat 的文本;已映射的拒绝原因为葡/中双语。目前授权成功时返回 "Rejeição 100: Autorizado o uso da NF-e"——请根据 success/status 判断,不要依据文本 |
nfceint | int | 已开具的 NFC-e 号码(注意:字段名是 nfce,不是 nfe) |
serieint | int | NFC-e 系列号 |
chavestring | string | 44 位访问密钥(未授权时为空) |
modelostring | string | 单据模型:"nfce" |
xmlstring | string | 已授权 XML 的 URL |
danfestring | string | NFC-e DANFE 的 URL — 开具时为空; 请通过 /api/nfce/get_danfe 按需生成 |
离线应急开具时(税务局不可用时自动启用),返回的
status 为 "Contingencia",并带有额外字段 contingencia: true 和 tpEmis: 9;该发票需要之后传输给税务局。
返回 — 拒绝 / 错误
当税务局拒绝该发票时,
success 为 false,data.motivo 给出原因;chave 返回为空。字段校验错误(提交税务局之前)返回 success: false,消息位于 message,且没有 data 对象。
{
"success": false,
"data": {
"uuid": "65f8b9a1c2d3e4f5a6b7c8d9",
"status": "Failed",
"motivo": "Rejeição 226: Código da UF do Emitente diverge da UF autorizadora / 拒绝 226: 发件人所在州代码与授权州不一致",
"nfce": 5,
"serie": 1,
"chave": "",
"modelo": "nfce",
"xml": "",
"danfe": ""
}
}示例
# sign = md5(token + path + body + timestamp) # 按接口路径生成的调用模板,占位符替换为实际值 curl -X POST "https://api.tffiscal.com/api/nfce/create" \ -H "Content-Type: application/json" \ -H "token: $TOKEN" \ -H "timestamp: $TIMESTAMP" \ -H "sign: $SIGN" \ -d @body.json
{
"nature_of_operation": "Venda de mercadoria",
"issuance_type": "1",
"ambiente": "2",
"ind_pres": "1",
"client": {
"cpf": "12345678909",
"name": "Consumidor Final"
},
"products": [
{
"codigo": "PROD001",
"name": "Refrigerante 2L",
"ncm": "22021000",
"count": 2,
"unit": "UN",
"unit_price": 10.50,
"total_price": 21.00,
"origem": 0,
"indicador_total": 1,
"category_id": "TF123"
}
],
"pag_info": [
{
"payment_indicator": "0",
"payment_method": "17",
"amount": 21.00
}
]
}
{
"id": "PED-2026-0001",
"nature_of_operation": "Venda de mercadoria",
"issuance_type": "1",
"ambiente": "2",
"ind_pres": "1",
"ind_intermed": "0",
"total_discount_amount": 0.00,
"troco": 0.00,
"seguro": 0.00,
"outras_despesas": 0.00,
"informacoes_complementares": "Pedido entregue na loja",
"informacoes_fisco": "ICMS recolhido conforme legislação",
"client": {
"cpf": "12345678909",
"cnpj": "",
"ie": "",
"name": "Consumidor Final",
"endereco": "Rua das Flores",
"number": "100",
"complemento": "Sala 5",
"bairro": "Centro",
"city": "São Paulo",
"uf": "SP",
"cep": "01001000",
"telefone": "11999998888",
"email": "cliente@exemplo.com"
},
"products": [
{
"codigo": "PROD001",
"name": "Refrigerante 2L",
"ncm": "22021000",
"cest": "0300100",
"gtin": "7891234567895",
"gtin_tributavel": "7891234567895",
"count": 2,
"unit": "UN",
"unit_price": 10.50,
"total_price": 21.00,
"discount_price": 0.00,
"origem": 0,
"indicador_total": 1,
"category_id": "TF123",
"nItemPed": 1
},
{
"codigo": "PROD002",
"name": "Salgadinho 100g",
"ncm": "19053100",
"count": 1,
"unit": "UN",
"unit_price": 8.00,
"total_price": 8.00,
"origem": 0,
"indicador_total": 1,
"category_id": "TF124",
"nItemPed": 2
}
],
"pag_info": [
{
"payment_indicator": "0",
"payment_method": "03",
"amount": 29.00,
"card_info": {
"integration_type": "1",
"brand_code": "01",
"acquirer_cnpj": "01234567000195",
"authorization_code": "AUTH123456"
}
}
]
}
{
"success": true,
"data": {
"uuid": "65f8b9a1c2d3e4f5a6b7c8d9",
"status": "Success",
"motivo": "Rejeição 100: Autorizado o uso da NF-e",
"nfce": 5,
"serie": 1,
"chave": "35260111444777000161650010000000051234567893",
"modelo": "nfce",
"xml": "https://oss.example.com/.../chave.xml",
"danfe": ""
}
}NFC-e 完整示例
示例 1 — 现场销售(无收货方)
{
"nature_of_operation": "Venda de mercadoria",
"issuance_type": "1",
"ambiente": "2",
"ind_pres": "1",
"products": [
{
"codigo": "001",
"name": "Refrigerante 350ml",
"ncm": "22021000",
"count": 3,
"unit": "UN",
"unit_price": 5.50,
"total_price": 16.50,
"category_id": "TF123",
"origem": 0,
"indicador_total": 1
}
],
"pag_info": [
{ "payment_indicator": "0", "payment_method": "17" }
]
}示例 2 — 送货上门(含收货方)
{
"nature_of_operation": "Venda de mercadoria",
"issuance_type": "1",
"ambiente": "2",
"ind_pres": "4",
"client": {
"cpf": "12345678909",
"name": "Maria Silva",
"endereco": "Rua das Flores",
"number": "456",
"bairro": "Jardim Primavera",
"city": "São Paulo",
"uf": "SP",
"cep": "04567000"
},
"products": [
{
"codigo": "PIZZA01",
"name": "Pizza Grande Marguerita",
"ncm": "19059090",
"count": 1,
"unit": "UN",
"unit_price": 45.90,
"total_price": 45.90,
"category_id": "TF124",
"origem": 0,
"indicador_total": 1
}
],
"pag_info": [
{ "payment_indicator": "0", "payment_method": "03" }
],
"informacoes_complementares": "Entrega em até 40 minutos"
}