### Quick Setup for NFE.io Node.js Examples Source: https://nfe.io/docs/desenvolvedores/bibliotecas/nodejs Clone the repository, install dependencies, configure credentials interactively, and run tests or examples. ```bash # 1. Clone and install git clone https://github.com/nfe/client-nodejs.git cd client-nodejs npm install # 2. Configure your credentials (interactive) npm run examples:setup # 3. Test the connection npm run examples:test # 4. Run the examples npm run examples ``` -------------------------------- ### Install dependencies Source: https://nfe.io/docs/desenvolvedores/bibliotecas/nodejs/exemplos Install project dependencies using npm. This is required before building or running examples. ```bash npm install ``` -------------------------------- ### Run npm setup script Source: https://nfe.io/docs/desenvolvedores/bibliotecas/nodejs/exemplos Execute this script to automatically set up your API key, environment, and .env.test file. Recommended for initial setup. ```bash npm run examples:setup ``` -------------------------------- ### Create Product with HTTP Client (Python) Source: https://nfe.io/docs/desenvolvedores/rest-api/cadastro-de-produtos-v1/products-post Example of creating a product using the http.client library in Python. Ensure you replace placeholders like '' and 'tenantId' with your actual credentials and identifiers. ```python import http.client import json conn = http.client.HTTPSConnection("api.nfse.io") payload = json.dumps({ "tenantId": "string", "collectionId": "string", "sku": "string", "origin": "national", "description": "string", "gtin": "string", "taxGtin": "string", "tax": { "ncm": "string", "cest": "string" }, "customTax": [ { "issuer": [ { "taxRegime": "NationalSimple", "taxProfile": "none" } ], "recipient": [ { "taxProfile": "none" } ], "OperationCode": 0, "intraState": { "cfop": 0, "icms": { "cst": "string", "modBC": "string", "modBCST": "string", "motDesICMS": "string", "motDesICMSST": "string", "pICMS": "string", "pRedBC": "string", "pMVAST": "string", "pRedBCST": "string", "pICMSST": "string", "pFCP": "string", "pFCPST": "string", "pFCPSTRet": "string", "pRedBCEfet": "string", "pICMSEfet": "string", "pDif": "string", "pFCPDif": "string", "pCredSN": "string" }, "pis": { "cst": "string", "pPIS": "string" }, "cofins": { "cst": "string", "pCOFINS": "string" } }, "interState": { "cfop": 0, "icms": { "cst": "string", "modBC": "string", "modBCST": "string", "motDesICMS": "string", "motDesICMSST": "string", "pICMS": "string", "pRedBC": "string", "pMVAST": "string", "pRedBCST": "string", "pICMSST": "string", "pFCP": "string", "pFCPST": "string", "pFCPSTRet": "string", "pRedBCEfet": "string", "pICMSEfet": "string", "pDif": "string", "pFCPDif": "string", "pCredSN": "string" }, "pis": { "cst": "string", "pPIS": "string" }, "cofins": { "cst": "string", "pCOFINS": "string" } } } ] }) headers = { 'Content-Type': 'application/json', 'Accept': 'application/json', 'Authorization': '' } conn.request("POST", "/:tenantId/products?apikey=%3CapiKey%3E", payload, headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8")) ``` -------------------------------- ### List Companies cURL Example Source: https://nfe.io/docs/documentacao/gerenciamento-empresas/api-empresas Example of how to make a GET request to list companies using cURL, including the Authorization header. ```bash curl -X GET "https://api.nfse.io/v2/companies?limit=20" \ -H "Authorization: sk_live_xxx" ``` -------------------------------- ### Practical Examples Source: https://nfe.io/docs/desenvolvedores/bibliotecas/nodejs Run ready-to-use examples to test NFE.io functionalities. ```APIDOC ## Practical Examples The `Examples` page provides complete examples you can run with your credentials. **How to Run:** ```bash # Interactive mode with menu npm run examples # Or directly node examples/run-examples.js ``` **Available Examples:** 1. **List Invoices**: Query existing invoices. 2. **Manage People**: CRUD operations for customers (individuals/legal entities). 3. **Issue Invoice**: Complete workflow: create → email → download PDF/XML. 4. **Configure Webhooks**: Receive notifications for events. ``` -------------------------------- ### Python HTTP Client Example Source: https://nfe.io/docs/desenvolvedores/rest-api/consulta-de-enderecos-v1/v-2-addresses-by-term-get Example of how to make a GET request to the address search API using Python's http.client. ```python import http.client conn = http.client.HTTPSConnection("") payload = '' headers = { 'Accept': 'application/json', 'Authorization': '' } conn.request("GET", "//address.api.nfe.io/v2/addresses/:term", payload, headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8")) ``` -------------------------------- ### Run examples with helper script Source: https://nfe.io/docs/desenvolvedores/bibliotecas/nodejs/exemplos Use the helper script to run examples interactively, execute a specific example by its number, or run all examples in sequence. ```bash node examples/run-examples.js ``` ```bash node examples/run-examples.js 1 ``` ```bash node examples/run-examples.js all ``` -------------------------------- ### Python HTTP Client Example Source: https://nfe.io/docs/desenvolvedores/rest-api/contribuintes-v2/consultar-todas-as-empresas-da-conta Example of how to make a GET request to the NFE.io API using Python's http.client library, including authorization. ```python import http.client conn = http.client.HTTPSConnection("nfe.io") payload = '' headers = { 'Accept': 'application/json', 'Authorization': '' } conn.request("GET", "/v2/companies?apikey=%3CapiKey%3E", payload, headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8")) ``` -------------------------------- ### Instalar NFE.io SDK (v2 e v3) Source: https://nfe.io/docs/desenvolvedores/bibliotecas/nodejs/migracao-v2 Instala o SDK NFE.io. As versões v2 e v3 usam o mesmo nome de pacote. ```bash # v2 e v3 usam o mesmo nome npm install nfe-io ``` -------------------------------- ### Python HTTP Client Example Source: https://nfe.io/docs/desenvolvedores/rest-api/calculo-de-impostos-v1/listar-perfis-fiscais-do-destinatario Example of how to make a GET request to the NFE.io API using Python's http.client to list recipient tax profiles. ```python import http.client conn = http.client.HTTPSConnection("nfe.io") payload = '' headers = { 'Accept': 'application/json', 'Authorization': '' } conn.request("GET", "/tax-codes/recipient-tax-profile?apikey=%3CapiKey%3E", payload, headers) res = conn.getresponse() data = res.read() print(data.decode("utf-8")) ```