Both are irreversible, so both are done in two calls: a PREVIEW that says what would happen and returns a short-lived preview_token, and the action, which the server refuses without that token. Show the preview to a person before acting.
Voiding an accepted invoice
-
POST /v1/invoices/{id}/void/preview(permissioninvoices:void): what would be sent to SUNAT, the last day it can still be voided, and thepreview_token. -
POST /v1/invoices/{id}/void(permissioninvoices:void;Idempotency-Keyrequired) withreasonand thatpreview_token. It answers202: the invoice staysaccepteduntil SUNAT confirms, and only then becomesvoided. -
GET /v1/invoices/{id}/void(permissioninvoices:read): the state of the void, with whether it is final. The eventsinvoice.voided,invoice.void_rejectedandinvoice.void_failedsay how it ended.
It can refuse with: invoice_not_voidable, void_not_available, already_voided, void_in_progress, invoice_externally_reversed, invoice_held, void_window_expired, test_scenario_not_allowed, test_scenario_unknown, preview_token_required, preview_token_invalid.
Past its window an invoice cannot be voided through SUNAT. If it was reversed directly at the provider, because the window passed or because someone did it by hand in the provider’s portal, POST /v1/invoices/{id}/mark_externally_reversed (permission invoices:void; Idempotency-Key required) records that (a note, not a fiscal state). Within the window, the normal path is to void it here with POST /v1/invoices/{id}/void.
| Why a void did not happen | Meaning | What to do |
|---|---|---|
fiscal_rejected |
SUNAT rejected the void. The invoice is still accepted and in force. | Read sunat on the void for SUNAT’s code and text. A new void can be requested once the cause is fixed. |
void_window_expired |
The window to void the invoice passed before the void could be sent (7 days from its issue date). | If it was reversed by hand at the provider, record it with POST /v1/invoices/{id}/mark_externally_reversed. |
test_scenario_expired |
A test void waited 24 hours for a manual resolution and was closed. The invoice is still accepted. | Nothing: it was a test. Request another void and resolve it by hand. |
held_closed_by_staff |
The provider kept giving an answer about the void that the service could not interpret, so the void was held, and a person of the staff of the service closed it as failed after asking the provider for it. The invoice is still accepted. | The event invoice.void_failed carries, in close, the reason the staff wrote. If the invoice must still be voided, request a new void (preview it again) while its window lasts. |
Correcting an invoice that ended failed or rejected
-
GET /v1/invoices/{id}/correction(permissioninvoices:correct): what would be issued now, in the SAME invoice (its number or the next one, and why), and thepreview_token. -
POST /v1/invoices/{id}/correction(permissioninvoices:correct;Idempotency-Keyrequired) with thepreview_tokenand what changes. The same invoice goes back toprocessing; its previous attempt stays in its history.
It can refuse with: invoice_not_correctable, void_in_progress, invoice_held, invoice_type_not_allowed_for_regime, test_scenario_not_allowed, test_scenario_unknown, preview_token_required, preview_token_invalid, correction_proposal_changed, issuer_not_configured.
A token that expired, belongs to another invoice or no longer matches what would be done is refused (preview_token_invalid): ask for the preview again.