> For the complete documentation index, see [llms.txt](https://kb.logicerp.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kb.logicerp.com/logic-erp-learning-hub-tutorials-and-best-practices/api-documentation/sale/push/cancel-a-sale-challan-return.md).

# Cancel a Sale Challan Return

Cancels a **sale challan return** (goods taken back against delivery challans) that is already saved in Logic ERP. The return is not removed: it stays **marked as cancelled**, its number stays used, and what it had put in place is **reversed** — the returned goods are taken **out of stock** again, and challan lines it had returned are open again. You point to the return by its **series and number**, by your **party order number**, or by Logic ERP's internal number. A cancel cannot be undone.

### **Endpoint**

| Name          | Detail                                            |
| ------------- | ------------------------------------------------- |
| Address       | `https://your-server/api/CancelSaleChallanReturn` |
| Method        | `POST`                                            |
| Authorization | Basic Auth                                        |

The response and the common messages are explained in [How Every API Call Works](https://kb.logicerp.com/logic-erp-learning-hub-tutorials-and-best-practices/api-documentation/how-every-api-call-works.md).

This endpoint has its own licence. It works like [Cancel a Sale Challan](https://kb.logicerp.com/logic-erp-learning-hub-tutorials-and-best-practices/api-documentation/sale/push/cancel-a-sale-challan.md); the differences are the series it accepts and the direction of the stock. Send one return per request. Field names are matched without regard to upper/lower case; fields not listed below are ignored.

### **Request fields**

| Field           | Type   | Required              | Default | Meaning                                                                                                                                                                                                                                             |
| --------------- | ------ | --------------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Branch_Code`   | number | **Yes** (in practice) | `0`     | The branch the return belongs to (`Branch_Code` in [Get Branch Info](https://kb.logicerp.com/logic-erp-learning-hub-tutorials-and-best-practices/api-documentation/masters/pull/get-branch-info.md)). The return is looked for in this branch only. |
| `DocCode`       | number | One of the three ways | `0`     | Logic ERP's internal number of the return – the `LastSavedCode` you received when you saved it. When it is above `0`, `BillSeries`, `Bill_No` and `PartyOrderNo` are not used.                                                                      |
| `BillSeries`    | text   | One of the three ways | empty   | The series of the return as shown in Logic ERP. It must be a **challan return** series of the branch – a normal challan series is not accepted here. Use it with `Bill_No`.                                                                         |
| `Bill_No`       | number | With `BillSeries`     | `0`     | The return number within the series. A number only.                                                                                                                                                                                                 |
| `PartyOrderNo`  | text   | One of the three ways | empty   | The party order number saved on the return. Used when `DocCode` is `0` and the return was not found by series and number.                                                                                                                           |
| `Cancel_Reason` | text   | **Yes**               | –       | Why the return is cancelled. Stored with the cancellation, together with the Logic ERP user, date and time.                                                                                                                                         |
| `DisplayError`  | text   | No                    | `"0"`   | `"1"` = when the cancel fails, `Message` carries the full technical detail.                                                                                                                                                                         |

### **Rules Logic ERP applies**

**Finding the return**

* The return must belong to the branch in `Branch_Code`. Returns of **any financial year** are found.
* With `DocCode` above `0`, the document with that internal number is used. Otherwise `BillSeries` + `Bill_No` are tried first, then `PartyOrderNo`, which must match exactly one challan or challan return of the branch.
* You must send at least `DocCode`, or `BillSeries` with `Bill_No`, or `PartyOrderNo`.

> **Known issue – the party order number is not limited to returns.** The `PartyOrderNo` search, and `DocCode`, look at sale challans and challan returns together. If the number belongs to a **sale challan**, that challan is cancelled. Use `BillSeries` and `Bill_No` with a challan return series to be sure.

**What blocks a cancel**

Nothing is changed when any of these applies:

* The return is **already cancelled**, or `Cancel_Reason` is empty.
* It has been **marked as posted** in Logic ERP's document posting, or it was transferred to head office or imported from another branch (when the user rights of your API user stop changes to such documents).
* The return date is in a **locked period**, on or before the **lock date** for modifications, or on or before the last **physical stock entry** date (when that lock is switched on).
* It has been **approved**, when approved documents may not be changed; or it was changed by someone else while the cancel was running.
* Taking the goods out of stock again would make the stock of a lot negative, when negative stock is not allowed.

**What a cancel does**

All of the following happen together, or none of them:

* The return and its lines are **marked as cancelled** and kept. Its number is **not** freed.
* The returned quantities are **taken out of stock** again.
* Challan lines that the return had marked as returned are **open again** on their challans.
* If the return was posted in accounts, its accounting entries are removed. Loyalty points, discount coupons and gift vouchers linked to it are released, as for a challan.
* The reason, user, date and time are recorded, and an audit-trail entry is written.

There is no endpoint that un-cancels a return, and a cancelled return cannot be cancelled again.

> **Known issue – the reason is sometimes missing from `Message`.** Some refusals come back as *The operation was canceled.*, without the reason, even with `"DisplayError": "1"`. Nothing was cancelled. Check the return in Logic ERP, or ask your Logic ERP team.

### **Example request**

```json
{
  "Branch_Code": 2,
  "BillSeries": "CRT",
  "Bill_No": 14,
  "Cancel_Reason": "Return entered twice"
}
```

### **Response**

| Field            | Type         | Meaning                                                                                                                              |
| ---------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------ |
| `Status`         | true / false | `true` when the return was cancelled.                                                                                                |
| `Message`        | text         | `"Success"` when cancelled; otherwise the reason.                                                                                    |
| `LastSavedCode`  | number       | Logic ERP's internal number of the cancelled return.                                                                                 |
| `LastSavedDocNo` | text         | The return number in Logic ERP's internal form of type, series and number, for example `"CHCRT 14"`. `null` when the request failed. |
| `request_ID`     | text         | As described on the common page. `null` when the request failed before the return was found.                                         |

### **Example response**

```json
{
  "LastSavedDocNo": "CHCRT 14",
  "Status": true,
  "Message": "Success",
  "LastSavedCode": 5530,
  "request_ID": "c2d94f10-5a6e-4b3b-9e7f-1f08a4d6b912"
}
```

### **Messages you may see**

| Message                                                                  | Meaning                                                                                                                                                  | What to do                                                 |
| ------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------- |
| `Please Define Bill No. Or PartyOrderNo to Continue...`                  | None of `DocCode`, `BillSeries` or `PartyOrderNo` was sent.                                                                                              | Send one of them.                                          |
| `Bill No. not defined against Bill Series : …`                           | `BillSeries` sent without `Bill_No`.                                                                                                                     | Send the return number.                                    |
| `Unable to Retrive Bill Series : …`                                      | No challan return series with that name in the branch (a normal challan series gives this too).                                                          | Check the series and `Branch_Code`.                        |
| `Duplicate Bill exists againts Party Order No. : … in Branch Code : …`   | More than one document matched.                                                                                                                          | Send `DocCode` or the series and number.                   |
| `Unable to found Document againts Party Order No. … and Branch Code : …` | No document matched in that branch – also for a `DocCode` or a series and number that is not found (the message names the party order number even then). | Check the branch and the number.                           |
| `Document No. … was not cancelled.`                                      | The cancel ran but the return is still not cancelled.                                                                                                    | Check the return in Logic ERP and cancel it there.         |
| `Document has already been cancelled...`                                 | Already cancelled.                                                                                                                                       | Nothing to do.                                             |
| `Please Enter Cancel Remarks to Continue...`                             | `Cancel_Reason` is empty.                                                                                                                                | Send a reason.                                             |
| `Cannot allow cancellation.... This document has been posted.....`       | The return is marked as posted.                                                                                                                          | Ask your Logic ERP team.                                   |
| `Entry/Modification is locked for this period....`                       | The return date is in a locked period.                                                                                                                   | Ask your Logic ERP team.                                   |
| `The operation was canceled.`                                            | Refused by a check that does not return its reason. Nothing was cancelled.                                                                               | Check the return in Logic ERP, or ask your Logic ERP team. |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://kb.logicerp.com/logic-erp-learning-hub-tutorials-and-best-practices/api-documentation/sale/push/cancel-a-sale-challan-return.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
