Create Replacement Invoice API

Create a replacement invoice for an issued electronic invoice via the SePay eInvoice API. Returns a tracking_code to follow the processing status.

||

What is a replacement invoice?

A replacement invoice is issued when an e-invoice that has already been issued and accepted by the tax authority turns out to need a correction. Once the replacement is issued successfully, the original is flagged replaced and is no longer in force.

Unlike an adjustment invoice, which records only the difference, a replacement carries the full correct content of the new invoice: line items, quantities, unit prices, tax rates and the buyer details.

For example: the original invoice has the wrong product name and unit price on two lines. Instead of issuing several adjustment invoices, you can issue one replacement with the whole content corrected.

Origin invoice requirements

The origin invoice is identified by original_invoice_reference_code (the reference_code of a previously created invoice, under the same provider_account_id).

The origin invoice must:

  • Have been issued successfully and accepted by the tax authority. Draft or in-progress invoices cannot be replaced.
  • Be a new invoice, a replacement invoice or an already-adjusted invoice.
  • Not have been replaced or cancelled.
  • Never have been replaced before. Each origin invoice can be replaced once only.

A replacement invoice can itself be replaced if a mistake is found. An already-adjusted invoice can also be replaced.

How it works in the SePay eInvoice API

POST v1/invoices/replace takes original_invoice_reference_code together with the full content of the new invoice.

The API returns a tracking_code as soon as it accepts the request. Signing and filing the invoice with the tax authority are processed asynchronously. Use the tracking_code with the invoice status tracking API to follow the status and get the final result.

Each origin invoice can be replaced once only. If the replacement itself has a mistake, you adjust or replace that replacement - not the original invoice again.


API Endpoint

POST
https://einvoice-api.sepay.vn/v1/invoices/replace

API Request

provider_account_idstringrequired

Provider account ID (UUID) - must be the account that issued the origin invoice

original_invoice_reference_codestringrequired

Reference code of the issued origin invoice to replace

issued_datestring

Invoice issue date (YYYY-MM-DD HH:mm:ss). Optional - defaults to now. If provided, it must be today.

reference_codestring

Reference code of the replacement invoice, must be unique. Auto-generated as UUID if omitted.

payment_methodenum

Payment method. Optional - when omitted, the origin invoice's payment method is reused (TM/CK when the origin has none either).

  • TM: Cash
  • CK: Bank transfer
  • TM/CK: Cash and bank transfer
  • KHAC: Other
is_draftbooleanrequired

Must be a real boolean (true/false):

  • true: Create as draft (issue later via the issue invoice API)
  • false: Create and issue immediately
buyerobjectrequired
itemsarray<object>required

List of goods/services

notesstring

Invoice notes, max 255 characters

total_amountinteger

Final total payable amount of the invoice (tax included). Optional. If provided, it must be an integer (no decimals).

  • Omitted: the system computes it from the line items and rounds to a whole number.
  • Provided: the system uses your value exactly as-is and performs NO validation against the line items.

Warning (when provided): You are solely responsible for this value. If it does not match the goods subtotal + tax, the invoice will display an incorrect total and the tax authority may reject it.

API Response

Success Response (202)
{
  "success": true,
  "data": {
    "tracking_code": "3f8b1c2a-7d95-11f1-aef4-52c7e9b4f41b",
    "tracking_url": "https://einvoice-api.sepay.vn/v1/invoices/replace/check/3f8b1c2a-7d95-11f1-aef4-52c7e9b4f41b",
    "message": "Đã tạo yêu cầu xuất hóa đơn thay thế"
  }
}
successboolean
dataobject

Error Handling

400Bad Request

Missing or invalid required fields (VALIDATION_ERROR).

401Unauthorized

Missing or invalid Bearer token, or token expired (TOKEN_EXPIRED).

400INVALID_IS_DRAFT_TYPE

is_draft must be a real boolean (true/false), not a string.

400ISSUED_DATE_INVALID

issued_date is not today's date.

400INVALID_ISSUED_DATE

issued_date does not match the Y-m-d H:i:s format.

422INVALID_ORIGIN_INVOICE

The origin invoice is not eligible: not issued yet, already replaced/cancelled, or already has another replacement (including drafts).

422REGISTRATION_NOT_TAX_APPROVED

Business has not registered eInvoicing or the tax authority has not approved the filing (production only).

422INVOICE_DATE_BEFORE_TAX_APPROVAL

Invoice date is before the tax authority approval date (production only).

409EINVOICE_DOCUMENT_EXISTED

An invoice already exists for this reference_code. reference_code must be unique.

500EINVOICE_ACCOUNT_NOT_FOUND

No eInvoice provider account found for the given provider_account_id.

500QUOTA_HAS_BEEN_USERD_UP

The plan's invoice quota is used up. Top up the quota before calling again - do not auto-retry, this error does not clear by itself.

500REGISTRATION_NOT_COMPLETE

The company has not completed its eInvoice plan registration.

500BILLING_IS_UNPAID

The company has not paid for its eInvoice plan.

500Internal Server Error

System error while processing the request.

Usage Notes

  • items uses the same parameters as the create invoice API - it contains the full corrected content of the invoice, NOT the difference. The invoice total cannot be negative.
  • Goods/services and promotional lines (line_type = 1, 2) require item_code, unit and a quantity greater than 0.
  • buyer is required - a replacement re-states the whole invoice, including buyer information.
  • payment_method is optional - when omitted, the origin invoice's payment method is reused.
  • issued_date is optional and must always be today (defaults to the API call time).
  • is_draft=true creates a draft replacement invoice - issue it later via the issue invoice API using the draft's reference_code. is_draft=false creates and issues immediately.
  • After a successful request, use tracking_url to call the invoice status tracking API - always poll until a terminal result (success or failure).

Sample Code

>
>
>
>
>
curl --request POST \
--url https://einvoice-api.sepay.vn/v1/invoices/replace \
--header 'Authorization: Bearer REPLACE_BEARER_TOKEN' \
--header 'content-type: application/json' \
--data '{"provider_account_id":"0aea3134-da40-11f0-aef4-52c7e9b4f41b","original_invoice_reference_code":"084e179d-d95a-11f0-aef4-52c7e9b4f41b","issued_date":"2026-07-30 00:00:00","reference_code":"3f8b1c2a-7d95-11f1-aef4-52c7e9b4f41b","payment_method":"CK","is_draft":false,"buyer":{"type":"personal","name":"Công ty TNHH ABC","legal_name":"CÔNG TY CỔ PHẦN ABC","tax_code":"0123456789","address":"123 Đường ABC, Quận 1, TP.HCM","email":"contact@abc.com","phone":"0901234567","buyer_code":"KH-001","national_id":"001234567890"},"items":[{"line_number":1,"line_type":1,"item_code":"SP001","item_name":"Sản phẩm A","unit":"cái","quantity":10,"unit_price":100000,"tax_rate":10,"discount_tax":10,"discount_amount":100000,"before_discount_and_tax_amount":4500000}],"notes":"Thay thế cho hóa đơn ký hiệu C26TSE số 589 ngày 26/01/2026","total_amount":4950000}'

Sample Parameters

Basic replacement invoice

json
{
    "provider_account_id": "{{your-provider-account-id}}",
    "original_invoice_reference_code": "084e179d-d95a-11f0-aef4-52c7e9b4f41b",
    "buyer": {
        "type": "company",
        "name": "Công ty ABC",
        "legal_name": "CÔNG TY TNHH ABC",
        "tax_code": "0101234567",
        "address": "123 Đường A, Quận B, Hà Nội",
        "email": "buyer@example.com"
    },
    "items": [
        {
            "line_number": 1,
            "line_type": 1,
            "item_code": "SP001",
            "item_name": "Sản phẩm A",
            "unit": "cái",
            "quantity": 2,
            "unit_price": 4500000,
            "tax_rate": 10
        }
    ],
    "notes": "Thay thế cho hóa đơn ký hiệu C26TSE số 589 ngày 26/01/2026",
    "payment_method": "CK",
    "is_draft": false
}

Replacement invoice with a discount and a trade discount line

json
{
    "provider_account_id": "{{your-provider-account-id}}",
    "original_invoice_reference_code": "084e179d-d95a-11f0-aef4-52c7e9b4f41b",
    "reference_code": "replacement-invoice-001",
    "buyer": {
        "type": "personal",
        "name": "Nguyễn Văn A",
        "address": "Số 88 Đường Ánh Sao, Phường Bình An, Quận 9, TP Hồ Chí Minh",
        "email": "buyeremaildemo@gmail.com"
    },
    "items": [
        {
            "line_number": 1,
            "line_type": 1,
            "item_code": "SP001",
            "item_name": "Sản phẩm A",
            "unit": "cái",
            "quantity": 10,
            "unit_price": 100000,
            "discount_tax": 10,
            "tax_rate": 10
        },
        {
            "line_number": 2,
            "line_type": 3,
            "item_name": "Chiết khấu thương mại",
            "before_discount_and_tax_amount": 50000,
            "tax_rate": 10
        }
    ],
    "notes": "Thay thế cho hóa đơn ký hiệu C26TSE số 589 ngày 26/01/2026",
    "payment_method": "TM/CK",
    "is_draft": true
}

Next Steps

After a successful request returning a tracking_code:

  1. Track invoice status - Use the tracking_code to check the processing result (required)
After a successful status
  • If created as a draft (is_draft=true): continue with the issue invoice API to issue officially
  • If created officially (is_draft=false): you can download the invoice or view its details - the replacement invoice has document_type=4, and the origin becomes document_type=5 (replaced)