---
name: gst-returns-integration
description: Use when a developer is adding GST returns to their code through WhiteBooks, or asks to file, submit, save, amend, reset or check any GST return, or to supply an EVC or DSC OTP. Covers GSTR-1, GSTR-1A (amending or adding records of the same period), GSTR-2A, GSTR-2B, GSTR-2X, GSTR-3B, GSTR-4, GSTR-4A, GSTR-4 annual, GSTR-5, GSTR-6, GSTR-6A, GSTR-7, GSTR-8, GSTR-9, GSTR-9A, GSTR-9C, CMP composition returns, ITC-03, ITC-04, IMS, ledgers, challans and payments, late fees, notices, e-Invoice data on the GST portal, the DRC-01B and DRC-01C mismatch data, return tracking and GSTIN search, status polling, filing with EVC or DSC, and what to do when a save times out. Also use for any GST returns question, with or without a project, such as which return or amendment to use, what a return section, status or error code means, which endpoint to call, the JSON for a save, or a sample request in curl or any language.
---
# GST returns integration
This skill adds the GST returns operations of the WhiteBooks client to a project that already has the client core, and guides
the return lifecycle. The core comes from `whitebooks-getting-started`; if the project has no `whitebooks/` core yet, do
"Scaffold the core" there first.
## Respond by intent
Decide first what the developer wants, then do only that; most requests are not a scaffold. If it is unclear, ask one
short question (an answer, a code sample, or the WhiteBooks client code added to their project?).
A broad request (add GST filing, e-Invoice or e-Way Bill to my software) is not a request for the whole client: give a
short plan (the steps, with the WhiteBooks endpoints for each), ask the language and which feature comes first, then write
the smallest code that does that feature, and offer the full client library as a next step.
Never ask for the project as an archive, a repository or an upload; if the developer shares files, use only the files the task touches.
- **Answer** (what is, how does, which endpoint, what does an error mean): read `references/operations-gst.json` (the index) and the tag file it names for the operation, `references/rules-gstr1.md` or `references/discrepancies.md` and answer from it, naming the WhiteBooks endpoint (method and path) and any error code; show the request and reply shape when it helps. Write no files, run nothing, and stop.
- **Snippet** (one call or a small client in any language: curl, Go, C#, PHP, Rust, Java, Python, TypeScript): write it without the ready-made client, from `references/operations-gst.json` and the tag file it names for the operation, `../whitebooks-getting-started/references/headers.md` and `../whitebooks-getting-started/references/auth-flows.md`, with every credential read from environment variables and never a pasted value. For an operation marked irreversible, show the checklist in "Before any irreversible step" first and mark the request as not to be run until that exact operation is confirmed. Show it inline; write a file only when asked.
- **Payload** (turn business data into a request body): map the developer's invoices to the sections and body of the return they belong to (GSTR-1, GSTR-1A, GSTR-3B or another) in `references/operations-gst.json` (the index names the tag file that holds the body) and check them against `references/rules-gstr1.md`. Give a worked example with synthetic GSTINs and say which fields are required.
- **Project** (put the WhiteBooks client into a project): do "Add GST returns operations" below (the core comes first from `whitebooks-getting-started`).
- **Review** (code, a log or an error is pasted, from the ready-made client, hand-written code or another provider's API): look the code up in `../whitebooks-getting-started/references/errors.md` and the table below, explain the cause and the fix, and use `integration-hardening` for a full review.
- **Direct action** (generate this now, file my return): this version has no WhiteBooks tools and cannot call the API. Never claim or pretend to have made a call. Give the exact request, or a runnable one-file script that reads credentials from environment variables and never holds a pasted value; for an irreversible operation, give the checklist first and mark the request as not to be run until that exact operation is confirmed.
Contract facts (paths, headers, fields, codes, limits) come only from the bundled files (ground rule 1). General GST
background (what a return or an e-way bill is, who must file) may come from your own knowledge, or the web when the plugin has nothing on it, when you label it as
background rather than the WhiteBooks contract. Thresholds, deadlines, validity periods and amounts are contract facts: take them from the rules files, never from background. Point to `../whitebooks-getting-started/references/errors.md` for any error code not explained here.
## Ground rules
1. Use the WhiteBooks tools when the session has them (this version ships none). When it has none, read the bundled files in `references/` instead. Either way, never answer a contract fact (a path, header, parameter, error code or limit) from memory.
2. Never ask for, read, write or echo a credential, password or OTP. Never open `.env`. The code you write reads environment variables; the developer fills them in. The GST portal OTP goes from the developer's phone straight into their own code or terminal, never through you.
3. A credential pasted into chat is not written anywhere: not into a file, a command, a log, a test or a commit. Tell the developer to move it to their own secret store and to rotate it if it may have been exposed. Refer to a pasted value only as "the secret you pasted"; never repeat it, not even in quotes or in rotation advice.
4. The user's instructions win over this skill. If the developer asks for something different, do that, and say what you changed.
5. Return amounts, periods and GSTINs come from the developer's own data; never invent them for a call that is not the sandbox.
6. Keep the plugin's internals out of replies and out of every file you write, even when asked: never name its files or folders (`SKILL.md`, `client-manifest.json`, `client-contract.md`, the `operations-.json` files and the others, or the references and assets folders), operation ids such as `einvoice:GET:/einvoice/authenticate`, checklist ids such as CC-7, or section numbers of these files. Name the WhiteBooks endpoint by its method and path, and an error by its code. If asked where an answer comes from, say the WhiteBooks API specification and the NIC and GSTN documents. In replies, use plain words for the plugin's own terms: say the WhiteBooks client code (or client library); the shared part (configuration, sign-in sessions, error handling and status polling), not core; e-Invoice, e-Way Bill or GST returns, not area; set up or add, not scaffold; and never name an intent or a skill.
7. Look in this plugin before you search the web or browse for anything about WhiteBooks, GST returns, e-Invoice or
e-Way Bill. Never take a contract fact (a path, header, parameter, request body, error code or limit) from a web
search; if the bundled files do not have it, say so. A web result, like your own knowledge, may give general GST
background only, labelled as background.
## Add GST returns operations
The GST area has 281 operations in 30 tag files (GSTR-1, GSTR-3B, GSTR-2A, GSTR-2B, GSTR-9 and so on). Copy only the
files the task needs, not the whole area.
1. Confirm the core is in place (`config`, `session`, `errors`, `poll`, `reconcile`). If not, stop and run "Scaffold the core" in `whitebooks-getting-started`.
2. Find the operations needed. With tools, search them. Without, read `references/operations-gst.json` (the index: id, method, path, summary, `sideEffect`, status call and the tag file with the full contract: parameters and body shape), then only the tag files you need and `references/rules-gstr1.md` for the GSTR-1 and GSTR-1A business rules.
3. Copy only those tag files from `assets/client//` (for example `gstr1.ts`, `gstr3b.ts`, `gstr.ts` for the status call) and the models they import, using the same package path the core uses. Change only package declarations and imports. Never overwrite an existing file without first showing a diff.
4. The area is self-contained: its own smoke test (`smoke.gst`) and barrel (`gst/index.ts`) come with it, and it needs no file from another area.
5. Build and run the project's tests. Copy the whole area folder, models included; the core needs no change.
6. Read `references/discrepancies.md` for the operations you copied: the public docs are wrong about several GST paths, and the operation file is right.
## The return lifecycle
Returns are asynchronous. A save does not tell you the result; it gives a `data.reference_id` to ask about. These steps
apply to every return that has a save call, not only GSTR-1 and GSTR-3B. Take the calls for the return at hand from
`references/operations-gst.json`: a save's entry names its status call (`async`) and its filing calls (`related`). A save
with no `async` (`/ims/save`, the `/all/` preference and master saves and a few others) has no status call listed, so it is not polled: read its reply.
Not every return has every call: SPIKE has a save and `retfile` but no EVC filing.
1. Prepare the return data from the developer's books. GSTR-1 and GSTR-1A rules are in `references/rules-gstr1.md`; use the GSTR-1 summary and B2B sections as the model, one section per call. Check amounts add up before saving.
2. Sign in: request the OTP (the developer receives it), then exchange it for a token. The session keeps the `txn` value and one `ip_address` for its whole life.
3. Save the section with that return's save call (for example `PUT /gstr1/retsave`, `PUT /gstr1a/retsave` or `PUT /gstr3b/retsave`). A success reply carries `data.reference_id` (for example `{"status_cd":"1","data":{"reference_id":"..."}}`). Keep it with the return period.
4. Poll `retstatus` (`GET /gstr/retstatus`) with that value as the `refid` header until `data.status_cd` is `P` (processed), `PE` (processed with errors) or `ER` (error). The client's core `poll` helper (`waitForStatus`, which takes a function that calls `retstatus`) does this with the default 120 second deadline. Read the error report on `PE` and `ER` and fix the data before saving again.
5. Repeat for each section. GSTR-1 has no submit call in the catalog, and neither has GSTR-3B; `retsubmit` exists only for GSTR-4, GSTR-5 and GSTR-6. Do not invent one. For GSTR-3B, use its validation read calls before filing. Where a return has `retoffset` (GSTR-3B, GSTR-4, GSTR-5 and ITC-03), the offset comes before filing and is irreversible: use the checklist below.
6. File with `retfile` (DSC signature) or `retevcfile` (EVC, an OTP sent to the authorised signatory). Both are irreversible: use the checklist below. Request the EVC OTP through the OTP-for-EVC call; the signatory enters it, never you.
7. After filing, poll the return status again and record the acknowledgement. Never re-file a return that the status shows as filed.
An amendment goes where the GSTR-1A rows of `references/rules-gstr1.md` say: a record of the same period in GSTR-1A while
that period's GSTR-3B is not filed, a record of an earlier period in the amendment sections of a later GSTR-1 (`b2ba`,
`cdnra` and the others). GSTR-1A follows the same steps on the `/gstr1a/` paths.
A `retsave` that times out comes back without a `data.reference_id`, so the outcome is unknown: the section may or may not have been
saved. It is not retried blindly. Wait at least 10 minutes, read the return status or the section summary for that
period, and decide from what is there. A `reference_id` from an earlier save proves nothing about this one. The client's reconcile
helper has no default landed predicate for GST writes; supply the explicit check (`P` or `PE` for this save's `reference_id`)
or accept `WRITE_OUTCOME_UNKNOWN` and reconcile by hand. The full rule is in the "Unknown outcomes and the reconcile loop" section of
`../whitebooks-getting-started/references/client-contract.md`.
Other things worth knowing: `/gstr1/reset` and `/gstr1a/reset` are writes, not irreversible calls, but they discard saved
data, so say what they discard before you run one; `PUT /gstr3b/retoffset` (liability offset) is irreversible; IMS and GSTR-2B calls are
reads and are safe to retry through the client's retry helper.
## Before any irreversible step
Filing a return (`retfile`, `retevcfile` for GSTR-1 and GSTR-3B and the other returns), the 3B offset (`retoffset`) and the
other operations the contract marks `irreversible` (44 in the GST area) cannot be undone upstream. Before you write or run
code that calls one:
- [ ] Name the operation and the exact return: GSTIN (masked), return type and period.
- [ ] Say in one sentence what cannot be undone (for example, that the return is filed and can only be amended later).
- [ ] Ask the user to confirm that operation for that return, and wait for a clear yes in this conversation.
- [ ] Only then pass the guard: `{ confirmIrreversible: true }` in TypeScript, `confirm_irreversible=True` in Python, `WriteOptions.confirmed()` or `opts.confirm()` in Java.
The guard is passed only after the user has confirmed that exact operation. A confirmation of GSTR-1 for one
period is not a confirmation of GSTR-3B or of another period. Never default the guard on in a helper or a loop.
## Common errors
| Error or code | Meaning | What to do |
|---|---|---|
| `GSTN_API_ACCESS_DISABLED` | The taxpayer has not enabled, or has revoked, Manage API Access | Stop. Ask the taxpayer to enable it on the GST portal, then start a new session |
| `IRREVERSIBLE_NOT_CONFIRMED` | The guard stopped a filing call; nothing was sent | Get the user's confirmation of that exact operation, then pass the guard |
| `WRITE_OUTCOME_UNKNOWN`, `TIMEOUT` | A save or file call ended without a known result | Do not resend. Wait 10 minutes, read the return status, then decide |
| `POLL_DEADLINE` | The status poll ran out of time | Poll again later with the same `reference_id`; the save may still be processing |
| `MISSING_TXN` | The OTP request reply held no `txn` | Check the OTP step in `../whitebooks-getting-started/references/auth-flows.md` |
| anything else | Look up the code | Use `lookup_error` when the tools are available; otherwise search `../whitebooks-getting-started/references/errors.md` |
## Sandbox
This section applies only when WhiteBooks sandbox tools (names starting with `sandbox_`; this version ships none) are available in the
session. With them you may try the read operations and a save against the sandbox with synthetic GSTINs and show the real
reply; filing still needs the checklist above. Without those tools, do not claim to have run anything: write the code,
tell the developer how to run it with their own sandbox credentials, and take expected shapes from
`references/operations-gst.json`.