POST
/api/nfs/company/create注册 NFS-e 公司
注册(或更新)用于 NFS-e 开具的企业。请求头 token 下若已存在相同 CNPJ 的企业,则更新该企业:必填的 NFS-e 字段(im、codigo_municipio_nfse、codigo_servico_nfse)以及证书和证书密码每次都会更新;选填的 NFS-e 字段(cnae_nfse、serie_nfse、number_nfse、regime_especial_tributacao、optante_simples_nacional)只在请求中传入时更新,未传时保留原值。cep 与已保存的不同时,按新 CEP 更新地址(cep、address、house_number、town、city、state,以及传入时的 complemento)和城市 IBGE 代码,IBGE 代码决定开具通道(圣保罗或国家系统);新 CEP 无法查询时返回错误,企业不做任何更新。名称不更新。否则创建新企业并返回该企业专用的 token。注意路径为 /api/nfs/...(没有 "e"),与其他 NFS-e 接口不同。
必需请求头
tokenstring | string | 集成商 B2B token |
signstring | string | MD5 签名 |
timestampstring | string | Unix 时间戳(秒) |
Body
cnpj*string | string | 企业 CNPJ(仅数字) |
name*string | string | 法人名称 |
cep*string | string | 邮政编码(仅数字)。 系统据此查询所在城市的 IBGE 代码,NFS-e 开具通道(圣保罗 Paulistana 或国家系统)由该城市决定 |
address*string | string | 街道 |
house_*string | string | 门牌号 |
town*string | string | 街区 |
city*string | string | 城市 |
state*string | string | 州缩写(2 个字母,如 "SP") |
cert_*string | string | A1 数字证书文件内容(.pfx/.p12 的 Base64,也接受 data:...;base64, 形式)。证书须能用 cert_pwd 打开且未过期 |
cert_string | string | 已废弃,2026-09-01 起拒绝。 证书 HTTPS URL |
cert_*string | string | 数字证书密码 |
im*string | string | 市政登记号(Inscrição Municipal) |
codigo_*string | string | 开具地城市的 IBGE 代码(7 位)。 国家系统开具时作为 DPS 的开具地和服务提供地;不决定开具通道 |
codigo_*string | string | 默认服务代码,开具请求未传 codigo_servico 时使用。国家系统为全国税目代码(cTribNac,6 位数字);圣保罗为市服务代码(5 位)。开具时非数字字符会被去掉 |
aliasstring | string | 商号 |
iestring | string | 州登记号 |
invoice_string | string | 税务体制。仅登记,不影响 NFS-e 开具 |
unitstring | string | 单位 / 分支 |
emailstring | string | 联系邮箱。国家系统开具时写入 DPS 的服务提供方信息 |
telefonestring | string | 电话。国家系统开具时写入 DPS 的服务提供方信息 |
complementostring | string | 地址补充 |
cnae_string | string | 默认 CNAE,开具请求未传 cnae 时使用。仅国家系统使用 |
serie_int | int | NFS-e 序列。 未传或为 0 时按序列 1 开具 |
number_int | int | 起始编号:该企业该序列的第一张 NFS-e 使用此编号,之后依次递增。 仅在该企业该序列尚未分配过编号(编号计数器尚不存在;开具失败的请求也会分配编号)时生效;已有计数器时不会被修改,编号不会回退。未设置或不大于 1 时从 1 开始 |
regime_int | int | 特殊税制代码,国家系统开具时写入 DPS 的 regEspTrib。 默认 0(无) |
optante_bool | bool | 是否为 Simples Nacional 纳税人。 国家系统开具时: true 写入 opSimpNac = 3(ME/EPP),false 写入 opSimpNac = 1(非 Simples Nacional)。默认 false |
* 必填字段。
注意:返回的 token 用于其他 NFS-e 接口(/api/nfse/create、/cancel、/get_danfse、/get_xml、/get_list)。如果企业已存在,消息为 "Empresa atualizada para NFS-e",返回的 token 是现有 token。NFS-e 的默认 ISS 税率不能通过本接口设置。
常见错误
| 消息 | 原因 |
|---|---|
| O campo cnpj é obrigatório | 必填字段为空。name、cep、address、house_number、town、city、state、cert_pwd、codigo_municipio_nfse、codigo_servico_nfse 返回同格式的消息 |
| O campo im (Inscrição Municipal) é obrigatório para NFS-e | 未传 im |
| Informe cert_content (conteúdo do certificado) | cert_content 与 cert_file 均未传 |
| cert_content não é um certificado válido (esperado Base64) / cert_content 不是合法的证书内容(应为 Base64) | cert_content 无法按 Base64 解码 |
| cert_file foi descontinuado; envie o certificado em cert_content ... | 使用了已停用的 cert_file |
| Certificado ou senha incorretos / 证书或密码不正确 | 证书无法用 cert_pwd 打开 |
| Certificado vencido em yyyy-MM-dd / 证书已过期:yyyy-MM-dd | 证书已过有效期 |
| Não foi possível consultar o CEP informado; a empresa não foi atualizada | 更新已有企业时 CEP 与已保存的不同,且无法查询新 CEP |
示例
# sign = md5(token + path + body + timestamp) # 按接口路径生成的调用模板,占位符替换为实际值 curl -X POST "https://api.tffiscal.com/api/nfs/company/create" \ -H "Content-Type: application/json" \ -H "token: $TOKEN" \ -H "timestamp: $TIMESTAMP" \ -H "sign: $SIGN" \ -d @body.json
{
"cnpj": "43649380000100",
"name": "EMPRESA EXEMPLO LTDA",
"alias": "Exemplo",
"ie": "ISENTO",
"invoice_type": "simples_nacional",
"email": "contato@empresa.com",
"telefone": "11999999999",
"cep": "03027020",
"address": "Rua Exemplo",
"house_number": "86",
"complemento": "Andar 2",
"town": "Centro",
"city": "São Paulo",
"state": "SP",
"cert_content": "MIIOkAIBAzCC...(Base64)",
"cert_pwd": "senha-do-certificado",
"im": "12345678",
"codigo_municipio_nfse": "3550308",
"codigo_servico_nfse": "07498",
"cnae_nfse": "6201501",
"serie_nfse": 1,
"number_nfse": 1,
"regime_especial_tributacao": 0,
"optante_simples_nacional": true
}
{
"success": true,
"message": "Empresa cadastrada para NFS-e",
"data": {
"company_id": 12345,
"token": "token-dedicado-da-empresa"
}
}