E-Invoicing API Quickstart: 15-Minute Guide

This guide walks you through integrating EFact into an existing application, creating an invoice, and tracking its clearance status through to ACCEPTED.

In short

Issuing your first DGI-compliant electronic invoice with EFact takes approximately 15 minutes: install the Node.js or Python SDK, configure your secret API key, and call invoices.create(). EFact generates UBL 2.1 XML, signs it with XAdES, and submits it to the DGI; status transitions to ACCEPTED within seconds in the sandbox.

Prerequisites

  • • An EFact account with a secret API key (efact_sk_...)
  • • Node.js ≥ 18 (for the Node.js SDK)

Step 1 - Install the backend SDK

Node.js / TypeScript

npm install @itzenata/efact-node

Step 2 - Create an Invoice

Node.js / TypeScript

Node.js Create Invoice
import { EFact, CreateInvoiceRequestPaymentMethodEnum } from '@itzenata/efact-node'

const efact = new EFact(process.env.EFACT_SECRET_KEY!)

const invoice = await efact.invoices.create({
  invoiceNumber: 'INV-2026-042',
  invoiceDate: '2026-06-19',
  currency: 'MAD',
  paymentMethod: CreateInvoiceRequestPaymentMethodEnum.BankTransfer,
  buyerIce: '001234567890123',    // ICE - 15 digits
  buyerName: 'Client SARL',
  buyerAddress: 'Casablanca, Morocco',
  lines: [
    {
      lineNumber: 1,
      description: 'Consulting services',
      quantity: 1,
      unitPrice: 12000,
      vatRate: 20,
    },
  ],
})

console.log(invoice.id, invoice.status)

What happens on EFact servers: Our API validates your request, generates compliant UBL 2.1 XML, and applies the XAdES electronic signature synchronously: the returned invoice is already at status SIGNED. Transmission to the DGI then proceeds asynchronously; track it via the status endpoint.

Step 3 - Check status

Node.js / TypeScript

Poll Invoice Status
const status = await efact.invoices.retrieveStatus(invoice.id)

if (status.status === 'ACCEPTED') {
  console.log('DGI reference:', status.dgiReference)
} else if (status.status === 'REJECTED') {
  console.log('Rejection reason:', status.dgiErrorMessage)
}

The status progresses through SIGNED → TRANSMITTED → ACCEPTED or REJECTED. Poll efact.invoices.retrieveStatus(id) until you reach a terminal status.

DGI simulator: the national DGI e-invoicing platform is not yet open to integrations. Clearance (ACCEPTED / REJECTED status, DGI reference, QR code) currently runs on our simulator, which reproduces the official flow. Moving to the official platform requires no change on the client side. Learn more

Expected outcome

In under 15 minutes, your application:

  1. 1. Creates an invoice with 3 lines of SDK code
  2. 2. Tracks invoice status through to DGI clearance

Next steps

Frequently asked questions

How long does it take to issue your first invoice with EFact?

Expect about 15 minutes: install the SDK (@itzenata/efact-node or itzenata-efact), configure your API key, then call invoices.create() with your invoice data. EFact generates the UBL 2.1 XML, applies the electronic signature, and transmits it to the DGI. The status moves to ACCEPTED in a few seconds in the simulator.

What do I need to start the EFact integration?

You need an EFact account with a configured organization (legal details and signing certificate), a secret API key (efact_sk_), and the official Node.js / TypeScript SDK. You do not need to set up any signature infrastructure or DGI transmission pipeline on your side.

How do I track an invoice status after creation?

After create(), the invoice starts as PENDING and then moves to ACCEPTED or REJECTED. Query invoices.retrieveStatus(id) every 2 to 5 seconds. Once ACCEPTED, you receive the DGI reference and artifacts (signed XML, PDF). In production, webhooks replace polling.