Skip to main content
All use cases
MarketplaceMarketplaces

Every order: charged, invoiced, shipped, notified.

The agent takes each order from your stream and makes four calls: a Pix charge with codespar_charge, the NF-e with codespar_invoice, the shipping label with codespar_ship and a WhatsApp text with codespar_notify. Each goes to the provider your project connected. NFe.io and Z-API have no test environment: a test key is refused there, and in a live project the NF-e is issued for real and the message is really sent.

BeforeFive tools, five tabs, manual handoffs
AfterOne agent, four calls per order
4
meta tools per order
Try it in the Sandbox
Pix
Charge
codespar_charge mints a Pix charge on the connected provider
NF-e
Invoice
codespar_invoice issues the NF-e through NFe.io, in live projects only
Melhor Envio
Ship
codespar_ship quotes, buys the label and tracks
WhatsApp
Notify
codespar_notify sends a WhatsApp text through Z-API, in live projects only
Illustrative example · demo data

One order, four calls.

An example with demo data: the agent charges order #4821 by Pix, issues the NF-e, buys the label and sends the buyer a WhatsApp text. The NF-e and the WhatsApp text only run in a live project.

  • The Pix charge goes to the provider the project connected
  • NF-e through NFe.io: live projects only, no test environment
  • WhatsApp through Z-API: a text, queued; live projects only
Order #4821
charge · invoice · ship · notify
Agent
codespar_charge · Pix · R$ 219,80
via codespar_charge · Asaas
✓ Pix
codespar_invoice · NF-e
via codespar_invoice · NFe.io
codespar_ship · label
via codespar_ship · Melhor Envio
codespar_notify · WhatsApp · QUEUED
via codespar_notify · Z-API
✓ #4821 · Pix · NF-e · label · WhatsApporder_4821
The pain

The conversation is the easy part.

Fulfillment lives in tools that do not talk to each other: charge here, invoice there, ship somewhere else, notify by hand.

Charge in one tool, invoice in another

The agent charges and invoices with two meta tools

Buy the label in a third tab

codespar_ship quotes and buys the label at Melhor Envio

Notify the buyer by hand

codespar_notify sends a WhatsApp text through Z-API

Track the parcel on the carrier's site

codespar_ship with action=track reads the tracking

How the agent does it

Fulfillment as four calls.

The agent reads each order from your stream and calls codespar_charge (Pix), codespar_invoice (NF-e), codespar_ship (label) and codespar_notify (WhatsApp). Each call goes to the provider the project connected. The NF-e and the WhatsApp text run only in a live project, where they are real; the fiscal setup lives on the NFe.io company the connection points to. Writing the order back to your ERP is your integration.

01
Order
Your system

Read from your stream

02
Charge
codespar_charge

Pix charge

Connected provider
03
Invoice
codespar_invoice

NF-e · live projects only

NFe.io
04
Ship
codespar_ship

Label

Melhor Envio
05
Notify
codespar_notify

WhatsApp text · live projects only

Z-API
Architecture

Your order stream hands the agent each paid-for order. codespar_charge mints the Pix charge on the connected provider (Asaas, Mercado Pago, EBANX, Celcoin, Iugu or Stone). codespar_invoice issues the NF-e through NFe.io for the company the connection points to. codespar_ship quotes, buys and tracks the label at Melhor Envio. codespar_notify sends a WhatsApp text through Z-API, which answers that the message is queued. Writing the result back to your ERP is your integration.

In code

The code, and what it assumes.

autonomous-fulfillment.ts
// Prerequisites: CODESPAR_API_KEY set to a test key (csk_test_…), a Pix
// provider (Asaas, for instance) and Melhor Envio connected to the project.
// NFe.io and Z-API have no test environment: codespar_invoice (NF-e) and
// codespar_notify (WhatsApp) need a live key, and then issue and send for real.
import { CodeSpar } from "@codespar/sdk";

const session = await new CodeSpar().create("user_0000", { preset: "brazilian" });
const buyer = { name: "Ana Souza", email: "ana@example.com", document: "12345678909", phone: "+5511999990000" };

// 1 · charge the order by Pix (amount in reais)
const charge = await session.charge({ amount: 219.8, currency: "BRL", method: "pix", description: "Order #4821", buyer });
console.log(charge.status, charge.pix_copy_paste);

// 2 · buy the shipping label at Melhor Envio
const label = await session.ship({
  action: "label",
  origin: { postal_code: "01310-100" },
  destination: { postal_code: "20040-002" },
  items: [{ description: "Order #4821", weight_g: 800, width_cm: 15, height_cm: 10, length_cm: 20 }],
});
console.log(label.status, label.tracking_code);

Example with the published SDK (@codespar/sdk 0.16.11). Its prerequisites are in the comments. Compiling does not prove the integration: run it in test mode first.

Featured tools
codespar_charge

Mints a Pix charge on the provider the project connected.

codespar_invoice

Issues the NF-e through NFe.io; live projects only.

codespar_ship

Quotes, buys and tracks the shipping label at Melhor Envio.

codespar_notify

Sends a WhatsApp text through Z-API; live projects only.

See the meta-tool reference

Start with a test key.

Test keys are free. Open the sandbox, connect the providers your project uses and see which tools it can call before you build.

Autonomous fulfillment agent — CodeSpar | CodeSpar