Invoice Analytics
Retrieve invoice analytics including totals and counts by status.
GET
https://api.zenpayz.com/merchant/api/v1/invoices/analyticsBearer · API key
Request
Headers
| Header | Description |
|---|---|
Authorization REQUIRED | Bearer {api_key} |
X-Signature REQUIRED | HMAC-SHA256 signature |
X-Timestamp REQUIRED | ISO 8601 timestamp |
X-Secret-Salt REQUIRED | Secret salt for HMAC validation |
Content-Type REQUIRED | application/json |
Response
Success (200 OK)
{
"success": true,
"data": {
"totalInvoices": 150,
"totalAmount": 125000.00,
"totalPaid": 95000.00,
"totalOutstanding": 30000.00,
"byStatus": {
"DRAFT": 10,
"SENT": 25,
"VIEWED": 8,
"PARTIALLY_PAID": 5,
"PAID": 85,
"OVERDUE": 12,
"CANCELLED": 3,
"VOID": 2
},
"averageInvoiceAmount": 833.33,
"averagePaymentTime": 14.5
},
"message": "Invoice analytics retrieved successfully",
"error": null,
"meta": {
"request_id": "req_xxxxx",
"timestamp": "2024-01-15T10:30:00.000Z",
"processing_time_ms": 80,
"api_version": "v1",
"endpoint": "GET /invoices/analytics",
"user_type": "merchant"
}
}
Error Responses
| Code | HTTP | Message |
|---|---|---|
| UNAUTHORIZED | 401 | Invalid API key |
Examples
- cURL
- JavaScript
- SDK
curl -X GET https://api.zenpayz.com/merchant/api/v1/invoices/analytics \
-H "Authorization: Bearer zp_test_xxxxx" \
-H "X-Timestamp: 2024-01-15T10:30:00.000Z" \
-H "X-Signature: a1b2c3d4e5f6..." \
-H "X-Secret-Salt: your_secret_salt" \
-H "Content-Type: application/json"
const response = await fetch('https://api.zenpayz.com/merchant/api/v1/invoices/analytics', {
method: 'GET',
headers: {
'Authorization': `Bearer ${apiKey}`,
'X-Timestamp': timestamp,
'X-Signature': signature,
'X-Secret-Salt': secretSalt,
'Content-Type': 'application/json',
},
});
const result = await response.json();
console.log(result.data.totalInvoices); // 150
console.log(result.data.totalPaid); // 95000.00
const analytics = await zenpays.invoices.analytics();
console.log(analytics.totalInvoices); // 150
console.log(analytics.totalPaid); // 95000.00