Python Examples
All examples use the requests library. Install it with:
pip install requestsimport requests
API_BASE = "https://api.suit.pe"API_KEY = "sk_live_YOUR_API_KEY"
headers = { "Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"}Emit a Factura (Invoice)
Section titled “Emit a Factura (Invoice)”def emit_invoice(): response = requests.post( f"{API_BASE}/api/invoices", headers=headers, json={ "series": "F001", "correlative": 1, "issueDate": "2026-02-20", "dueDate": "2026-03-20", "currencyCode": "PEN", "customer": { "identityType": "6", "identityNumber": "20100047218", "name": "Empresa Cliente SAC", "address": "Av. Javier Prado 1234, San Isidro" }, "items": [ { "code": "SRV-001", "description": "Servicio de consultoria", "quantity": 1, "unitCode": "ZZ", "unitPrice": 1000.00, "igvType": "10" } ] } )
result = response.json() print(f"Invoice: {result}") # {"id": "cm3abc123", "status": "ACCEPTED", "documentId": "20123456789-01-F001-00000001"} return resultEmit a Boleta (Receipt)
Section titled “Emit a Boleta (Receipt)”def emit_receipt(): response = requests.post( f"{API_BASE}/api/receipts", headers=headers, json={ "series": "B001", "correlative": 1, "issueDate": "2026-02-20", "currencyCode": "PEN", "customer": { "identityType": "1", "identityNumber": "12345678", "name": "Juan Perez" }, "items": [ { "code": "SRV-002", "description": "Corte de cabello premium", "quantity": 1, "unitCode": "ZZ", "unitPrice": 50.00, "igvType": "10" } ] } )
return response.json()Emit a Nota de Credito (Credit Note)
Section titled “Emit a Nota de Credito (Credit Note)”def emit_credit_note(): response = requests.post( f"{API_BASE}/api/credit-notes", headers=headers, json={ "series": "F001", "correlative": 1, "issueDate": "2026-02-21", "currencyCode": "PEN", "referenceDocumentId": "F001-00000001", "referenceDocumentType": "01", "responseCode": "01", "responseDescription": "Anulacion de la operacion", "customer": { "identityType": "6", "identityNumber": "20100047218", "name": "Empresa Cliente SAC" }, "items": [ { "code": "SRV-001", "description": "Servicio de consultoria (anulacion)", "quantity": 1, "unitCode": "ZZ", "unitPrice": 1000.00, "igvType": "10" } ] } )
return response.json()Emit a Nota de Debito (Debit Note)
Section titled “Emit a Nota de Debito (Debit Note)”def emit_debit_note(): response = requests.post( f"{API_BASE}/api/debit-notes", headers=headers, json={ "series": "F001", "correlative": 1, "issueDate": "2026-02-21", "currencyCode": "PEN", "referenceDocumentId": "F001-00000001", "referenceDocumentType": "01", "responseCode": "01", "responseDescription": "Intereses por mora", "customer": { "identityType": "6", "identityNumber": "20100047218", "name": "Empresa Cliente SAC" }, "items": [ { "code": "INT-001", "description": "Intereses moratorios - Febrero 2026", "quantity": 1, "unitCode": "ZZ", "unitPrice": 150.00, "igvType": "10" } ] } )
return response.json()Send a Comunicacion de Baja (Voided Document)
Section titled “Send a Comunicacion de Baja (Voided Document)”import time
def send_voided_document(): # Step 1: Send the voided document response = requests.post( f"{API_BASE}/api/voided-documents", headers=headers, json={ "issueDate": "2026-02-20", "referenceDate": "2026-02-19", "correlative": 1, "items": [ { "series": "F001", "correlative": 1, "documentType": "01", "reason": "Error en datos del cliente" } ] } )
result = response.json() print(f"Ticket: {result['ticket']}")
# Step 2: Poll for the result final_result = check_ticket(result["id"]) print(f"Final status: {final_result['status']}") return final_result
def check_ticket(document_id, max_attempts=12): for i in range(max_attempts): response = requests.post( f"{API_BASE}/api/documents/{document_id}/check-ticket", headers=headers ) result = response.json()
if result["status"] != "SENT": return result
# Wait 5 seconds before next attempt time.sleep(5)
raise Exception("Ticket check timed out")List documents
Section titled “List documents”def list_documents(page=1, limit=20, doc_type=None, status=None, from_date=None, to_date=None): params = {"page": page, "limit": limit}
if doc_type: params["type"] = doc_type if status: params["status"] = status if from_date: params["from"] = from_date if to_date: params["to"] = to_date
response = requests.get( f"{API_BASE}/api/documents", headers=headers, params=params )
return response.json()
# Usageinvoices = list_documents(doc_type="01", page=1, limit=10)Download PDF
Section titled “Download PDF”def download_pdf(document_id, output_path): response = requests.get( f"{API_BASE}/api/documents/{document_id}/pdf", headers=headers )
with open(output_path, "wb") as f: f.write(response.content)
print(f"PDF saved to {output_path}")
# Usagedownload_pdf("cm3abc123", "./invoice-F001-1.pdf")Retry a failed document
Section titled “Retry a failed document”def retry_document(document_id): response = requests.post( f"{API_BASE}/api/documents/{document_id}/retry", headers=headers )
return response.json()Complete integration example
Section titled “Complete integration example”from datetime import date, timedelta
def emit_invoice_after_payment(payment, customer): """Emit an invoice after a payment is received.""" today = date.today() due_date = today + timedelta(days=30)
response = requests.post( f"{API_BASE}/api/invoices", headers=headers, json={ "series": "F001", "correlative": payment["invoice_number"], "issueDate": today.isoformat(), "dueDate": due_date.isoformat(), "currencyCode": "PEN", "customer": { "identityType": customer["document_type"], "identityNumber": customer["document_number"], "name": customer["name"], "address": customer.get("address", "") }, "items": [ { "code": item["code"], "description": item["name"], "quantity": item["quantity"], "unitCode": "ZZ", "unitPrice": item["price"], "igvType": "10" } for item in payment["items"] ] } )
result = response.json()
if result["status"] == "ACCEPTED": print(f"Invoice accepted: {result['documentId']}") elif result["status"] == "REJECTED": print(f"Invoice rejected: {result['cdrDescription']}") elif result["status"] == "SUNAT_ERROR": print(f"SUNAT error, will retry later: {result['id']}")
return result