# Add usage

Use the **addSubscriptionUsage** method via JSON-RPC API 6.0 to update specific usage easier, to add one usage line at a time, without having to create a file to do so, or to add multiple usages at the same time.

## Request parameters

<table><thead><tr><th width="219.333251953125">Parameter</th><th>Type / Description</th></tr></thead><tbody><tr><td><code>merchantCode</code></td><td><p><strong>Required (string)</strong></p><p>Your unique 2Checkout merchant code.</p></td></tr><tr><td><code>sessionId</code></td><td><p><strong>Required (string)</strong></p><p>Unique 2Checkout session ID code.</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>SubscriptionReference</code></td><td><p><strong>Required (string)</strong></p><p>Unique code that represents a subscription. Example: 83FE4FEF2.</p></td></tr><tr><td><code>OptionCode</code></td><td><p><strong>Required (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>UsageStart</code></td><td><p><strong>Required (datetime)</strong></p><p>The datetime when the usage started; can be the same as <code>UsageEnd</code>. Example: 2018-09-03 17:28:32.</p></td></tr><tr><td><code>UsageEnd</code></td><td><p><strong>Required (datetime)</strong></p><p>The datetime when the usage ended and is recorded. Example: 2018-09-03 17:28:32.</p></td></tr><tr><td><code>Units</code></td><td><p><strong>Required (number)</strong></p><p>Number of units recorded. Example: 10.</p></td></tr><tr><td><code>Description</code></td><td><p><strong>Optional (string)</strong></p><p>It can be used to store a short merchant comment of the usage being uploaded. This can be anything, from the source of usage (mobile, web, etc.), to why changes occurred, etc. Example: Subscription usage for September.</p></td></tr></tbody></table>

### Request Sample

```php
<?php
require ('PATH_TO_AUTH'); // authentication call
$SubscriptionReference = 'B7D8E72224';
$jsonRpcRequest = array (
    'jsonrpc' => '2.0',
    'method' => 'addSubscriptionUsage',
    'params' => array($sessionID, $SubscriptionReference, array(array("OptionCode" => "MeteredPricing", "UsageStart" => "2020-02-22 15:40:00", "UsageEnd" => "2020-03-22 15:40:00","Units" => 10))),
    'id' => $i++
);
var_dump ("addSubscriptionUsage", callRPC((Object)$jsonRpcRequest, $host));
```

## Response

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

```php
{
"jsonrpc": "2.0",
"id": 260,
"result": [\
{\
"UsageReference": "120011112631",\
"SubscriptionReference": "67F3AD6A32",\
"OptionCode": "USG_MN",\
"UsageStart": "2020-07-06 12:00:00",\
"UsageEnd": "2020-07-07 12:00:00",\
"Units": 10,\
"Description": "",\
"RenewalOrderReference": 0\
}\
]
}
```

## Error handling

| Error message description                                                                                                      | Error code      | Error message                                                                                                                                    |
| ------------------------------------------------------------------------------------------------------------------------------ | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| **LICENCECODE is not a valid license code for the merchant**                                                                   | INPUT\_ERROR    | Usage was not added as the license code provided is invalid.                                                                                     |
| **OPTIONCODE is invalid for the Merchant and License or is not a usage-based option code**                                     | INPUT\_ERROR    | Usage was not added as the option code provided is invalid.                                                                                      |
| **Provided usage entries overlap within themselves or with existing usage entries**                                            | INPUT\_ERROR    | Usage was not added as the usage interval provided overlaps with an existing usage interval for the same LICENCECODE and OPTIONCODE combination. |
| **Provided date formats are unsupported**                                                                                      | INPUT\_ERROR    | Usage start / end format unsupported. Please use YYYY-MM-DD HH:MM:SS.                                                                            |
| **One or more mandatory parameters are missing or do not have the required format**                                            | INPUT\_ERROR    | Usage was not added as one or more of the mandatory parameters are missing.                                                                      |
|                                                                                                                                |                 | Usage was not added as one or more of the parameters do not match the required format.                                                           |
|                                                                                                                                |                 | Units not allowed.                                                                                                                               |
| **Provided usages' start date is prior to the subscription start date or end date is after the subscription expiration date.** | INPUT\_ERROR    | Usage interval out of bounds.                                                                                                                    |
| **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/add-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.
