-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenapi.yaml
More file actions
743 lines (688 loc) · 23.6 KB
/
openapi.yaml
File metadata and controls
743 lines (688 loc) · 23.6 KB
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
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
openapi: 3.1.0
info:
title: Chargebee Billing API
version: "2024-01"
description: |
The Chargebee Billing API lets you manage the full subscription lifecycle —
create and update subscriptions, collect payments, issue invoices, and
handle revenue recognition.
## Authentication
All requests use HTTP Basic Auth. Pass your API key as the username with
an empty password:
```bash
curl https://your-site.chargebee.com/api/v2/subscriptions \
-u your_api_key:
```
Your API key is scoped to a Chargebee site. Use test-site keys for
development and live-site keys for production.
## Base URL
```
https://{site}.chargebee.com/api/v2
```
Replace `{site}` with your Chargebee site name.
## Versioning
The API version is set per request using the `chargebee-version` header.
If omitted, the default version for your site is used. We recommend
pinning to a specific version in production.
```
chargebee-version: 2024-01-01
```
## Pagination
List endpoints return a maximum of 100 results. Use `next_offset` from
the response to retrieve the next page:
```bash
curl "https://your-site.chargebee.com/api/v2/subscriptions?limit=25&offset={next_offset}"
```
## Errors
Chargebee uses standard HTTP status codes. All errors return a JSON
body with `api_error_code`, `message`, and `error_code` fields.
See [Error Codes](#section/Error-Codes) for a full taxonomy.
contact:
name: Chargebee Developer Support
url: https://www.chargebee.com/docs/
email: support@chargebee.com
license:
name: Proprietary
servers:
- url: https://{site}.chargebee.com/api/v2
description: Production
variables:
site:
default: your-site
description: Your Chargebee site name
tags:
- name: Subscriptions
description: |
Manage the full subscription lifecycle — create, update, cancel,
pause, and reactivate subscriptions. A subscription ties a customer
to a plan and drives all downstream billing events.
- name: Invoices
description: |
Invoices represent finalized billing events. They are created
automatically at the end of each billing cycle or manually via
the API. Once created, invoices can be voided but not deleted.
- name: Customers
description: |
Customer records store billing identity and payment methods.
A customer can have multiple subscriptions.
- name: Plans
description: |
Plans define pricing, billing frequency, and trial settings.
Customers subscribe to plans.
paths:
# ── SUBSCRIPTIONS ──────────────────────────────────────────────
/subscriptions:
get:
operationId: list-subscriptions
summary: List subscriptions
description: |
Returns a paginated list of subscriptions. Filter by `customer_id`,
`status`, or `plan_id` to narrow results.
Results are sorted by creation date, descending.
tags: [Subscriptions]
parameters:
- name: limit
in: query
description: Number of results to return. Maximum 100.
schema:
type: integer
minimum: 1
maximum: 100
default: 10
- name: offset
in: query
description: |
Pagination cursor. Pass the `next_offset` value from a
previous response to retrieve the next page.
schema:
type: string
- name: customer_id[is]
in: query
description: Filter by customer ID (exact match).
schema:
type: string
example: cus_KmQ9xT4pRw2v
- name: status[is]
in: query
description: Filter by subscription status.
schema:
$ref: '#/components/schemas/SubscriptionStatus'
- name: plan_id[is]
in: query
description: Filter by plan ID.
schema:
type: string
responses:
"200":
description: A paginated list of subscriptions.
content:
application/json:
schema:
type: object
properties:
list:
type: array
items:
type: object
properties:
subscription:
$ref: '#/components/schemas/Subscription'
next_offset:
type: string
nullable: true
description: |
Cursor for the next page. `null` if this is the last page.
example:
list:
- subscription:
id: sub_HxKtL3QmVr9p
customer_id: cus_KmQ9xT4pRw2v
plan_id: plan_pro_monthly
status: active
current_term_start: 1704067200
current_term_end: 1706745600
created_at: 1704067200
currency_code: USD
next_offset: null
"400":
$ref: '#/components/responses/BadRequest'
"401":
$ref: '#/components/responses/Unauthorized'
post:
operationId: create-subscription
summary: Create a subscription
description: |
Creates a new subscription for an existing customer. If the plan has
a trial period, the subscription starts in `in_trial` status.
Otherwise it moves to `active` immediately.
### What happens at creation
1. The subscription is created in `in_trial` or `active` status.
2. If the plan has an immediate charge (setup fee or first billing
cycle), an invoice is generated.
3. If payment collection is configured, Chargebee attempts to collect
the invoice immediately.
### Idempotency
Pass an `Idempotency-Key` header to safely retry failed requests
without creating duplicate subscriptions.
tags: [Subscriptions]
requestBody:
required: true
content:
application/x-www-form-urlencoded:
schema:
type: object
required: [plan_id, customer_id]
properties:
plan_id:
type: string
description: ID of the plan to subscribe to.
example: plan_pro_monthly
customer_id:
type: string
description: ID of the customer to subscribe.
example: cus_KmQ9xT4pRw2v
plan_quantity:
type: integer
description: |
Quantity of plan units. Required for per-seat plans.
Defaults to 1.
minimum: 1
default: 1
trial_end:
type: integer
description: |
Unix timestamp for a custom trial end date. Overrides
the plan's default trial period. Must be in the future.
auto_collection:
type: string
enum: [on, off]
description: |
Whether to automatically collect payment at renewal.
Defaults to the customer's `auto_collection` setting.
responses:
"200":
description: Subscription created successfully.
content:
application/json:
schema:
type: object
properties:
subscription:
$ref: '#/components/schemas/Subscription'
customer:
$ref: '#/components/schemas/Customer'
invoice:
$ref: '#/components/schemas/Invoice'
nullable: true
description: |
The invoice generated at creation, if any. `null` if
no immediate charge was applicable.
"400":
$ref: '#/components/responses/BadRequest'
"401":
$ref: '#/components/responses/Unauthorized'
"404":
$ref: '#/components/responses/NotFound'
/subscriptions/{subscription_id}:
get:
operationId: retrieve-subscription
summary: Retrieve a subscription
description: Returns a single subscription by ID.
tags: [Subscriptions]
parameters:
- $ref: '#/components/parameters/SubscriptionId'
responses:
"200":
description: Subscription retrieved successfully.
content:
application/json:
schema:
type: object
properties:
subscription:
$ref: '#/components/schemas/Subscription'
"401":
$ref: '#/components/responses/Unauthorized'
"404":
$ref: '#/components/responses/NotFound'
/subscriptions/{subscription_id}/cancel:
post:
operationId: cancel-subscription
summary: Cancel a subscription
description: |
Cancels an active or in-trial subscription.
### Cancellation timing
By default, the subscription cancels at the end of the current
billing term (`end_of_term: true`). The subscription moves to
`non_renewing` status and access continues until term end.
To cancel immediately, pass `end_of_term: false`. The subscription
moves to `cancelled` status immediately and any unused days are
credited based on your proration settings.
### Dunning
If a subscription is in `active` status but has an unpaid invoice,
cancelling immediately attempts final payment collection before
cancelling.
tags: [Subscriptions]
parameters:
- $ref: '#/components/parameters/SubscriptionId'
requestBody:
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
end_of_term:
type: boolean
default: true
description: |
`true` — cancel at the end of the current billing term.
`false` — cancel immediately.
cancel_reason_code:
type: string
description: |
Reason for cancellation. Used in churn analytics.
Must match a code configured in your Chargebee site.
responses:
"200":
description: Subscription cancelled successfully.
content:
application/json:
schema:
type: object
properties:
subscription:
$ref: '#/components/schemas/Subscription'
"400":
$ref: '#/components/responses/BadRequest'
"401":
$ref: '#/components/responses/Unauthorized'
"404":
$ref: '#/components/responses/NotFound'
# ── INVOICES ───────────────────────────────────────────────────
/invoices:
get:
operationId: list-invoices
summary: List invoices
description: |
Returns a paginated list of invoices. Voided invoices are included
by default. To exclude them from revenue reporting, filter by
`status[is_not]=voided`.
tags: [Invoices]
parameters:
- name: limit
in: query
schema:
type: integer
minimum: 1
maximum: 100
default: 10
- name: customer_id[is]
in: query
schema:
type: string
- name: status[is]
in: query
schema:
$ref: '#/components/schemas/InvoiceStatus'
- name: status[is_not]
in: query
description: Exclude invoices with this status.
schema:
$ref: '#/components/schemas/InvoiceStatus'
- name: date[after]
in: query
description: Filter invoices created after this Unix timestamp.
schema:
type: integer
responses:
"200":
description: A paginated list of invoices.
content:
application/json:
schema:
type: object
properties:
list:
type: array
items:
type: object
properties:
invoice:
$ref: '#/components/schemas/Invoice'
next_offset:
type: string
nullable: true
"401":
$ref: '#/components/responses/Unauthorized'
/invoices/{invoice_id}:
get:
operationId: retrieve-invoice
summary: Retrieve an invoice
description: Returns a single invoice by ID.
tags: [Invoices]
parameters:
- name: invoice_id
in: path
required: true
schema:
type: string
example: inv_KmQ9xT4pRw2v
responses:
"200":
description: Invoice retrieved successfully.
content:
application/json:
schema:
type: object
properties:
invoice:
$ref: '#/components/schemas/Invoice'
"401":
$ref: '#/components/responses/Unauthorized'
"404":
$ref: '#/components/responses/NotFound'
# ── COMPONENTS ─────────────────────────────────────────────────
components:
securitySchemes:
basicAuth:
type: http
scheme: basic
description: |
HTTP Basic Auth. Pass your API key as the username, leave the
password empty.
parameters:
SubscriptionId:
name: subscription_id
in: path
required: true
description: Unique identifier for the subscription. Prefix `sub_`.
schema:
type: string
example: sub_HxKtL3QmVr9p
schemas:
SubscriptionStatus:
type: string
enum:
- future
- in_trial
- active
- non_renewing
- paused
- cancelled
description: |
The subscription's current state in the lifecycle.
| Status | Description |
|---|---|
| `future` | Created but start date is in the future. |
| `in_trial` | Within the trial period. No charge yet. |
| `active` | Billing normally. Renews at `current_term_end`. |
| `non_renewing` | Scheduled to cancel at `current_term_end`. |
| `paused` | Billing paused. Resumes at `resume_date`. |
| `cancelled` | Terminated. No further billing. |
InvoiceStatus:
type: string
enum:
- paid
- posted
- payment_due
- not_paid
- voided
- pending
description: |
| Status | Description |
|---|---|
| `paid` | Payment collected. |
| `posted` | Issued but not yet due. |
| `payment_due` | Due but not yet collected. |
| `not_paid` | Collection failed after dunning. |
| `voided` | Cancelled. Excluded from revenue. |
| `pending` | Draft — line items still being added. |
Subscription:
type: object
description: |
Represents an ongoing billing relationship between a customer and
a plan. Subscriptions drive invoice generation, renewal, and
access control.
properties:
id:
type: string
description: Unique identifier. Prefix `sub_`.
example: sub_HxKtL3QmVr9p
customer_id:
type: string
description: ID of the customer this subscription belongs to.
example: cus_KmQ9xT4pRw2v
plan_id:
type: string
description: ID of the plan the customer is subscribed to.
example: plan_pro_monthly
status:
$ref: '#/components/schemas/SubscriptionStatus'
plan_quantity:
type: integer
description: Number of plan units. Relevant for per-seat plans.
example: 5
current_term_start:
type: integer
description: Unix timestamp for the start of the current billing term.
example: 1704067200
current_term_end:
type: integer
description: |
Unix timestamp for the end of the current billing term.
An invoice is generated at this time unless the subscription
is in `non_renewing` or `cancelled` status.
example: 1706745600
trial_start:
type: integer
nullable: true
description: Unix timestamp for trial start. `null` if no trial.
example: null
trial_end:
type: integer
nullable: true
description: Unix timestamp for trial end. `null` if no trial.
example: null
cancelled_at:
type: integer
nullable: true
description: Unix timestamp of cancellation. `null` if active.
currency_code:
type: string
description: ISO 4217 currency code.
example: USD
created_at:
type: integer
description: Unix timestamp of subscription creation.
example: 1704067200
updated_at:
type: integer
description: Unix timestamp of last update.
example: 1704153600
metadata:
type: object
nullable: true
description: |
Key-value store for your own data. Up to 20 keys.
Values must be strings.
additionalProperties:
type: string
Invoice:
type: object
description: |
Represents a finalized billing event. Created automatically at
renewal or manually via the API. Invoices cannot be deleted —
only voided.
> **Tip:** Voided invoices are excluded from MRR and ARR
> calculations. Always filter `status != voided` for revenue
> reporting.
properties:
id:
type: string
description: Unique identifier. Prefix `inv_`.
example: inv_KmQ9xT4pRw2v
customer_id:
type: string
example: cus_KmQ9xT4pRw2v
subscription_id:
type: string
nullable: true
description: |
ID of the related subscription. `null` for one-off invoices.
example: sub_HxKtL3QmVr9p
status:
$ref: '#/components/schemas/InvoiceStatus'
amount_due:
type: integer
description: |
Total amount due, in the smallest currency unit (cents for USD).
Use `currency_code` to format for display.
example: 4900
amount_paid:
type: integer
description: Amount already collected, in smallest currency unit.
example: 4900
amount_adjusted:
type: integer
description: Total credits or adjustments applied.
example: 0
currency_code:
type: string
example: USD
due_date:
type: integer
nullable: true
description: |
Unix timestamp for payment due date. `null` for
immediate-payment invoices.
line_items:
type: array
description: Individual charges making up the invoice total.
items:
type: object
properties:
id:
type: string
example: li_HxKtL3QmVr9p
description:
type: string
example: Pro Plan — Jan 2024
unit_amount:
type: integer
example: 4900
quantity:
type: integer
example: 1
amount:
type: integer
example: 4900
entity_type:
type: string
enum: [plan, addon, adhoc, plan_item_price, addon_item_price]
created_at:
type: integer
example: 1704067200
updated_at:
type: integer
example: 1704153600
Customer:
type: object
description: |
A customer record stores billing identity, contact info, and
payment methods. One customer can have multiple subscriptions.
properties:
id:
type: string
description: Unique identifier. Prefix `cus_`.
example: cus_KmQ9xT4pRw2v
email:
type: string
format: email
example: dev@example.com
first_name:
type: string
nullable: true
example: Alex
last_name:
type: string
nullable: true
example: Rivera
company:
type: string
nullable: true
example: Acme Corp
auto_collection:
type: string
enum: [on, off]
description: |
Whether Chargebee automatically collects payment for this
customer's invoices. Can be overridden per subscription.
created_at:
type: integer
example: 1704067200
Error:
type: object
description: Error response body returned for all 4xx and 5xx responses.
properties:
api_error_code:
type: string
description: Machine-readable error code. Use this for programmatic handling.
example: resource_not_found
message:
type: string
description: Human-readable error message. Do not parse for logic.
example: Subscription sub_HxKtL3QmVr9p not found.
error_code:
type: integer
description: Chargebee internal error code. For support reference.
example: 104
http_status_code:
type: integer
description: HTTP status code.
example: 404
type:
type: string
enum: [payment, operation, invalid_request, io_exception]
responses:
BadRequest:
description: |
The request was malformed or missing required parameters.
Check `api_error_code` and `message` for specifics.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
example:
api_error_code: param_missing
message: "Required parameter missing: plan_id"
error_code: 100
http_status_code: 400
type: invalid_request
Unauthorized:
description: |
Authentication failed. Verify your API key is correct and
scoped to the right site (test vs. live).
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
example:
api_error_code: api_authentication_failed
message: API key is invalid or does not match the site.
error_code: 10000
http_status_code: 401
type: operation
NotFound:
description: The requested resource does not exist.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
example:
api_error_code: resource_not_found
message: Subscription sub_HxKtL3QmVr9p not found.
error_code: 104
http_status_code: 404
type: operation
security:
- basicAuth: []