Skip to content

Commit 7df8be5

Browse files
docs: update examples
1 parent fbcbfe3 commit 7df8be5

18 files changed

Lines changed: 637 additions & 0 deletions

src/resources/coupons/coupons.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ export class Coupons extends APIResource {
1717
/**
1818
* This endpoint allows the creation of coupons, which can then be redeemed at
1919
* subscription creation or plan change.
20+
*
21+
* @example
22+
* ```ts
23+
* const coupon = await client.coupons.create({
24+
* discount: {
25+
* discount_type: 'percentage',
26+
* percentage_discount: 0,
27+
* },
28+
* redemption_code: 'HALFOFF',
29+
* });
30+
* ```
2031
*/
2132
create(body: CouponCreateParams, options?: Core.RequestOptions): Core.APIPromise<Coupon> {
2233
return this._client.post('/coupons', { body, ...options });
@@ -28,6 +39,14 @@ export class Coupons extends APIResource {
2839
* The list of coupons is ordered starting from the most recently created coupon.
2940
* The response also includes `pagination_metadata`, which lets the caller retrieve
3041
* the next page of results if they exist.
42+
*
43+
* @example
44+
* ```ts
45+
* // Automatically fetches more pages as needed.
46+
* for await (const coupon of client.coupons.list()) {
47+
* // ...
48+
* }
49+
* ```
3150
*/
3251
list(query?: CouponListParams, options?: Core.RequestOptions): Core.PagePromise<CouponsPage, Coupon>;
3352
list(options?: Core.RequestOptions): Core.PagePromise<CouponsPage, Coupon>;
@@ -45,6 +64,11 @@ export class Coupons extends APIResource {
4564
* This endpoint allows a coupon to be archived. Archived coupons can no longer be
4665
* redeemed, and will be hidden from lists of active coupons. Additionally, once a
4766
* coupon is archived, its redemption code can be reused for a different coupon.
67+
*
68+
* @example
69+
* ```ts
70+
* const coupon = await client.coupons.archive('coupon_id');
71+
* ```
4872
*/
4973
archive(couponId: string, options?: Core.RequestOptions): Core.APIPromise<Coupon> {
5074
return this._client.post(`/coupons/${couponId}/archive`, options);
@@ -54,6 +78,11 @@ export class Coupons extends APIResource {
5478
* This endpoint retrieves a coupon by its ID. To fetch coupons by their redemption
5579
* code, use the [List coupons](list-coupons) endpoint with the redemption_code
5680
* parameter.
81+
*
82+
* @example
83+
* ```ts
84+
* const coupon = await client.coupons.fetch('coupon_id');
85+
* ```
5786
*/
5887
fetch(couponId: string, options?: Core.RequestOptions): Core.APIPromise<Coupon> {
5988
return this._client.get(`/coupons/${couponId}`, options);

src/resources/coupons/subscriptions.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ export class Subscriptions extends APIResource {
1616
* coupon as a [paginated](/api-reference/pagination) list, ordered starting from
1717
* the most recently created subscription. For a full discussion of the
1818
* subscription resource, see [Subscription](/core-concepts#subscription).
19+
*
20+
* @example
21+
* ```ts
22+
* // Automatically fetches more pages as needed.
23+
* for await (const subscription of client.coupons.subscriptions.list(
24+
* 'coupon_id',
25+
* )) {
26+
* // ...
27+
* }
28+
* ```
1929
*/
2030
list(
2131
couponId: string,

src/resources/credit-notes.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ export class CreditNotes extends APIResource {
4040
* Note: Both start_date and end_date are inclusive - the service period will cover
4141
* both the start date and end date completely (from start of start_date to end of
4242
* end_date).
43+
*
44+
* @example
45+
* ```ts
46+
* const creditNote = await client.creditNotes.create({
47+
* line_items: [
48+
* {
49+
* amount: 'amount',
50+
* invoice_line_item_id: '4khy3nwzktxv7',
51+
* },
52+
* ],
53+
* reason: 'duplicate',
54+
* });
55+
* ```
4356
*/
4457
create(body: CreditNoteCreateParams, options?: Core.RequestOptions): Core.APIPromise<Shared.CreditNote> {
4558
return this._client.post('/credit_notes', { body, ...options });
@@ -49,6 +62,14 @@ export class CreditNotes extends APIResource {
4962
* Get a paginated list of CreditNotes. Users can also filter by customer_id,
5063
* subscription_id, or external_customer_id. The credit notes will be returned in
5164
* reverse chronological order by `creation_time`.
65+
*
66+
* @example
67+
* ```ts
68+
* // Automatically fetches more pages as needed.
69+
* for await (const creditNote of client.creditNotes.list()) {
70+
* // ...
71+
* }
72+
* ```
5273
*/
5374
list(
5475
query?: CreditNoteListParams,
@@ -68,6 +89,13 @@ export class CreditNotes extends APIResource {
6889
/**
6990
* This endpoint is used to fetch a single [`Credit Note`](/invoicing/credit-notes)
7091
* given an identifier.
92+
*
93+
* @example
94+
* ```ts
95+
* const creditNote = await client.creditNotes.fetch(
96+
* 'credit_note_id',
97+
* );
98+
* ```
7199
*/
72100
fetch(creditNoteId: string, options?: Core.RequestOptions): Core.APIPromise<Shared.CreditNote> {
73101
return this._client.get(`/credit_notes/${creditNoteId}`, options);

src/resources/dimensional-price-groups/dimensional-price-groups.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ export class DimensionalPriceGroups extends APIResource {
2424
* widgets used and we want to charge differently depending on the color of the
2525
* widget. We can create a price group with a dimension "color" and two prices: one
2626
* that charges \$10 per red widget and one that charges \$20 per blue widget.
27+
*
28+
* @example
29+
* ```ts
30+
* const dimensionalPriceGroup =
31+
* await client.dimensionalPriceGroups.create({
32+
* billable_metric_id: 'billable_metric_id',
33+
* dimensions: ['region', 'instance_type'],
34+
* name: 'name',
35+
* });
36+
* ```
2737
*/
2838
create(
2939
body: DimensionalPriceGroupCreateParams,
@@ -34,6 +44,14 @@ export class DimensionalPriceGroups extends APIResource {
3444

3545
/**
3646
* Fetch dimensional price group
47+
*
48+
* @example
49+
* ```ts
50+
* const dimensionalPriceGroup =
51+
* await client.dimensionalPriceGroups.retrieve(
52+
* 'dimensional_price_group_id',
53+
* );
54+
* ```
3755
*/
3856
retrieve(
3957
dimensionalPriceGroupId: string,
@@ -46,6 +64,14 @@ export class DimensionalPriceGroups extends APIResource {
4664
* This endpoint can be used to update the `external_dimensional_price_group_id`
4765
* and `metadata` of an existing dimensional price group. Other fields on a
4866
* dimensional price group are currently immutable.
67+
*
68+
* @example
69+
* ```ts
70+
* const dimensionalPriceGroup =
71+
* await client.dimensionalPriceGroups.update(
72+
* 'dimensional_price_group_id',
73+
* );
74+
* ```
4975
*/
5076
update(
5177
dimensionalPriceGroupId: string,
@@ -57,6 +83,14 @@ export class DimensionalPriceGroups extends APIResource {
5783

5884
/**
5985
* List dimensional price groups
86+
*
87+
* @example
88+
* ```ts
89+
* // Automatically fetches more pages as needed.
90+
* for await (const dimensionalPriceGroup of client.dimensionalPriceGroups.list()) {
91+
* // ...
92+
* }
93+
* ```
6094
*/
6195
list(
6296
query?: DimensionalPriceGroupListParams,

src/resources/dimensional-price-groups/external-dimensional-price-group-id.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ import * as DimensionalPriceGroupsAPI from './dimensional-price-groups';
77
export class ExternalDimensionalPriceGroupID extends APIResource {
88
/**
99
* Fetch dimensional price group by external ID
10+
*
11+
* @example
12+
* ```ts
13+
* const dimensionalPriceGroup =
14+
* await client.dimensionalPriceGroups.externalDimensionalPriceGroupId.retrieve(
15+
* 'external_dimensional_price_group_id',
16+
* );
17+
* ```
1018
*/
1119
retrieve(
1220
externalDimensionalPriceGroupId: string,
@@ -22,6 +30,14 @@ export class ExternalDimensionalPriceGroupID extends APIResource {
2230
* This endpoint can be used to update the `external_dimensional_price_group_id`
2331
* and `metadata` of an existing dimensional price group. Other fields on a
2432
* dimensional price group are currently immutable.
33+
*
34+
* @example
35+
* ```ts
36+
* const dimensionalPriceGroup =
37+
* await client.dimensionalPriceGroups.externalDimensionalPriceGroupId.update(
38+
* 'external_dimensional_price_group_id',
39+
* );
40+
* ```
2541
*/
2642
update(
2743
externalDimensionalPriceGroupId: string,

src/resources/events/backfills.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ export class Backfills extends APIResource {
5252
*
5353
* You may not have multiple backfills in a pending or pending_revert state with
5454
* overlapping timeframes.
55+
*
56+
* @example
57+
* ```ts
58+
* const backfill = await client.events.backfills.create({
59+
* timeframe_end: '2019-12-27T18:11:19.117Z',
60+
* timeframe_start: '2019-12-27T18:11:19.117Z',
61+
* });
62+
* ```
5563
*/
5664
create(body: BackfillCreateParams, options?: Core.RequestOptions): Core.APIPromise<BackfillCreateResponse> {
5765
return this._client.post('/events/backfills', { body, ...options });
@@ -64,6 +72,14 @@ export class Backfills extends APIResource {
6472
* backfill. The response also includes
6573
* [`pagination_metadata`](/api-reference/pagination), which lets the caller
6674
* retrieve the next page of results if they exist.
75+
*
76+
* @example
77+
* ```ts
78+
* // Automatically fetches more pages as needed.
79+
* for await (const backfillListResponse of client.events.backfills.list()) {
80+
* // ...
81+
* }
82+
* ```
6783
*/
6884
list(
6985
query?: BackfillListParams,
@@ -85,13 +101,27 @@ export class Backfills extends APIResource {
85101
* backfill, Orb will asynchronously reflect the updated usage in invoice amounts
86102
* and usage graphs. Once all of the updates are complete, the backfill's status
87103
* will transition to `reflected`.
104+
*
105+
* @example
106+
* ```ts
107+
* const response = await client.events.backfills.close(
108+
* 'backfill_id',
109+
* );
110+
* ```
88111
*/
89112
close(backfillId: string, options?: Core.RequestOptions): Core.APIPromise<BackfillCloseResponse> {
90113
return this._client.post(`/events/backfills/${backfillId}/close`, options);
91114
}
92115

93116
/**
94117
* This endpoint is used to fetch a backfill given an identifier.
118+
*
119+
* @example
120+
* ```ts
121+
* const response = await client.events.backfills.fetch(
122+
* 'backfill_id',
123+
* );
124+
* ```
95125
*/
96126
fetch(backfillId: string, options?: Core.RequestOptions): Core.APIPromise<BackfillFetchResponse> {
97127
return this._client.get(`/events/backfills/${backfillId}`, options);
@@ -105,6 +135,13 @@ export class Backfills extends APIResource {
105135
*
106136
* If a backfill is reverted before its closed, no usage will be updated as a
107137
* result of the backfill and it will immediately transition to `reverted`.
138+
*
139+
* @example
140+
* ```ts
141+
* const response = await client.events.backfills.revert(
142+
* 'backfill_id',
143+
* );
144+
* ```
108145
*/
109146
revert(backfillId: string, options?: Core.RequestOptions): Core.APIPromise<BackfillRevertResponse> {
110147
return this._client.post(`/events/backfills/${backfillId}/revert`, options);

src/resources/events/events.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ export class Events extends APIResource {
7272
* - By default, no more than 100 events can be amended for a single customer in a
7373
* 100 day period. For higher volume updates, consider using the
7474
* [event backfill](create-backfill) endpoint.
75+
*
76+
* @example
77+
* ```ts
78+
* const event = await client.events.update('event_id', {
79+
* event_name: 'event_name',
80+
* properties: { foo: 'bar' },
81+
* timestamp: '2020-12-09T16:09:53Z',
82+
* });
83+
* ```
7584
*/
7685
update(
7786
eventId: string,
@@ -122,6 +131,11 @@ export class Events extends APIResource {
122131
* - By default, no more than 100 events can be deprecated for a single customer in
123132
* a 100 day period. For higher volume updates, consider using the
124133
* [event backfill](create-backfill) endpoint.
134+
*
135+
* @example
136+
* ```ts
137+
* const response = await client.events.deprecate('event_id');
138+
* ```
125139
*/
126140
deprecate(eventId: string, options?: Core.RequestOptions): Core.APIPromise<EventDeprecateResponse> {
127141
return this._client.put(`/events/${eventId}/deprecate`, options);
@@ -332,6 +346,20 @@ export class Events extends APIResource {
332346
* "validation_failed": []
333347
* }
334348
* ```
349+
*
350+
* @example
351+
* ```ts
352+
* const response = await client.events.ingest({
353+
* events: [
354+
* {
355+
* event_name: 'event_name',
356+
* idempotency_key: 'idempotency_key',
357+
* properties: { foo: 'bar' },
358+
* timestamp: '2020-12-09T16:09:53Z',
359+
* },
360+
* ],
361+
* });
362+
* ```
335363
*/
336364
ingest(params: EventIngestParams, options?: Core.RequestOptions): Core.APIPromise<EventIngestResponse> {
337365
const { backfill_id, debug, ...body } = params;
@@ -354,6 +382,13 @@ export class Events extends APIResource {
354382
*
355383
* By default, Orb will not throw a `404` if no events matched, Orb will return an
356384
* empty array for `data` instead.
385+
*
386+
* @example
387+
* ```ts
388+
* const response = await client.events.search({
389+
* event_ids: ['string'],
390+
* });
391+
* ```
357392
*/
358393
search(body: EventSearchParams, options?: Core.RequestOptions): Core.APIPromise<EventSearchResponse> {
359394
return this._client.post('/events/search', { body, ...options });

src/resources/events/volume.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ export class Volume extends APIResource {
2323
* where the start and end time are hour-aligned and in UTC. When a specific
2424
* timestamp is passed in for either start or end time, the response includes the
2525
* hours the timestamp falls in.
26+
*
27+
* @example
28+
* ```ts
29+
* const eventVolumes = await client.events.volume.list({
30+
* timeframe_start: '2019-12-27T18:11:19.117Z',
31+
* });
32+
* ```
2633
*/
2734
list(query: VolumeListParams, options?: Core.RequestOptions): Core.APIPromise<EventVolumes> {
2835
return this._client.get('/events/volume', { query, ...options });

src/resources/invoice-line-items.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ export class InvoiceLineItems extends APIResource {
2525
* - If both `item_id` and `name` are provided: The item is looked up by ID for
2626
* association, but the provided `name` is used for the line item (not the item's
2727
* name).
28+
*
29+
* @example
30+
* ```ts
31+
* const invoiceLineItem =
32+
* await client.invoiceLineItems.create({
33+
* amount: '12.00',
34+
* end_date: '2023-09-22',
35+
* invoice_id: '4khy3nwzktxv7',
36+
* quantity: 1,
37+
* start_date: '2023-09-22',
38+
* });
39+
* ```
2840
*/
2941
create(
3042
body: InvoiceLineItemCreateParams,

0 commit comments

Comments
 (0)