# POST /api/v2/getdashboardstats — Dashboard Stats

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

A POST request API by which you can get the stats of dashboard like total sales, total refund, recurring amount and so on. In response you can get all the stats which is shown on the dashboard of your Pabbly Subscriptions account.

**Body parameters:**

| Name | Type | Required | Description |
|------|------|----------|-------------|
| product_id | string | Yes | Get the stats product wise or for all products. |
| interval | string | Yes | Fill the interval for States like last 30 days, this_week and so on. |

**Example request body:**

```json
{
"product_id":"5e3a95143c92e44b424b6d47",
"interval":"last_30_days"
}
```

**Response (200)** — Dashboard Stats:

```json
{
    "status": "success",
    "message": "Total stats",
    "data": {
        "total_customer_count": 11,
        "total_paid_customer_count": 9,
        "total_sales_amount": 5013.52,
        "total_sales_count": 35,
        "total_onetime_sales_count": 0,
        "total_onetime_sales_amount": 0,
        "total_recurring_sales_count": 35,
        "total_recurring_sales_amount": 5013.52,
        "total_refund_count": 0,
        "total_refund_amount": 0,
        "total_cancelled_subscription_count": 0,
        "total_cancelled_subscription_amount": 0,
        "mrr": "33590.75",
        "total_net_revenue": 4726.1,
        "total_affiliate_sales_amount": 1999,
        "total_affiliate_commission_amount": 239.9,
        "total_net_amount_via_affiliate": 1759.1,
        "total_affiliate_count": 2,
        "total_rebill_amount": 25840.98,
        "total_rebill_subscription_count": 188,
        "total_missed_invoice_amount": 400,
        "total_missed_invoice_count": 4,
        "arpu": "429.6454545"
    }
}
```

**Code examples:**

_cURL_

```curl
curl -X POST https://payments.pabbly.com/api/v1/api/v2/getdashboardstats \
  -u {{YOUR_API_KEY}}:{{YOUR_SECRET_KEY}} \
  -H "Content-Type: application/json" \
  -d '{
    "product_id": "5e3a95143c92e44b424b6d47",
    "interval": "last_30_days"
  }'
```

_Ruby_

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

uri = URI('https://payments.pabbly.com/api/v1/api/v2/getdashboardstats')
request = Net::HTTP::Post.new(uri)
request.basic_auth '{{YOUR_API_KEY}}', '{{YOUR_SECRET_KEY}}'
request['Content-Type'] = 'application/json'
request.body = "{\"product_id\":\"5e3a95143c92e44b424b6d47\",\"interval\":\"last_30_days\"}"

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/api/v2/getdashboardstats',
    auth=HTTPBasicAuth('{{YOUR_API_KEY}}', '{{YOUR_SECRET_KEY}}'),
    json={
    'product_id': '5e3a95143c92e44b424b6d47',
    'interval': 'last_30_days'
},
)

data = response.json()
```

_PHP_

```php
<?php
$ch = curl_init('https://payments.pabbly.com/api/v1/api/v2/getdashboardstats');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_USERPWD, '{{YOUR_API_KEY}}:{{YOUR_SECRET_KEY}}');
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"product_id":"5e3a95143c92e44b424b6d47","interval":"last_30_days"}');

$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/api/v2/getdashboardstats"))
    .header("Authorization", "Basic " + credentials)
    .header("Content-Type", "application/json")
    .method("POST", HttpRequest.BodyPublishers.ofString("{\"product_id\":\"5e3a95143c92e44b424b6d47\",\"interval\":\"last_30_days\"}"));

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/api/v2/getdashboardstats', {
  method: 'POST',
  headers: {
    'Authorization': `Basic ${credentials}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "product_id": "5e3a95143c92e44b424b6d47",
    "interval": "last_30_days"
  }),
});

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

_Go_

```go
package main

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

func main() {
    payload := strings.NewReader("{\"product_id\":\"5e3a95143c92e44b424b6d47\",\"interval\":\"last_30_days\"}")
    req, _ := http.NewRequest("POST", "https://payments.pabbly.com/api/v1/api/v2/getdashboardstats", payload)
    req.Header.Set("Content-Type", "application/json")
    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/api/v2/getdashboardstats");
request.Headers.TryAddWithoutValidation("Authorization", $"Basic {credentials}");
request.Content = new StringContent("{\"product_id\":\"5e3a95143c92e44b424b6d47\",\"interval\":\"last_30_days\"}");
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

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

