1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
use crate::api::*;
use crate::{ApiError, ClientConfig, HttpClient, QueryBuilder, RequestOptions};
use reqwest::Method;
pub struct InsightsClient {
pub http_client: HttpClient,
}
impl InsightsClient {
pub fn new(config: ClientConfig) -> Result<Self, ApiError> {
Ok(Self {
http_client: HttpClient::new(config.clone())?,
})
}
/// Returns the organization-wide receivables position as of now: total open balance, the past-due portion, invoice counts, and a breakdown by days past due. Unlike the other insights endpoints this is a point-in-time snapshot rather than a period aggregate, so it takes no date range. Amounts from every currency are converted into the organization's base currency.
///
/// # Arguments
///
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use alguna::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// api_key: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Alguna::new(config).expect("Failed to build client");
/// client.insights.ar_aging(None).await;
/// }
/// ```
pub async fn ar_aging(
&self,
options: Option<RequestOptions>,
) -> Result<ArAgingSummaryResponse, ApiError> {
self.http_client
.execute_request(Method::GET, "insights/ar-aging", None, None, options)
.await
}
/// Returns one entry per customer and currency, each with the open balance, invoice counts, and a breakdown by days past due. A customer billed in more than one currency produces one entry per currency, so entries for a single customer can be summed by invoice count but never by amount. Like the aging summary, this is a point-in-time snapshot and takes no date range.
///
/// # Arguments
///
/// * `customer_alias` - Filter by an alternative identifier (external ID) for the customer. Used when customer_id is not provided.
/// * `customer_id` - Filter by customer ID. Provide at most one of customer_id or customer_alias; omit both to report on every customer.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use alguna::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// api_key: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Alguna::new(config).expect("Failed to build client");
/// client
/// .insights
/// .ar_aging_by_customer(
/// &ArAgingByCustomerQueryRequest {
/// customer_alias: Some("ext_39003209203023902".to_string()),
/// customer_id: Some("cust_abc123".to_string()),
/// ..Default::default()
/// },
/// None,
/// )
/// .await;
/// }
/// ```
pub async fn ar_aging_by_customer(
&self,
request: &ArAgingByCustomerQueryRequest,
options: Option<RequestOptions>,
) -> Result<ArAgingByCustomerResponse, ApiError> {
self.http_client
.execute_request(
Method::GET,
"insights/ar-aging/by-customer",
None,
QueryBuilder::new()
.string("customer_alias", request.customer_alias.clone())
.string("customer_id", request.customer_id.clone())
.build(),
options,
)
.await
}
/// Returns top customers ranked by net billings for the selected period, with a comparison to the prior period. Remaining customers are aggregated into an 'other' total.
///
/// # Arguments
///
/// * `date_range` - Time period for the query. Determines the primary period and automatically calculates a comparison period.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use alguna::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// api_key: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Alguna::new(config).expect("Failed to build client");
/// client
/// .insights
/// .billings_by_customer(
/// &BillingsByCustomerQueryRequest {
/// date_range: BillingsByCustomerInsightsRequestDateRange::ThisMonth,
/// },
/// None,
/// )
/// .await;
/// }
/// ```
pub async fn billings_by_customer(
&self,
request: &BillingsByCustomerQueryRequest,
options: Option<RequestOptions>,
) -> Result<BillingsByCustomerResponse, ApiError> {
self.http_client
.execute_request(
Method::GET,
"insights/billings/by-customer",
None,
QueryBuilder::new()
.serialize("date_range", Some(request.date_range.clone()))
.build(),
options,
)
.await
}
/// Returns billings broken down by product for the selected period, with a comparison to the prior period.
///
/// # Arguments
///
/// * `customer_id` - Optional customer ID to filter by
/// * `date_range` - Time period for the query.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use alguna::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// api_key: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Alguna::new(config).expect("Failed to build client");
/// client
/// .insights
/// .billings_by_product(
/// &BillingsByProductQueryRequest {
/// customer_id: Some("cust_abc123".to_string()),
/// date_range: BillingsByProductInsightsRequestDateRange::ThisMonth,
/// },
/// None,
/// )
/// .await;
/// }
/// ```
pub async fn billings_by_product(
&self,
request: &BillingsByProductQueryRequest,
options: Option<RequestOptions>,
) -> Result<BillingsByProductResponse, ApiError> {
self.http_client
.execute_request(
Method::GET,
"insights/billings/by-product",
None,
QueryBuilder::new()
.string("customer_id", request.customer_id.clone())
.serialize("date_range", Some(request.date_range.clone()))
.build(),
options,
)
.await
}
/// Returns a time series of net billings data points split into fixed and metered components. Based on issued invoices.
///
/// # Arguments
///
/// * `date_range` - Time period for the query. Determines the primary period and automatically calculates a comparison period.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use alguna::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// api_key: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Alguna::new(config).expect("Failed to build client");
/// client
/// .insights
/// .billings_over_time(
/// &BillingsOverTimeQueryRequest {
/// date_range: BillingsOverTimeInsightsRequestDateRange::ThisMonth,
/// },
/// None,
/// )
/// .await;
/// }
/// ```
pub async fn billings_over_time(
&self,
request: &BillingsOverTimeQueryRequest,
options: Option<RequestOptions>,
) -> Result<AmountsOverTimeResponse, ApiError> {
self.http_client
.execute_request(
Method::GET,
"insights/billings/over-time",
None,
QueryBuilder::new()
.serialize("date_range", Some(request.date_range.clone()))
.build(),
options,
)
.await
}
/// Returns customer lifecycle metrics: active, churned, new, and reactivated customer counts with comparison to the prior period.
///
/// # Arguments
///
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use alguna::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// api_key: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Alguna::new(config).expect("Failed to build client");
/// client.insights.customers(None).await;
/// }
/// ```
pub async fn customers(
&self,
options: Option<RequestOptions>,
) -> Result<CustomerInsightsResponse, ApiError> {
self.http_client
.execute_request(Method::GET, "insights/customers", None, None, options)
.await
}
/// Returns a time series of customer lifecycle events: new, reactivated, existing, and churned customer counts per period.
///
/// # Arguments
///
/// * `date_range` - Time period for the query. Determines the primary period and automatically calculates a comparison period.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use alguna::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// api_key: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Alguna::new(config).expect("Failed to build client");
/// client
/// .insights
/// .customers_over_time(
/// &CustomersOverTimeQueryRequest {
/// date_range: CustomersOverTimeInsightsRequestDateRange::ThisMonth,
/// },
/// None,
/// )
/// .await;
/// }
/// ```
pub async fn customers_over_time(
&self,
request: &CustomersOverTimeQueryRequest,
options: Option<RequestOptions>,
) -> Result<CustomerInsightsOverTimeResponse, ApiError> {
self.http_client
.execute_request(
Method::GET,
"insights/customers/over-time",
None,
QueryBuilder::new()
.serialize("date_range", Some(request.date_range.clone()))
.build(),
options,
)
.await
}
/// Returns a net revenue summary including current month, last month, and annualized figures broken down by fixed (recurring) and metered (usage-based) revenue.
///
/// # Arguments
///
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use alguna::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// api_key: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Alguna::new(config).expect("Failed to build client");
/// client.insights.revenue(None).await;
/// }
/// ```
pub async fn revenue(
&self,
options: Option<RequestOptions>,
) -> Result<NetRevenueResponse, ApiError> {
self.http_client
.execute_request(Method::GET, "insights/revenue", None, None, options)
.await
}
/// Returns a time series of revenue classified by movement type: existing, new, expansion, contraction, and churn.
///
/// # Arguments
///
/// * `date_range` - Time period for the query. Determines the primary period and automatically calculates a comparison period.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use alguna::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// api_key: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Alguna::new(config).expect("Failed to build client");
/// client
/// .insights
/// .revenue_breakdown_over_time(
/// &RevenueBreakdownOverTimeQueryRequest {
/// date_range: RevenueBreakdownOverTimeInsightsRequestDateRange::ThisMonth,
/// },
/// None,
/// )
/// .await;
/// }
/// ```
pub async fn revenue_breakdown_over_time(
&self,
request: &RevenueBreakdownOverTimeQueryRequest,
options: Option<RequestOptions>,
) -> Result<RevenueBreakdownOverTimeResponse, ApiError> {
self.http_client
.execute_request(
Method::GET,
"insights/revenue/breakdown-over-time",
None,
QueryBuilder::new()
.serialize("date_range", Some(request.date_range.clone()))
.build(),
options,
)
.await
}
/// Returns top customers ranked by net revenue for the selected period, with a comparison to the prior period. Remaining customers are aggregated into an 'other' total.
///
/// # Arguments
///
/// * `date_range` - Time period for the query. Determines the primary period and automatically calculates a comparison period.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use alguna::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// api_key: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Alguna::new(config).expect("Failed to build client");
/// client
/// .insights
/// .revenue_by_customer(
/// &RevenueByCustomerQueryRequest {
/// date_range: RevenueByCustomerInsightsRequestDateRange::ThisMonth,
/// },
/// None,
/// )
/// .await;
/// }
/// ```
pub async fn revenue_by_customer(
&self,
request: &RevenueByCustomerQueryRequest,
options: Option<RequestOptions>,
) -> Result<RevenueByCustomerResponse, ApiError> {
self.http_client
.execute_request(
Method::GET,
"insights/revenue/by-customer",
None,
QueryBuilder::new()
.serialize("date_range", Some(request.date_range.clone()))
.build(),
options,
)
.await
}
/// Returns revenue broken down by product for the selected period, with a comparison to the prior period.
///
/// # Arguments
///
/// * `customer_id` - Optional customer ID to filter by
/// * `date_range` - Time period for the query.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use alguna::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// api_key: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Alguna::new(config).expect("Failed to build client");
/// client
/// .insights
/// .revenue_by_product(
/// &RevenueByProductQueryRequest {
/// customer_id: Some("cust_abc123".to_string()),
/// date_range: RevenueByProductInsightsRequestDateRange::ThisMonth,
/// },
/// None,
/// )
/// .await;
/// }
/// ```
pub async fn revenue_by_product(
&self,
request: &RevenueByProductQueryRequest,
options: Option<RequestOptions>,
) -> Result<RevenueByProductResponse, ApiError> {
self.http_client
.execute_request(
Method::GET,
"insights/revenue/by-product",
None,
QueryBuilder::new()
.string("customer_id", request.customer_id.clone())
.serialize("date_range", Some(request.date_range.clone()))
.build(),
options,
)
.await
}
/// Returns a time series of net revenue data points split into fixed and metered components. Resolution (daily or monthly) is automatically determined by the date range.
///
/// # Arguments
///
/// * `date_range` - Time period for the query. Determines the primary period and automatically calculates a comparison period.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use alguna::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// api_key: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Alguna::new(config).expect("Failed to build client");
/// client
/// .insights
/// .revenue_over_time(
/// &RevenueOverTimeQueryRequest {
/// date_range: RevenueOverTimeInsightsRequestDateRange::ThisMonth,
/// },
/// None,
/// )
/// .await;
/// }
/// ```
pub async fn revenue_over_time(
&self,
request: &RevenueOverTimeQueryRequest,
options: Option<RequestOptions>,
) -> Result<AmountsOverTimeResponse, ApiError> {
self.http_client
.execute_request(
Method::GET,
"insights/revenue/over-time",
None,
QueryBuilder::new()
.serialize("date_range", Some(request.date_range.clone()))
.build(),
options,
)
.await
}
/// Returns the monthly recurring revenue (MRR), annual recurring revenue (ARR), and annual contract value (ACV) for a single subscription.
///
/// # Arguments
///
/// * `id` - Unique identifier for the subscription
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use alguna::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// api_key: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Alguna::new(config).expect("Failed to build client");
/// client
/// .insights
/// .revenue_by_subscription(&"id".to_string(), None)
/// .await;
/// }
/// ```
pub async fn revenue_by_subscription(
&self,
id: &str,
options: Option<RequestOptions>,
) -> Result<RevenueBySubscriptionResponse, ApiError> {
self.http_client
.execute_request(
Method::GET,
&format!("insights/revenue/subscription/{}", id),
None,
None,
options,
)
.await
}
}