codewithkarani

KRA eTIMS from ERPNext: what OSCU and VSCU actually send, and the failures to plan for

Karani GeoffreyKarani Geoffrey13 min read
On this page
  1. OSCU and VSCU in plain terms
  2. The order KRA expects things in
  3. Initialisation: one call, one key
  4. What a sales invoice actually sends
  5. What comes back, and what goes on the receipt
  6. How an ERPNext app wires this up
  7. Failure states to plan for
  8. Where the documents disagree
  9. Summary for business owners
  10. Sources

If your business runs on ERPNext and is registered for VAT in Kenya, every sales invoice now has a second life outside your system. Before a customer gets a valid tax invoice, ERPNext has to send that sale to KRA's eTIMS servers and get back a signature, a receipt number and a QR code. When that round trip works, nobody notices. When it fails, you can end up with invoices in ERPNext that KRA has never seen, or a receipt printed without the KRA details it is supposed to carry.

This article walks through what travels between ERPNext and KRA, in the order KRA expects it, and the failures to plan for before go-live. It is built from KRA's published specifications and the source of two open-source Frappe apps, so you can check every claim.

eTIMS system-to-system integration is a fixed sequence: initialise a device once to get a communication key (cmcKey), download KRA's code lists, register each item, then send each sale to /saveTrnsSalesOsdc and store the signature KRA returns. Plan for KRA being unreachable, for not knowing whether a timed-out sale was recorded, for gaps in invoice numbers, for codes that do not match KRA's lists, and for corrections, which go through credit notes.

OSCU and VSCU in plain terms

KRA offers two system-to-system routes, both documented in version 2.0 specifications dated April 2023, still the versions KRA links today.

  • OSCU (Online Sales Control Unit) is hosted by KRA. Your system calls KRA's API directly over HTTPS with JSON. The specification says plainly that "Internet is always needed". KRA's integration page describes it as "suitable for taxpayers whose invoicing is always online."
  • VSCU (Virtual Sales Control Unit) is a Java JAR you run on your own server. Your system talks to it on your network, by default on port 8088, and it talks to KRA. KRA describes it as "suitable for taxpayers undertaking bulk invoicing and is not always online." The sign-up guide says it needs Java 16 or higher.

The functions are the same eight groups in both: initialisation, code data, branch information, items, imported items, sales, purchases and stock. The URL paths differ. OSCU uses paths such as /saveTrnsSalesOsdc; the VSCU specification lists paths such as /trnsSales/saveSales.

The order KRA expects things in

KRA's step-by-step guide says the actions in its table "are ordered sequentially meaning that latter actions are dependent on some of the preceding actions." In practice that gives you this chain:

The order of eTIMS OSCU calls from an ERPNext site Six steps in order: initialise, code lists, items, sale, stock moves, stock level, each with the KRA result codes that signal a missing or failed step. Once per branch Master data Every transaction 1. Initialise selectInitOsdcInfo returns cmcKey 2. Code lists selectCodeList selectItemClsList 3. Items saveItem one per item code 4. Sale saveTrnsSalesOsdc returns rcptSign 5. Stock moves insertStockIO after the sale 6. Stock level saveStockMaster after stock moves Result codes that point at each stage 900, 901, 902 no header, invalid device, installed 910 Request parameter error: a code or field KRA does not accept 921, 922, 994 declared data cannot be received, invoice before sale, overlapped data
The OSCU call chain from ERPNext, with the result codes from section 4.18 of KRA's OSCU specification v2.0 that point at each stage.

The specification is explicit about stock: every stock in/out record "must have its sales Invoice information sent in advance", and every stock master update "must have its stock in/out information sent in advance".

Initialisation: one call, one key

First the taxpayer applies for OSCU or VSCU on the sandbox portal (etims-sbx.kra.go.ke) and waits for approval. Then your system calls /selectInitOsdcInfo with three fields: the KRA PIN (tin, 11 characters), the branch ID (bhfId, 2 characters, "00" for head office) and the device serial number (dvcSrlNo). The response carries taxpayer and branch details, the control unit ID (sdcId), the mrcNo, and the communication key, cmcKey.

The spec lists cmcKey as required on later requests; the Navari app described below sends it as an HTTP header with tin and bhfId. It is the credential for everything that follows, and Navari also stores it in each Integration Request log, which in Frappe 16.23.0 only System Managers can read by default. Keep it that way.

The OSCU base URLs in the specification are:

# OSCU API server, from section 1.2 of the OSCU specification v2.0
https://etims-api-sbx.kra.go.ke/etims-api/   # test (sandbox)
https://etims-api.kra.go.ke/etims-api/       # production

What a sales invoice actually sends

The sale goes to /saveTrnsSalesOsdc as one JSON object: a header, a receipt object and an itemList. Here is an abridged view of what the Navari app builds (build_invoice_payload in utils.py), with each value replaced by the ERPNext field it comes from:

{
  "invcNo": "trailing number of the Sales Invoice name",
  "orgInvcNo": "0 for a sale; the original's sequence number for a return",
  "trdInvcNo": "Sales Invoice name",
  "custTin": "customer tax_id, or null",
  "rcptTyCd": "S for a sale, R for a credit note",
  "pmtTyCd": "payment type code",
  "cfmDt": "posting date and time, yyyyMMddhhmmss",
  "salesDt": "posting date, yyyyMMdd",
  "taxblAmtA ... taxblAmtE": "taxable amount per tax band",
  "taxRtA ... taxRtE": "rate per band",
  "taxAmtA ... taxAmtE": "tax per band",
  "totTaxblAmt": "base_net_total",
  "totTaxAmt": "total_taxes_and_charges",
  "totAmt": "grand_total",
  "receipt": { "custTin": "...", "rcptPbctDt": "same as cfmDt" },
  "itemList": [
    {
      "itemSeq": "row idx",
      "itemCd": "eTIMS item code registered with saveItem",
      "itemClsCd": "KRA item classification code",
      "qty": "abs(qty)",
      "prc": "base_rate",
      "taxTyCd": "A, B, C, D or E",
      "taxblAmt": "net_amount",
      "taxAmt": "item tax amount"
    }
  ]
}

The tax bands come from section 4.1 of the specification: A is exempt, B is 16%, C is 0%, D is non-VAT and E is 8%. Three produce zero tax, so the band matters for reporting, not just arithmetic. The item code (itemCd) also has a defined structure in section 4.19: country of origin, product type, packaging unit, quantity unit, then a running number, as in the spec's example KE2NTBA0000012.

What comes back, and what goes on the receipt

A successful response has resultCd "000" and a data object with five values: curRcptNo (current receipt number), totRcptNo (total receipt number), intrlData (internal data, 26 characters), rcptSign (receipt signature, 16 characters) and sdcDateTime. Store all five against the invoice.

KRA's separate Technical Specification for the Trader Invoicing System (TIS) says what the printed receipt must carry: an "SCU Information" block with the control unit date and time, the CU ID, a CU invoice number made of the CU ID and receipt number (the example is KRACU04XXXXXXXX/1), the internal data and receipt signature split by a dash every four characters, and a QR code. Two rules in that document shape your print format:

  • Rule 10: "it shall be impossible to issue receipt if the TIS did not receive any response from the OSCU/VSCU."
  • Rule 6.17: print only one original; reprints carry a "Copy" watermark.

So your print format should refuse to render a tax invoice while the signature fields are empty.

How an ERPNext app wires this up

Navari's open-source kenya_compliance app (AGPL-3.0) is a worked example. Notes from its develop branch at commit 5e8d0b1 (16 October 2025).

  • Device setup: the settings DocType calls /selectInitOsdcInfo in before_insert and stores cmcKey and sdcId on the record.
  • Sending a sale: hooks.py registers on_submit for Sales Invoice. It builds the payload and puts the HTTP call on a background queue with frappe.enqueue (300-second job timeout). Submitting in ERPNext therefore never waits for KRA; the signature arrives later.
  • Logging: every call creates an Integration Request record, marked Completed or Failed.
  • Result: on success it writes the five response values and a QR code onto the invoice and sets custom_successfully_submitted; on a KRA error it logs resultCd and resultMsg to the Error Log.
  • Retry: an hourly scheduler job, send_sales_invoices_information, finds submitted invoices that are not yet marked successful and runs the same submit logic again. Code lists and item classifications refresh monthly; notices refresh hourly.
  • Cancellation: before_cancel blocks cancelling an invoice that eTIMS has accepted and tells the user to raise a credit note.

Because the retry depends on the Frappe scheduler, a stopped scheduler means unsent invoices simply stay unsent. If that sounds familiar, the scheduled jobs checklist covers how to check it. For how this fits alongside stock, serials and M-Pesa on a single retail submit, see the submit chain behind ERPNext retail.

A second app, kenya_etims_compliance (MIT, commit 9508b8a, 24 September 2026), is stricter. It builds the payload in before_submit, holds the invoice back with a recorded reason if a line lacks its eTIMS codes or the totals contradict the lines, and queues the rest. Retries run every five minutes, backing off up to 30 minutes, three attempts by default. Once KRA has accepted a submission it is never sent again; a missing signature is repaired from the stored response.

Failure states to plan for

1. KRA is unreachable

OSCU needs a live connection for every signature. The TIS specification requires the invoicing system to "independently detect whether the OSCU/VSCU is operational or not, and inform user of its status" (rule 6.8) and to issue receipts only when connected (rule 6.7). VSCU buys you time but not forever: its specification says that if there is no internet connection for 24 hours after it issues a receipt signature, "VSCU stops issuing a receipt number."

Decide up front what your till does while eTIMS is down. Both apps above queue the sale; make that queue visible to someone whose job it is to watch it.

2. The request timed out, so did KRA record it?

A timeout tells you nothing about whether the sale reached KRA. The result codes include 994 ("There is an overlapped Data") and 921 ("Sales or sales invoice data which is declared cannot be received"), but the v2.0 documents do not say which one a resent invcNo produces. Test it in the sandbox before deciding how your retry treats it. Check your timeouts too: in the Navari code the HTTP timeout is 1,800 seconds but the background job timeout is 300, so the job runner kills a hung call before the app's own error handling runs. The M-Pesa idempotency article covers the same "did it go through?" problem for payments.

3. Gaps in invoice numbers

TIS rule 6.3 requires "consecutive numbers" per receipt type, and after a total reset numbering must "recommence from the next number in the sequence as retrieved from the last transmitted invoice." The VSCU initialisation response includes lastSaleInvcNo and lastInvcNo for exactly this.

Navari takes invcNo from the trailing number of the Sales Invoice name (its example is eTIMS-INV-00-00001), which ties the eTIMS sequence to ERPNext's naming series. Frappe assigns that number when a draft is first saved, and only rolls the counter back when the deleted document was the newest (revert_series_if_last in frappe/model/naming.py). Deleting an older draft leaves a gap. Use a dedicated series per branch and do not let staff delete eTIMS drafts.

4. Device and branch problems

Codes 900 ("There is no Header information"), 901 ("It is not valid device"), 902 ("This device is installed") and 903 ("Only OSCU device can be verified.") mean the setup is wrong, not the invoice, so retrying will not help. Navari's build_headers also raises an error for any branch ID other than "00" or "01"; check that before adding a third branch.

5. Codes that do not match KRA's lists

Classification, packaging unit, quantity unit, country, payment type and tax type codes all come from /selectCodeList and /selectItemClsList, which return only changes after lastReqDt. Section 2.2 says to move that date only "once successfully retrieved"; Navari's error handler also moves it after a failed request, which can skip changes. And do not copy rates from the spec's sample JSON: the samples show band B at 18% while the code table says 16%. Read rates from the code list.

6. Corrections go through credit notes

You do not cancel a signed invoice in ERPNext; Navari blocks it. TIS rule 6.16 says each correction must refer to the original SCU receipt number, and an original may be cancelled only once. On the wire, a credit note is a sale with rcptTyCd "R" and orgInvcNo set to the original. The spec defines reason codes for rfdRsnCd: 01 Missing Quantity, 02 Missing data, 03 Damaged, 04 Wasted, 05 Raw Material Shortage, 06 Refund. Navari reads the original's stored sequence number through return_against, so the original must have been accepted first.

7. Sandbox settings left in production

In Navari's success handler at that commit, the QR link uses the sandbox host etims-sbx.kra.go.ke whatever the environment. Search your code for sbx before go-live. KRA's own documents differ on the QR: the TIS text describes date, time, CU number, receipt number, internal data and signature joined by #, while its sample receipt shows an etims.kra.go.ke link built from PIN, branch ID and signature. Confirm which KRA expects.

8. Invoices that never qualify for sending

Navari's on_submit sends only when update_stock is 1, the invoice is not deferred and it is not an opening entry. The form script sets update_stock, but an invoice created by API or import with it off fails the check, and the hourly retry and bulk action call the same function, so it is never sent. Run a weekly report of submitted invoices with no receipt signature.

Where the documents disagree

The OSCU sales table labels itemClsCd "Item Code" and itemCd "Item Classification Code", and names the line tax field totTaxAmt where the sample uses taxAmt. The VSCU spec shows both /selectInitInfo and /initializer/selectInitInfo, and the sign-up guide's OSCU example drops /etims-api from the base URL. When the documents disagree, the sandbox decides. The earlier eTIMS survival guide covers an outbox design for the same API outside ERPNext.

Summary for business owners

eTIMS is a fixed sequence: register your device, load KRA's lists, register your products, then send each sale and keep the signature KRA returns. What goes wrong is predictable: KRA offline, not knowing if a sale went through, numbering gaps, unrecognised product codes, and corrections that need a credit note. Before go-live, ask whoever runs your ERPNext to show you three things: where unsent invoices appear, who is told when they pile up, and a test credit note that KRA has accepted.

Sources

Frequently asked questions

What is the difference between OSCU and VSCU for KRA eTIMS?
OSCU (Online Sales Control Unit) is hosted by KRA and your system calls KRA's API directly, so it needs an internet connection for every invoice. VSCU (Virtual Sales Control Unit) is a Java JAR you run on your own server, by default on port 8088, which talks to KRA for you. KRA describes OSCU as suited to invoicing that is always online and VSCU as suited to bulk invoicing that is not always online. VSCU's specification says it stops issuing receipt numbers if it has had no internet connection for 24 hours after issuing a receipt signature.
What does KRA return when an ERPNext sales invoice is accepted by eTIMS?
A successful call to /saveTrnsSalesOsdc returns resultCd "000" and five values: curRcptNo (current receipt number), totRcptNo (total receipt number), intrlData (internal data), rcptSign (receipt signature) and sdcDateTime (the control unit's date and time). These must be stored against the invoice and printed in the receipt's SCU Information block, together with a QR code.
Can I cancel a Sales Invoice in ERPNext after it has been sent to eTIMS?
No. Once KRA has accepted the invoice, corrections go through a credit note: a return Sales Invoice sent with rcptTyCd "R" and orgInvcNo pointing at the original invoice number. KRA's TIS specification says a correction must refer to the original receipt number and an original may be cancelled only once. The Navari kenya_compliance app blocks cancelling an accepted invoice for this reason.
Why do eTIMS invoice numbers need to be gapless in ERPNext?
KRA's TIS specification requires consecutive receipt numbers per receipt type, and after a reset numbering must continue from the last transmitted invoice. If an integration takes invcNo from the ERPNext naming series, deleting an older draft leaves a gap, because Frappe only rolls the series counter back when the deleted document was the newest. A dedicated naming series per branch, and no deleting of eTIMS drafts, avoids this.
Which eTIMS result codes mean my device setup is wrong rather than the invoice?
In KRA's OSCU specification v2.0, code 900 means there is no header information, 901 means the device is not valid, 902 means the device is already installed and 903 means only an OSCU device can be verified. These point at initialisation or the tin, bhfId and cmcKey sent with each request, so retrying the same invoice will not fix them.
#KRA eTIMS#OSCU#VSCU#ERPNext#Kenya tax compliance#Sales Invoice

Written by

Karani Geoffrey

Software engineer in Nairobi and founder of Upeosoft. I build ERPNext, AI and web systems that businesses run on, and write down what I learn along the way. More about me

Keep reading