> For the complete documentation index, see [llms.txt](https://docs.2checkout.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.2checkout.com/json-rpc-api-reference/json-rpc-api-6.0/api-requests/subscription/revert-a-subscription.md).

# Revert a subscription

Use the **revertSubscription** method to roll a subscription back to the state it was in immediately before its last order (e.g. a renewal, upgrade, or extend). Revert restores the expiration date, product/quantity values and pricing options captured in the pre-order snapshot, and records the reversal — along with the reason provided — in the subscription's history.

## Request parameters

| Parameter        | Type / Description                                                                                                                                                                                                                                                                                     |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `sessionID`      | <p><strong>Required (string)</strong><br>Session identifier, the output of the <strong>Login</strong> method. Include <code>sessionID</code> into all your requests. 2Checkout throws an exception if the values are incorrect. The <code>sessionID</code> expires in <strong>10 minutes</strong>.</p> |
| `LicenceCode`    | <p><strong>Required (string)</strong><br>Unique, system-generated subscription identifier of the subscription to revert.</p>                                                                                                                                                                           |
| `OrderReference` | <p><strong>Required (string)</strong><br>The 2Checkout reference number of the order whose changes should be undone. Must be the last order placed on the subscription.</p>                                                                                                                            |
| `Reason`         | <p><strong>Required (string)</strong></p><p>Free-text explanation for the revert. Recorded against the subscription's history alongside the revert event.</p>                                                                                                                                          |

Revert restores the subscription to its pre-order snapshot:

* Expiration date is reverted to the snapshot value.
* Product, product name, pricing options and quantity are reverted to the snapshot values.
* A new history entry is written, capturing the before/after values and the Reason supplied.

If reverting a prolong-license action causes the expiration date to fall in the past, the expiration date will be left to the current value.

Revert only accepts subscriptions whose last change was order-driven (renewal, upgrade, extend, etc.). If the subscription was modified some other way after that order, for example, directly by a merchant user, the revert will fail.

### Request sample

```php
<?php

require ('PATH_TO_AUTH');

$subscriptionReferenceTest = 'YOUR_SUBSCRIPTION_REFERENCE';

$jsonRpcRequest = array (
  'method' => 'getSubscription',
  'params' => array($sessionID, $subscriptionReferenceTest),
  'id' => $i++,
  'jsonrpc' => '2.0'
);

$updatedSubscription = callRPC((Object)$jsonRpcRequest, $host, true);
var_dump ($updatedSubscription);
$updatedSubscription->RecurringEnabled = false;
$updatedSubscription->SubscriptionEnabled = true;
$updatedSubscription->ExpirationDate = '2020-12-12';

$jsonRpcRequest = array (
  'method' => 'updateSubscription',
  'params' => array($sessionID, $updatedSubscription),
  'id' => $i++,
  'jsonrpc' => '2.0'
);

var_dump (callRPC((Object)$jsonRpcRequest, $host, true));
```

## Response parameters

<table><thead><tr><th width="110.5333251953125">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>Boolean</strong></td><td><strong>true</strong> or <strong>false</strong> depending on whether the changes were successful or not.</td></tr></tbody></table>

## Error codes

| Error code                             | Description                                                                                    |
| -------------------------------------- | ---------------------------------------------------------------------------------------------- |
| **LICENCE\_NOT\_FOUND**                | The licence or order cannot be found.                                                          |
| **NOT\_LAST\_ORDER**                   | The provided order is not the last order on this subscription.                                 |
| **NO\_SNAPSHOT**                       | No snapshot exists for this subscription before the given order.                               |
| **SUBSCRIPTION\_MODIFIED\_EXTERNALLY** | The subscription was modified outside of an order after the last order and cannot be reverted. |
| **SUBSEQUENT\_CHANGES**                | The subscription was modified after this order. Revert is not allowed.                         |
| **INVALID\_ORDER**                     | A valid OrderReference (order RefNo) is required.                                              |
| **MISSING\_REASON**                    | Reason for revert is required.                                                                 |
| **REVERT\_FAILED**                     | Revert transaction rolled back due to a database failure.                                      |


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.2checkout.com/json-rpc-api-reference/json-rpc-api-6.0/api-requests/subscription/revert-a-subscription.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
