# Retrieve usage

Use the **getSubscriptionUsages** method via JSON-RPC API 6.0 to search through subscription usages and retrieve all the usage information attached to a subscription.

## Request parameters <a href="#request-parameters" id="request-parameters"></a>

<table><thead><tr><th width="212.933349609375">Parameter</th><th>Type / Description</th></tr></thead><tbody><tr><td><code>merchantCode</code></td><td><p><strong>Required (string)</strong></p><p>The system-generated merchant ID.</p></td></tr><tr><td><code>hash</code></td><td><p><strong>Required (string)</strong></p><p>The MD5 hmac key for the request.</p></td></tr><tr><td><code>sessionID</code></td><td><p><strong>Required (string)</strong></p><p>The system-generated code of the session.</p></td></tr><tr><td><code>SubscriptionReference</code></td><td><p><strong>Required (string)</strong></p><p>The system-generated reference code of the subscription.</p></td></tr><tr><td><code>Page</code></td><td><p><strong>Required (number)</strong></p><p>The page to be returned.</p></td></tr><tr><td><code>Limit</code></td><td><p><strong>Required (number)</strong></p><p>The number of results per page.</p></td></tr><tr><td><code>IntervalStart</code></td><td><p><strong>Required (datetime)</strong></p><p>Filters all usages where <code>UsageEnd</code> >= <code>IntervalStart</code>. Format "YYYY-MM-DD". The timezone used is the one on the server.</p></td></tr><tr><td><code>IntervalEnd</code></td><td><p><strong>Required (datetime)</strong></p><p>Filters all usages where <code>UsageEnd</code> &#x3C;= <code>IntervalEnd</code>. Format "YYYY-MM-DD". The timezone used is the one on the server.</p></td></tr><tr><td><code>OptionCode</code></td><td><p><strong>Optional (string)</strong></p><p>Unique 2Checkout option code. The pay-per-usage price options group for which the usage is uploaded. Example: metered pricing. </p></td></tr><tr><td><code>RenewalOrderReference</code></td><td><p><strong>Optional (number)</strong></p><p>The renewal order unique identifier.</p></td></tr></tbody></table>

### Request Sample <a href="#request-sample" id="request-sample"></a>

```php
<?php
require ('PATH_TO_AUTH'); // authentication call
$SubscriptionReference = 'B7D8E72224';
$jsonRpcRequest = array(
    'jsonrpc' => '2.0',
    'method'  => 'getSubscriptionUsages',
    'params'  =>
        array(
            $sessionID,
            [
                'SubscriptionReference' => $SubscriptionReference,
                "Page"                  => 1,
                "Limit"                 => 10,
                "IntervalStart"         => "2020-07-01 10:40:00",
                "IntervalEnd"           => "2020-08-01 10:40:00",
                "RenewalOrderReference" => "11749701"
            ]
        ),
    'id'      => $i++
);
var_dump ("getSubscriptionUsages", callRPC((Object)$jsonRpcRequest, $host));
```

## Response <a href="#response" id="response"></a>

The **getUsages** method via JSON-RPC APIv6 returns the [Usage](/json-rpc-api-reference/json-rpc-api-6.0/api-requests/usage-management.md) object when successful.

```php
class stdClass#4 (2) {
      public $Items =>
      array(1) {
        [0] =>
        class stdClass#3 (8) {
          public $UsageReference =>
          string(12) "120011114371"
          public $SubscriptionReference =>
          string(10) "67F3AD6A32"
          public $OptionCode =>
          string(6) "USG_MN"
          public $UsageStart =>
          string(19) "2020-07-06 12:00:00"
          public $UsageEnd =>
          string(19) "2020-07-07 12:00:00"
          public $Units =>
          int(7)
          public $Description =>
          string(15) "Response sample"
          public $RenewalOrderReference =>
          int(0)
        }
      }
      public $Pagination =>
      class stdClass#5 (3) {
        public $Page =>
        int(1)
        public $Limit =>
        int(10)
        public $Count =>
        int(1)
      }
    }

```

## Error Handling <a href="#error-handling" id="error-handling"></a>

The below errors are returned when the **getUsages** method via JSON-RPC APIv6 is unsuccessful.

| Error message description                                     | Error code                 | Error message                                                                  |
| ------------------------------------------------------------- | -------------------------- | ------------------------------------------------------------------------------ |
| **The provided parameters lack the required type or format.** | SEARCH\_PAGE\_INVALID      | The `Page` parameter must be a positive integer higher than or equal to 1.     |
|                                                               | SEARCH\_LIMIT\_INVALID     | The `Limit` parameter must be a positive integer lower than 100.               |
|                                                               | MANDATORY\_FIELDS\_MISSING | Both `IntervalStart` and `IntervalEnd` parameters must be provided.            |
|                                                               | FILTER\_INVALID            | If provided, `RenewalOrderReference` must be a positive integer.               |
|                                                               | FILTER\_INVALID            | `IntervalStart` must be provided in the following format: YYYY-MM-DD HH:MM:SS. |
|                                                               | FILTER\_INVALID            | `IntervalStart` must be provided in the following format: YYYY-MM-DD HH:MM:SS. |
|                                                               | FILTER\_INVALID            | `IntervalEnd` must be provided in the following format: YYYY-MM-DD HH:MM:SS.   |
|                                                               | FILTER\_INVALID            | `IntervalEnd` must be provided in the following format: YYYY-MM-DD HH:MM:SS.   |
|                                                               | SEARCH\_PAGE\_INVALID      | The `Page` parameter must be a positive integer higher than or equal to 1.     |
|                                                               | SUBSCRIPTION\_NOT\_FOUND   | Subscription not found.                                                        |
| **Unexpected error happens**                                  | INTERNAL\_ERROR            | \<unexpected\_error>                                                           |


---

# Agent Instructions: 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:

```
GET https://docs.2checkout.com/json-rpc-api-reference/json-rpc-api-6.0/api-requests/usage-management/retrieve-usage.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
