Backend API
Invoices are created automatically when a subscription is charged. An invoice captures the billing period of a subscription, including the subscription plan and line items prices. Payments are applied directly to an invoice.
Fields
id
objectIdUnique identifier for the invoice.
account_id
objectIdrequiredID of the customer's account.
account
AccountExpandable link to the customer's account.
closed
booleanWhen true, it indicates no further attempts will be made to capture payment for the invoice.
coupon
CouponExpandable link to the coupon applied to the invoice.
coupon_code
stringCoupon code applied to the invoice.
coupon_id
objectIdID of the coupon applied to the invoice.
credits
Credit memoExpandable list of account credit transactions. Balance of these transactions is kept in balance.
credit_total
currencyTotal amount of additional credit applied to the order.
currency
stringThree-letter ISO currency code in uppercase. Defaults to the store's base currency.
currency_rate
floatCurrency percentage used in calculating the fixed amount.
date_created
dateautoDate and time the invoice was created.
date_due
dateThe date by which the invoice is to be paid.
date_payment_retry
dateDate the next automatic payment will be attempted.
date_period_end
dateEnd date of the subscription billing period for the invoice.
date_period_start
dateStart date of the subscription billing period for the invoice.
date_updated
dateautoDate and time the invoice was last updated.
discount_total
currencyautoTotal discount amount.
discounts
array of objectList of all discounts applied to the invoice.
id
stringUnique identifier for the object.
amount
currencyFixed discount amount.
rule
objectObject describing the discount rule details. Custom discounts don't require this value.
type
stringType of discount. Can be coupon or sale referring to the source of the discount. Custom discounts don't require this value.
grand_total
currencyautoGrand total including items and taxes.
item_discount
currencyautoSum of all line items before discounts and taxes.
item_tax_included
booleanIndicates line item prices include taxes.
item_tax
currencyautoTotal taxes applied to line items.
item_quantity
intautoTotal quantity of all line items.
item_quantity_creditable
intQuantity of creditable items on the order.
items
array of objectList of invoice line items.
id
objectIdUnique identifier for the object.
bundle_items
array of objectList of bundled items, if applicable.
.id
objectIdUnique identifier for the object.
.product_id
objectIdID of the bundled product.
.product
productExpandable link to the bundled product.
.quantity
intQuantity of the bundled item.
.quantity_total
intTotal quantity of the bundled item (items.quantity * bundle_items.quantity).
.variant_id
objectIdID of the bundled product variant.
.variant
variantExpandable link to the bundled product variant.
description
stringDescription used for custom line items, when product is not defined.
discount_each
currencyTotal discount amount divided by quantity.
discount_total
currencyTotal discount applied to the item.
discounts
array of objectList of discounts to be applied to the line items.
id
stringID of the promotion or discount to apply.
amount
currencyAmount of the discount to apply
options
array of objectLine item options, if applicable.
id
stringUnique identifier for the object.
name
stringName of the option.
value
stringValue of the option.
price
currencyPrice of the line item.
price_total
currencyOriginal item price used internally to determine if the item price was overridden and should be automatically updated when item options are changed.
product_id
objectIdID of the line item product.
product
productExpandable link to the line item product.
quantity
intQuantity of the line item.
taxes
array of objectList of taxes applied to the invoice line items.
.id
stringUnique identifier for the object.
.amount
currencyFixed tax amount.
tax_each
currencyTotal tax amount divided by quantity.
tax_total
currencyTotal tax applied to the item.
variant_id
objectIdID of the line item product variant.
variant
variantExpandable link to the line item product variant.
quantity_creditable
intQuantity of items eligible to be credited.
quantity_credited
intQuantity of items credited on the order.
net_days
intNet number of days for which the invoice is open before being considered past due.
notes
stringInternal admin notes, not visible to the customer.
number
stringautoUnique incremental invoice number, assigned automatically.
order
OrderExpandable link to the order the invoice was applied to, if applicable.
order_id
objectIdID of the order the invoice was applied to, if applicable.
paid
booleanautoIndicates the invoice was paid in full.
pastdue
booleanIndicates the invoice payment is past due.
payment_due
currencyautoPayment amount due on the invoice.
payment_error
stringA message describing the last payment error, if one occurred.
payment_retry_count
intThe number of times automatic payment has been attempted.
payment_retry_resolve
stringThe method used to resolve automatic payment when all retry attempts are exhausted. Can be blank (do nothing), canceled, or unpaid.
payment_total
currencySum of payments applied to the order, not including refunds.
payments
PaymentrequiredExpandable list of payments applied to the invoice.
refunds
RefundExpandable list of refunds applied to the invoice.
shipment_tax
currencyShipping tax amount, if applicable.
shipment_tax_included
booleanIndicates shipping total includes taxes, if applicable.
shipment_tax_included_total
currencyTotal of taxes applied separately from line items.
shipment_total
currencyTotal shipping price after discounts.
source
ProductExpands into the corresponding order or subscription using source_model and source_id.
source_id
objectIdUsed to expand source into corresponding order or subscription. Equal to order_id. If order_id is not set, then equal to subscription_id. If order_id nor subscription_id are set, is null.
source_model
stringUsed to expand source into corresponding order or subscription. If order_id is set, equals orders. If subscription_id is set, equals subscriptions. When neither is set, is null.
status
enumautoCurrent status of the invoice. Can be pending, paid, or unpaid.
Possible enum values:
sub_total
currencyautoSum of all line items before discounts, taxes and shipping.
subscription
SubscriptionExpandable link to the subscription the invoice was issued for.
subscription_id
objectIdID of the subscription the invoice was issued for.
tax_included_total
currencyautoTotal of taxes applied separately from line items.
tax_total
currencyautoTotal tax amount applied to the order including line items.
taxes
array of objectList of taxes applied to the order.
id
stringUnique identifier for the object.
name
stringName of the tax rule. For example, "NY Sales Tax".
shipping
booleanIndicates the tax applies to shipping.
priority
intPriority indicates the order in which a tax rule was applied. Higher priority rules are added on top of other tax rules with a lower priority. Rules with the same priority are calculated excluding each other.
rate
floatTax percentage used in calculating the fixed amount.
amount
currencyFixed tax amount.
The invoice model
{
"id": "60f199509111e7000000002f",
"account_id": "60f199509111e70000000031",
"currency": "USD",
"date_created": "2021-07-16T14:36:00.194Z",
"date_updated": "2021-07-16T14:36:00.194Z",
"items": [
{
"id": "5ca537326a0ec32a521139dd",
"product_id": "5c524166f4e8f3446a10331b",
"variant_id": "5c524166f4e8f3446a10331f",
"quantity": 2,
"price": 19.99,
"price_total": 38.98,
"orig_price": 19.99,
"options": [
{
"id": "5becb84fac207653a4816ee5",
"name": "Type",
"value": "Elven"
},
{
"id": "5becb84fac207653a4816ee6",
"name": "Enchanted",
"value": "Fire"
}
],
"discounts": [
{
"id": "coupon-0",
"amount": 5
}
],
"discount_each": 2.5,
"discount_total": 5,
"taxes": [
{
"id": "sales-tax",
"amount": 2
}
],
"tax_each": 1,
"tax_total": 2
}
],
"number": 117266,
"paid": false,
"pastdue": false,
"status": "pending"
}
Retrieve an existing invoice using the ID that was returned when created.
Arguments
id
objectIdrequiredID of the invoice to retrieve.
expand
stringExpanding link fields and child collections is performed using the expand argument.
- For example, expand=account would return a related customer account if one exists.
When the field represents a collection, you can specify the query limit.
- For example, expand=variants:10 would return up to 10 records of the variants collection.
See expanding for more details.
fields
stringReturn only the specified fields in the result. For example fields=name,slug would return only the fields name and slug in the response. Supports nested object and array fields using dot-notation. For example, items.product_id. The gift card id is always returned.
include
stringInclude one or more arbitrary queries in the response, possibly related to the main query.
See including for more details.
const swell = require('swell-node').init('store-id', 'secret-key');
await swell.get('/invoices/{id}', {
id: '60f199509111e70000000033'
});
Response
{
"id": "60f199509111e70000000037",
"account_id": "60f199509111e70000000038",
"currency": "USD",
"date_created": "2021-07-16T14:36:00.194Z",
"date_updated": "2021-07-16T14:36:00.194Z",
"items": [
{
"id": "5ca537326a0ec32a521139dd",
"product_id": "5c524166f4e8f3446a10331b",
"variant_id": "5c524166f4e8f3446a10331f",
"quantity": 2,
"price": 19.99,
"price_total": 38.98,
"orig_price": 19.99,
"options": [
{
"id": "5becb84fac207653a4816ee5",
"name": "Size",
"value": "Small"
},
{
"id": "5becb84fac207653a4816ee6",
"name": "Color",
"value": "Yellow"
}
],
"discounts": [
{
"id": "coupon-0",
"amount": 5
}
],
"discount_each": 2.5,
"discount_total": 5,
"taxes": [
{
"id": "sales-tax",
"amount": 2
}
],
"tax_each": 1,
"tax_total": 2
}
],
"number": 117266,
"paid": false,
"pastdue": false,
"status": "pending"
}
Return a list of invoices.
Arguments
expand
stringExpand link fields and child collections by using the expand argument.
- For example, expand=account would return a related customer account if one exists.
When the field represents a collection, you can specify the query limit.
- For example, expand=variants:10 would return up to 10 records of the variants collection.
See expanding for more details.
fields
stringReturns only the specified fields in the result.
- For example fields=name,slug would return only the fields name and slug in the response.
Supports nested object and array fields using dot-notation.
- For example, items.product_id. The product id is always returned.
include
objectInclude one or more arbitrary queries in the response which are potentially related to the main query.
See including for more details.
limit
intLimit the number of records returned, ranging between 1 and 1000. Defaults to 15.
page
intThe page number of results to return given the specified or default limit.
search
stringA text search is performed using the search argument. Searchable fields are defined by the model.
- For example, search=red would return records containing the word "red" anywhere in the defined text fields.
See searching for more details.
sort
stringExpression to sort results by using a format similar to a SQL sort statement.
- For example, sort=name asc would return records sorted by name ascending.
See sorting for more details.
where
objectAn object with criteria to filter the result.
- For example, active=true would return records containing a field active with the value true.
It's also possible to use query operators, for example, $eq, $ne, $gt, and more.
See querying for more details.
const swell = require('swell-node').init('store-id', 'secret-key');
await swell.get('/invoices/{id}', {
id: '60f199509111e70000000033'
});
Response
{
"count": 51,
"results": [
{
"id": "60f199509111e7000000002f",
"account_id": "60f199509111e7000000003c",
"currency": "USD",
"date_created": "2021-07-16T14:36:00.194Z",
"date_updated": "2021-07-16T14:36:00.194Z",
"items": [
{
"id": "5ca537326a0ec32a521139dd",
"product_id": "5c524166f4e8f3446a10331b",
"variant_id": "5c524166f4e8f3446a10331f",
"quantity": 2,
"price": 19.99,
"price_total": 38.98,
"orig_price": 19.99,
"options": [
{
"id": "5becb84fac207653a4816ee5",
"name": "Size",
"value": "Small"
},
{
"id": "5becb84fac207653a4816ee6",
"name": "Color",
"value": "Yellow"
}
],
"discounts": [
{
"id": "coupon-0",
"amount": 5
}
],
"discount_each": 2.5,
"discount_total": 5,
"taxes": [
{
"id": "sales-tax",
"amount": 2
}
],
"tax_each": 1,
"tax_total": 2
}
],
"number": 117266,
"paid": false,
"pastdue": false,
"status": "pending"
},
{...},
{...}
],
"page": 1,
"pages": {
"1": {
"start": 1,
"end": 25
},
"2": {
"start": 26,
"end": 50
},
"2": {
"start": 51,
"end": 51
}
}
}