# POST /invoices/create-metered/{{subscription_id}} — Create Metered Invoice

> Product: **Pabbly Subscription Billing** (v1)
> Base URL: `https://payments.pabbly.com/api/v1`
> Auth: Basic via `Authorization` header
> Canonical: `/subscription-billing/invoice/create-metered-invoice`

Generate a new invoice based on metered usage for the given subscription. Used for usage-based billing models where the amount depends on consumption.

**Path parameters:**

| Name | Type | Required | Description |
|------|------|----------|-------------|
| subscription_id | string | Yes |  |

**Example request body:**

```json
{
    "amount": 200, //Invoice amount
    "invoice_date":"2023-01-22" // Custom invoice date or due date (Optional)
}
```

**Response (200)** — Create Metered Invoice:

```json
{
    "status": "success",
    "message": "Invoice is created successfully",
    "data": {
        "user": {
            "verified": "1",
            "currency": "INR",
            "createdAt": "2018-01-02T10:34:49.381Z",
            "updatedAt": "2023-01-20T11:13:01.822Z",
            "id": "5a4b60497cfab6872a7feafb",
            "first_name": "Krishna",
            "last_name": "Thapa",
            "email": "krishna.thapa@pabbly.com",
            "address_line1": "",
            "address_line2": "",
            "city": "Bhopal",
            "state": "Madhya Pradesh",
            "country": "Afghanistan",
            "zip_code": "462016",
            "phone": "8602575688",
            "mobile": "",
            "facebook_url": "",
            "twitter_url": "",
            "time_zone": "Asia/Calcutta",
            "date_format": "YYYY/MM/DD hh:mm A",
            "currency_symbol": "₹"
        },
        "customer": {
            "billing_address": {
                "street1": "",
                "city": "",
                "state": "",
                "state_code": "",
                "zip_code": "",
                "country": ""
            },
            "shipping_address": {
                "street1": "",
                "city": "",
                "state": "",
                "state_code": "",
                "zip_code": "",
                "country": ""
            },
            "portal_status": true,
            "createdAt": "2023-01-20T11:24:19.800Z",
            "updatedAt": "2023-01-20T11:24:19.881Z",
            "id": "63ca79e3202e97777f1b8cd3",
            "first_name": "Test",
            "last_name": "Jun",
            "email_id": "admin@pabbly.com"
        },
        "plan": {
            "plan_type": "flat_fee",
            "plan_active": "true",
            "currency_code": "USD",
            "currency_symbol": "$",
            "is_metered": true,
            "createdAt": "2023-01-20T11:23:58.451Z",
            "updatedAt": "2023-01-20T11:23:58.451Z",
            "id": "63ca79ce7df4717768e4fd40",
            "product_id": "60926cdb76d902627cf101e0",
            "plan_name": "Metered Plan",
            "plan_code": "metered-plan",
            "price": "200",
            "billing_period": "",
            "billing_period_num": "",
            "billing_cycle": "onetime",
            "billing_cycle_num": null,
            "trial_period": 0,
            "setup_fee": 0,
            "plan_description": "<p>This is the test plan description.</p><p><br></p><p><img src=\"https://s3psb.pabbly.com/product/images/2022/2/Y9fZRFgdHKIR-1643959680-PlandescriptionImage.png\"></p><p><br></p><p>From the checkout customizer,</p><p><br></p><ul><li>You can change the bullet type.</li><li>You can change list style.</li><li>You can change text size</li><li>You can change the bullet color.</li><li>Image size should be 400W x 250H, Max Size - 100kb.</li></ul><p><br></p>"
        },
        "subscription": {
            "plan": {
                "plan_type": "flat_fee",
                "plan_active": "true",
                "currency_code": "USD",
                "currency_symbol": "$",
                "is_metered": true,
                "createdAt": "2023-01-20T11:23:58.451Z",
                "updatedAt": "2023-01-20T11:23:58.451Z",
                "id": "63ca79ce7df4717768e4fd40",
                "product_id": "60926cdb76d902627cf101e0",
                "plan_name": "Metered Plan",
                "plan_code": "metered-plan",
                "price": "200",
                "billing_period": "",
                "billing_period_num": "",
                "billing_cycle": "onetime",
                "billing_cycle_num": null,
                "trial_period": 0,
                "setup_fee": 0,
                "plan_description": "<p>This is the test plan description.</p><p><br></p><p><img src=\"https://s3psb.pabbly.com/product/images/2022/2/Y9fZRFgdHKIR-1643959680-PlandescriptionImage.png\"></p><p><br></p><p>From the checkout customizer,</p><p><br></p><ul><li>You can change the bullet type.</li><li>You can change list style.</li><li>You can change text size</li><li>You can change the bullet color.</li><li>Image size should be 400W x 250H, Max Size - 100kb.</li></ul><p><br></p>"
            },
            "setup_fee": 0,
            "currency_code": "USD",
            "currency_symbol": "$",
            "payment_method": "63ca79e4202e97777f1b8cd7",
            "taxable": true,
            "gateway_type": "test",
            "payment_terms": "net0",
            "gateway_id": "5abc734184b6887430870718",
            "gateway_name": "Test",
            "custom_fields": [],
            "requested_ip": "2405:201:301d:c115:f9c0:d94b:b3a7:aaee",
            "createdAt": "2023-01-20T11:24:19.810Z",
            "updatedAt": "2023-01-20T11:26:38.554Z",
            "id": "63ca79e3202e97777f1b8cd4",
            "customer_id": "63ca79e3202e97777f1b8cd3",
            "product_id": "60926cdb76d902627cf101e0",
            "plan_id": "63ca79ce7df4717768e4fd40",
            "amount": 100,
            "email_id": "admin@pabbly.com",
            "status": "live",
            "quantity": 1,
            "starts_at": "2023-01-20T11:24:19.191Z",
            "activation_date": "2023-01-20T11:24:20.202Z",
            "expiry_date": "2123-01-20T11:24:19.191Z",
            "trial_days": 0,
            "trial_expiry_date": "",
            "next_billing_date": "",
            "last_billing_date": "2023-01-20T11:24:20.202Z",
            "canceled_date": null,
            "customer": {
                "billing_address": {
                    "street1": "",
                    "city": "",
                    "state": "",
                    "state_code": "",
                    "zip_code": "",
                    "country": ""
                },
                "shipping_address": {
                    "street1": "",
                    "city": "",
                    "state": "",
                    "state_code": "",
                    "zip_code": "",
                    "country": ""
                },
                "portal_status": true,
                "createdAt": "2023-01-20T11:24:19.800Z",
                "updatedAt": "2023-01-20T11:24:19.881Z",
                "id": "63ca79e3202e97777f1b8cd3",
                "first_name": "Test",
                "last_name": "Jun",
                "email_id": "admin@pabbly.com"
            },
            "product": {}
        },
        "invoice": {
            "quantity": 1,
            "product_id": "60926cdb76d902627cf101e0",
            "setup_fee": 0,
            "currency_symbol": "$",
            "currency_code": "USD",
            "credit_note": {
                "total_tax": "0.00",
                "status": "success",
                "new_plan_total": 200,
                "total_credit_amount": 0,
                "charge_amount": 200,
                "credit_applied": []
            },
            "createdAt": "2023-01-22T00:00:00.000Z",
            "updatedAt": "2023-01-20T11:26:38.558Z",
            "id": "63ca7a6e202e97777f1b8ced",
            "customer_id": "63ca79e3202e97777f1b8cd3",
            "subscription_id": "63ca79e3202e97777f1b8cd4",
            "status": "sent",
            "invoice_id": "INV-1146",
            "payment_term": "net0",
            "amount": 200,
            "due_amount": 200,
            "due_date": "2023-01-22T00:00:00.000Z",
            "subscription": {
                "plan": {
                    "plan_type": "flat_fee",
                    "plan_active": "true",
                    "currency_code": "USD",
                    "currency_symbol": "$",
                    "is_metered": true,
                    "createdAt": "2023-01-20T11:23:58.451Z",
                    "updatedAt": "2023-01-20T11:23:58.451Z",
                    "id": "63ca79ce7df4717768e4fd40",
                    "product_id": "60926cdb76d902627cf101e0",
                    "plan_name": "Metered Plan",
                    "plan_code": "metered-plan",
                    "price": "200",
                    "billing_period": "",
                    "billing_period_num": "",
                    "billing_cycle": "onetime",
                    "billing_cycle_num": null,
                    "trial_period": 0,
                    "setup_fee": 0,
                    "plan_description": "<p>This is the test plan description.</p><p><br></p><p><img src=\"https://s3psb.pabbly.com/product/images/2022/2/Y9fZRFgdHKIR-1643959680-PlandescriptionImage.png\"></p><p><br></p><p>From the checkout customizer,</p><p><br></p><ul><li>You can change the bullet type.</li><li>You can change list style.</li><li>You can change text size</li><li>You can change the bullet color.</li><li>Image size should be 400W x 250H, Max Size - 100kb.</li></ul><p><br></p>"
                },
                "setup_fee": 0,
                "currency_code": "USD",
                "currency_symbol": "$",
                "payment_method": "63ca79e4202e97777f1b8cd7",
                "taxable": true,
                "gateway_type": "test",
                "payment_terms": "net0",
                "gateway_id": "5abc734184b6887430870718",
                "gateway_name": "Test",
                "custom_fields": [],
                "requested_ip": "2405:201:301d:c115:f9c0:d94b:b3a7:aaee",
                "createdAt": "2023-01-20T11:24:19.810Z",
                "updatedAt": "2023-01-20T11:26:38.554Z",
                "id": "63ca79e3202e97777f1b8cd4",
                "customer_id": "63ca79e3202e97777f1b8cd3",
                "product_id": "60926cdb76d902627cf101e0",
                "plan_id": "63ca79ce7df4717768e4fd40",
                "amount": 100,
                "email_id": "admin@pabbly.com",
                "status": "live",
                "quantity": 1,
                "starts_at": "2023-01-20T11:24:19.191Z",
                "activation_date": "2023-01-20T11:24:20.202Z",
                "expiry_date": "2123-01-20T11:24:19.191Z",
                "trial_days": 0,
                "trial_expiry_date": "",
                "next_billing_date": "",
                "last_billing_date": "2023-01-20T11:24:20.202Z",
                "canceled_date": null
            },
            "invoice_link": "https://payments.pabbly.com/secureinvoice/5a7ee69a36431f245eb2bc62/?cinvoice_id=1bed8647bc0c952921f82e8e973640a5:91df811946438db4a0c4371708765fb53a001f88aa025bd544a72455bf2168d37a538ea2cd45fd71345d3eada311a8c00a6ec63289182215520fef6c6320f7a1a2b62118e9bbc935e5d8abf8e0d65e27"
        }
    }
}
```

**Code examples:**

_cURL_

```curl
curl -X POST https://payments.pabbly.com/api/v1/invoices/create-metered/{{subscription_id}} \
  -u {{YOUR_API_KEY}}:{{YOUR_SECRET_KEY}}
```

_Ruby_

```ruby
require 'net/http'
require 'json'

uri = URI('https://payments.pabbly.com/api/v1/invoices/create-metered/{{subscription_id}}')
request = Net::HTTP::Post.new(uri)
request.basic_auth '{{YOUR_API_KEY}}', '{{YOUR_SECRET_KEY}}'

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
  http.request(request)
end

data = JSON.parse(response.body)
```

_Python_

```python
import requests
from requests.auth import HTTPBasicAuth

response = requests.post(
    'https://payments.pabbly.com/api/v1/invoices/create-metered/{{subscription_id}}',
    auth=HTTPBasicAuth('{{YOUR_API_KEY}}', '{{YOUR_SECRET_KEY}}'),
)

data = response.json()
```

_PHP_

```php
<?php
$ch = curl_init('https://payments.pabbly.com/api/v1/invoices/create-metered/{{subscription_id}}');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_USERPWD, '{{YOUR_API_KEY}}:{{YOUR_SECRET_KEY}}');

$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
```

_Java_

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Base64;

String credentials = Base64.getEncoder().encodeToString("{{YOUR_API_KEY}}:{{YOUR_SECRET_KEY}}".getBytes());

HttpClient client = HttpClient.newHttpClient();
HttpRequest.Builder builder = HttpRequest.newBuilder()
    .uri(URI.create("https://payments.pabbly.com/api/v1/invoices/create-metered/{{subscription_id}}"))
    .header("Authorization", "Basic " + credentials)
    .method("POST", HttpRequest.BodyPublishers.noBody());

HttpRequest request = builder.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

_Node.js_

```node
const credentials = Buffer.from('{{YOUR_API_KEY}}:{{YOUR_SECRET_KEY}}').toString('base64');

const response = await fetch('https://payments.pabbly.com/api/v1/invoices/create-metered/{{subscription_id}}', {
  method: 'POST',
  headers: {
    'Authorization': `Basic ${credentials}`,
  },
});

const data = await response.json();
```

_Go_

```go
package main

import (
    "fmt"
    "io"
    "net/http"
)

func main() {
    req, _ := http.NewRequest("POST", "https://payments.pabbly.com/api/v1/invoices/create-metered/{{subscription_id}}", nil)
    req.SetBasicAuth("{{YOUR_API_KEY}}", "{{YOUR_SECRET_KEY}}")

    res, _ := http.DefaultClient.Do(req)
    defer res.Body.Close()
    body, _ := io.ReadAll(res.Body)
    fmt.Println(string(body))
}
```

_.NET_

```dotnet
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes("{{YOUR_API_KEY}}:{{YOUR_SECRET_KEY}}"));

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://payments.pabbly.com/api/v1/invoices/create-metered/{{subscription_id}}");
request.Headers.TryAddWithoutValidation("Authorization", $"Basic {credentials}");

var response = await client.SendAsync(request);
var data = await response.Content.ReadAsStringAsync();
Console.WriteLine(data);
```

---

**Other endpoints in Invoice:**

- [GET /invoice/{{invoice_id}} — Get Single Invoice](/subscription-billing/invoice/get-single-invoice)
- [GET /invoices/transactions/{{invoice_id}} — List All Transactions By Invoice Id](/subscription-billing/invoice/list-all-transactions-by-invoice-id)
- [GET /invoices/{{customer_id}} — List All Invoices By Customer Id](/subscription-billing/invoice/list-all-invoices-by-customer-id)
- [GET /invoices — List All Invoices](/subscription-billing/invoice/list-all-invoices)
- [POST /invoice/recordpayment/{{invoice_id}} — Record Payment Invoice](/subscription-billing/invoice/record-payment-invoice)
- [POST /invoice/failedpayment/{{invoice_id}} — Record Failed Payment Invoice](/subscription-billing/invoice/record-failed-payment-invoice)
- [DELETE /invoices/{{invoice_id}} — Delete Invoice](/subscription-billing/invoice/delete-invoice)

