Aller à la documentation
SDK

openemail.billing

Chaque méthode de cet espace de noms : sa signature, ses paramètres, ce qu'elle retourne et un exemple.

Méthodes

The plan of the workspace and what it costs, as Plans & Billing shows them: the plan and its usage, the plans on sale, pay as you go, every charge with its invoice, and the links that start a checkout or open the billing portal. Only the workspace owner reaches it, and nothing is paid through the API.

billing.get()

Read the plan

Portéesbilling:read
Signature
get(options?: RequestScope): Promise<BillingResource>

Resolves the plan of the workspace and what it includes, as Plans & Billing shows it: how it is billed, when it renews or ends and the next charge, how many domains it holds, how much of this month's sends and today's AI actions are used, and pay as you go. metered is false when billing is off on the install, and then nothing is capped.

Billing belongs to the owner of the workspace: an API key acts for the owner, and an OAuth access token reaches billing only when the owner connected the app with every address. A token that acts for a member is 403 owner_only, and a key or token limited to particular addresses or domains is 422 capability_unsupported.

Paramètres

options.signalAbortSignal

Cancels the request.

options.apiKeystring

Overrides the client's API key for this call only.

Retourne

BillingResource with plan, interval, renewsAt, nextCharge, domains, usage and payAsYouGo.

Exemple

const billing = await openemail.billing.get() console.log(billing.planName, billing.usage.sends.used, billing.usage.sends.limit)

Remarques

  • A limit of null means the plan has none.

Aussi disponible dans

API
GET /billing
CLI
openemail billing get

billing.listPlans()

List the plans

Portéesbilling:read
Signature
listPlans(options?: RequestScope): Promise<BillingPlanListResource>

Resolves every plan, cheapest first, with its price in US cents and what it includes. available says whether it is sold on the install, and intervals the billing intervals it is sold at.

Billing belongs to the owner of the workspace: an API key acts for the owner, and an OAuth access token reaches billing only when the owner connected the app with every address. A token that acts for a member is 403 owner_only, and a key or token limited to particular addresses or domains is 422 capability_unsupported.

Paramètres

options.signalAbortSignal

Cancels the request.

options.apiKeystring

Overrides the client's API key for this call only.

Retourne

BillingPlanListResource with one BillingPlanResource per plan in data.

Exemple

const { data } = await openemail.billing.listPlans() const sold = data.filter((plan) => plan.available)

Aussi disponible dans

API
GET /billing/plans
CLI
openemail billing list-plans

billing.getUsage()

Read the usage history

Portéesbilling:read
Signature
getUsage(options?: BillingUsageOptions): Promise<BillingUsageResource>

Resolves the sends and AI actions of each day, and what pay as you go extras cost each month, as the Usage charts show them.

Billing belongs to the owner of the workspace: an API key acts for the owner, and an OAuth access token reaches billing only when the owner connected the app with every address. A token that acts for a member is 403 owner_only, and a key or token limited to particular addresses or domains is 422 capability_unsupported.

Paramètres

options.daysBillingUsageWindow

How many days back to go, from 1 to 3,660, or all for every day since the workspace was made. The server defaults to 30.

options.signalAbortSignal

Cancels the request.

options.apiKeystring

Overrides the client's API key for this call only.

Retourne

BillingUsageResource with days, months, dailyAiActions and monthlySends.

Exemple

const usage = await openemail.billing.getUsage({ days: 90 }) const sent = usage.days.reduce((total, day) => total + day.sends, 0)

Aussi disponible dans

API
GET /billing/usage
CLI
openemail billing get-usage

billing.listAlerts()

List the billing alerts

Portéesbilling:read
Signature
listAlerts(options?: RequestScope): Promise<BillingAlertListResource>

Resolves what the billing banner of the app would say now, most urgent first: a failed payment, paused pay as you go, sending or AI paused at a limit, a plan about to end, an allowance nearly used and a charge coming soon. An empty list means there is nothing to say.

Billing belongs to the owner of the workspace: an API key acts for the owner, and an OAuth access token reaches billing only when the owner connected the app with every address. A token that acts for a member is 403 owner_only, and a key or token limited to particular addresses or domains is 422 capability_unsupported.

Paramètres

options.signalAbortSignal

Cancels the request.

options.apiKeystring

Overrides the client's API key for this call only.

Retourne

BillingAlertListResource with one BillingAlertResource per alert in data.

Exemple

const { data } = await openemail.billing.listAlerts() const blocked = data.filter((alert) => alert.severity === 'blocked')

Remarques

  • An alert keeps its id while the same thing is true, so one that was dismissed can stay dismissed.

Aussi disponible dans

API
GET /billing/alerts
CLI
openemail billing list-alerts

billing.listCountries()

List the billing countries

Portéesbilling:read
Signature
listCountries(options?: RequestScope): Promise<BillingCountryListResource>

Resolves every country a billing address can be in, as the two-letter ISO 3166 codes saveInvoiceDetails takes as country.

Billing belongs to the owner of the workspace: an API key acts for the owner, and an OAuth access token reaches billing only when the owner connected the app with every address. A token that acts for a member is 403 owner_only, and a key or token limited to particular addresses or domains is 422 capability_unsupported.

Paramètres

options.signalAbortSignal

Cancels the request.

options.apiKeystring

Overrides the client's API key for this call only.

Retourne

BillingCountryListResource with the codes in data.

Exemple

const { data } = await openemail.billing.listCountries() console.log(data.includes('DE'))

Aussi disponible dans

API
GET /billing/countries
CLI
openemail billing list-countries

billing.getPayAsYouGo()

Read pay as you go

Portéesbilling:read
Signature
getPayAsYouGo(options?: RequestScope): Promise<PayAsYouGoResource>

Resolves pay as you go on the workspace: whether usage past the allowances is billed, the monthly limit and what extras cost so far, the current billing period once it is set up, the limits that can be chosen and the prices.

Billing belongs to the owner of the workspace: an API key acts for the owner, and an OAuth access token reaches billing only when the owner connected the app with every address. A token that acts for a member is 403 owner_only, and a key or token limited to particular addresses or domains is 422 capability_unsupported.

Paramètres

options.signalAbortSignal

Cancels the request.

options.apiKeystring

Overrides the client's API key for this call only.

Retourne

PayAsYouGoResource with the state, limits, prices and period.

Exemple

const payg = await openemail.billing.getPayAsYouGo() console.log(payg.enabled, payg.spentCents, payg.limitCents)

Remarques

  • Amounts are in US cents.

Aussi disponible dans

API
GET /billing/pay-as-you-go
CLI
openemail billing get-pay-as-you-go

billing.setPayAsYouGo()

Turn pay as you go on or off

Portéesbilling:write
Signature
setPayAsYouGo(body: PayAsYouGoSet, options?: RequestScope): Promise<PayAsYouGoSwitchResource>

Turns pay as you go on or off, as the switch on Plans & Billing does. Off takes effect at once, and usage stops at the allowances. On takes effect at once when a card is already saved. The first time, checkoutUrl is a link where the person adds a card, and pay as you go starts once they have: call confirmPayAsYouGo after they return.

Nothing is paid through the API: the person pays, changes the card or cancels on the billing provider's page the link opens, as they do from the app.

Billing belongs to the owner of the workspace: an API key acts for the owner, and an OAuth access token reaches billing only when the owner connected the app with every address. A token that acts for a member is 403 owner_only, and a key or token limited to particular addresses or domains is 422 capability_unsupported.

Paramètres

body.enabledbooleanObligatoire

true to turn it on, false to turn it off.

body.themeBillingTheme

light or dark, for the page the link opens.

body.localestring

A language tag such as de or pt-PT, for the page the link opens.

options.signalAbortSignal

Cancels the request.

options.apiKeystring

Overrides the client's API key for this call only.

Retourne

PayAsYouGoSwitchResource with enabled, suspended, activating and checkoutUrl.

Exemple

const result = await openemail.billing.setPayAsYouGo({ enabled: true }) if (result.checkoutUrl) console.log('Add a card here:', result.checkoutUrl)

Remarques

  • With an OAuth access token it asks for a verification code: until the app has verified one, it is refused with 403 step_up_required. An API key is never asked.

  • Turning it on where pay as you go is not set up on the install is 503 billing_not_configured.

  • The SDK does not retry it.

Aussi disponible dans

API
PATCH /billing/pay-as-you-go
CLI
openemail billing set-pay-as-you-go

billing.setPayAsYouGoLimit()

Set the pay as you go limit

Portéesbilling:write
Signature
setPayAsYouGoLimit(body: PayAsYouGoLimitSet, options?: RequestScope): Promise<PayAsYouGoLimitResource>

Sets the monthly spending limit of pay as you go, in US cents, one of the amounts getPayAsYouGo lists in limits. Extras stop for the rest of a calendar month once it is reached.

Billing belongs to the owner of the workspace: an API key acts for the owner, and an OAuth access token reaches billing only when the owner connected the app with every address. A token that acts for a member is 403 owner_only, and a key or token limited to particular addresses or domains is 422 capability_unsupported.

Paramètres

body.limitCentsnumberObligatoire

The limit in US cents: 1,000, 2,500, 5,000, 10,000, 25,000, 50,000, 100,000, 250,000 or 500,000.

options.signalAbortSignal

Cancels the request.

options.apiKeystring

Overrides the client's API key for this call only.

Retourne

PayAsYouGoLimitResource with limitCents.

Exemple

await openemail.billing.setPayAsYouGoLimit({ limitCents: 10_000 })

Remarques

  • With an OAuth access token it asks for a verification code: until the app has verified one, it is refused with 403 step_up_required. An API key is never asked.

  • A workspace where pay as you go was never set up is 409 pay_as_you_go_not_enrolled.

  • The SDK does not retry it.

Aussi disponible dans

API
PUT /billing/pay-as-you-go/limit
CLI
openemail billing set-pay-as-you-go-limit

billing.confirmPayAsYouGo()

Confirm pay as you go

Portéesbilling:write
Signature
confirmPayAsYouGo(options?: RequestScope): Promise<PayAsYouGoConfirmationResource>

Checks with the billing provider whether the card from a pay as you go checkout was saved, and records it, as the app does when the person comes back from the checkout. enabled says whether pay as you go is on now.

Billing belongs to the owner of the workspace: an API key acts for the owner, and an OAuth access token reaches billing only when the owner connected the app with every address. A token that acts for a member is 403 owner_only, and a key or token limited to particular addresses or domains is 422 capability_unsupported.

Paramètres

options.signalAbortSignal

Cancels the request.

options.apiKeystring

Overrides the client's API key for this call only.

Retourne

PayAsYouGoConfirmationResource with enabled.

Exemple

const { enabled } = await openemail.billing.confirmPayAsYouGo()

Remarques

  • With an OAuth access token it asks for a verification code: until the app has verified one, it is refused with 403 step_up_required. An API key is never asked.

  • It is safe to call again.

  • The SDK does not retry it.

Aussi disponible dans

API
POST /billing/pay-as-you-go/confirm
CLI
openemail billing confirm-pay-as-you-go

billing.startCheckout()

Start a checkout

Portéesbilling:write
Signature
startCheckout(body: BillingCheckoutCreate, options?: RequestScope): Promise<BillingCheckoutResource>

Starts buying a paid plan for a workspace on Free, as choosing a plan in the app does, and resolves with the link to the checkout. Nothing is charged until the person pays there, and the plan starts once they have. A workspace that already pays for a plan changes it with openPortal instead.

Nothing is paid through the API: the person pays, changes the card or cancels on the billing provider's page the link opens, as they do from the app.

Billing belongs to the owner of the workspace: an API key acts for the owner, and an OAuth access token reaches billing only when the owner connected the app with every address. A token that acts for a member is 403 owner_only, and a key or token limited to particular addresses or domains is 422 capability_unsupported.

Paramètres

body.planPaidPlanIdObligatoire

starter, business or enterprise.

body.intervalBillingInterval

month or year. Defaults to month.

body.themeBillingTheme

light or dark, for the page the link opens.

body.localestring

A language tag such as de or pt-PT, for the page the link opens.

options.signalAbortSignal

Cancels the request.

options.apiKeystring

Overrides the client's API key for this call only.

Retourne

BillingCheckoutResource with url.

Exemple

const { url } = await openemail.billing.startCheckout({ plan: 'business', interval: 'year' }) console.log('Pay here:', url)

Remarques

  • With an OAuth access token it asks for a verification code: until the app has verified one, it is refused with 403 step_up_required. An API key is never asked.

  • A workspace that already pays for a plan is 409 plan_conflict, and a plan or interval not sold on the install is 422 plan_unavailable.

  • The SDK does not retry it.

Aussi disponible dans

API
POST /billing/checkout
CLI
openemail billing start-checkout

billing.openPortal()

Open the billing portal

Portéesbilling:write
Signature
openPortal(body?: BillingHandoff, options?: RequestScope): Promise<BillingPortalResource>

Resolves with a link to the billing portal, where the person changes or cancels the plan, updates the card and downloads past invoices, as Manage does in the app.

Nothing is paid through the API: the person pays, changes the card or cancels on the billing provider's page the link opens, as they do from the app.

Billing belongs to the owner of the workspace: an API key acts for the owner, and an OAuth access token reaches billing only when the owner connected the app with every address. A token that acts for a member is 403 owner_only, and a key or token limited to particular addresses or domains is 422 capability_unsupported.

Paramètres

body.themeBillingTheme

light or dark, for the page the link opens.

body.localestring

A language tag such as de or pt-PT, for the page the link opens.

options.signalAbortSignal

Cancels the request.

options.apiKeystring

Overrides the client's API key for this call only.

Retourne

BillingPortalResource with url.

Exemple

const { url } = await openemail.billing.openPortal({ theme: 'dark' })

Remarques

  • With an OAuth access token it asks for a verification code: until the app has verified one, it is refused with 403 step_up_required. An API key is never asked.

  • The SDK does not retry it.

Aussi disponible dans

API
POST /billing/portal
CLI
openemail billing open-portal

billing.listInvoices()

List the charges

Portéesbilling:read
Signature
listInvoices(options?: BillingInvoiceListOptions): Promise<BillingInvoiceListResource>

Resolves every charge of the workspace with the state of its invoice, a page at a time, as History on Plans & Billing lists them. search matches the plan, the invoice number, the charge id and the name billed.

Billing belongs to the owner of the workspace: an API key acts for the owner, and an OAuth access token reaches billing only when the owner connected the app with every address. A token that acts for a member is 403 owner_only, and a key or token limited to particular addresses or domains is 422 capability_unsupported.

Paramètres

options.pagenumber

Which page, from 1.

options.limitnumber

Charges per page, from 1 to 100. The server defaults to 25.

options.sortBillingInvoiceSort

newest, the default, or oldest.

options.searchstring

Words to look for, up to 120 characters.

options.signalAbortSignal

Cancels the request.

options.apiKeystring

Overrides the client's API key for this call only.

Retourne

BillingInvoiceListResource with data, total, page, limit, hasMore and metered.

Exemple

const { data } = await openemail.billing.listInvoices({ limit: 10 }) const unpaid = data.filter((charge) => !charge.paid)

Remarques

Aussi disponible dans

API
GET /billing/invoices
CLI
openemail billing list-invoices

billing.getInvoice()

Get the invoice of a charge

Portéesbilling:read
Signature
getInvoice(orderId: string, options?: RequestScope): Promise<BillingInvoiceLinkResource>

Resolves with the link to the invoice of one charge, as a PDF, and its file name. An invoice that was not written yet is written first, which can take a few seconds. The link is signed by the billing provider, downloads the PDF and stops working after a while, so fetch it again rather than keeping it.

Billing belongs to the owner of the workspace: an API key acts for the owner, and an OAuth access token reaches billing only when the owner connected the app with every address. A token that acts for a member is 403 owner_only, and a key or token limited to particular addresses or domains is 422 capability_unsupported.

Paramètres

orderIdstringObligatoire

The charge id, as listInvoices returns it.

options.signalAbortSignal

Cancels the request.

options.apiKeystring

Overrides the client's API key for this call only.

Retourne

BillingInvoiceLinkResource with url and fileName.

Exemple

const { data } = await openemail.billing.listInvoices({ limit: 1 }) const invoice = await openemail.billing.getInvoice(data[0].id) console.log(invoice.fileName, invoice.url)

Remarques

Aussi disponible dans

API
GET /billing/invoices/{orderId}
CLI
openemail billing get-invoice

billing.saveInvoiceDetails()

Save the billing details of a charge

Portéesbilling:write
Signature
saveInvoiceDetails(orderId: string, body: BillingDetailsSet, options?: RequestScope): Promise<BillingInvoiceDetailsResource>

Saves the name and address billed on a charge, as the Billing address dialog does, keeps the address for later charges, and starts writing its invoice. invoice is ready when the charge already had one, started when it is being written, and refused with the reason in message.

Billing belongs to the owner of the workspace: an API key acts for the owner, and an OAuth access token reaches billing only when the owner connected the app with every address. A token that acts for a member is 403 owner_only, and a key or token limited to particular addresses or domains is 422 capability_unsupported.

Paramètres

orderIdstringObligatoire

The charge id, as listInvoices returns it.

body.namestringObligatoire

Who is billed, up to 200 characters.

body.line1stringObligatoire

The street address, up to 200 characters.

body.line2string

A flat, suite or building, up to 200 characters.

body.citystringObligatoire

Up to 120 characters.

body.postalCodestring

Up to 40 characters.

body.statestring

The state or region, up to 60 characters. In the US and Canada, its two-letter code.

body.countrystringObligatoire

A two-letter ISO 3166 code, one of those listCountries returns.

options.signalAbortSignal

Cancels the request.

options.apiKeystring

Overrides the client's API key for this call only.

Retourne

BillingInvoiceDetailsResource with invoice and message.

Exemple

await openemail.billing.saveInvoiceDetails(chargeId, {    name: 'Acme Ltd',    line1: '1 Market Street',    city: 'London',    postalCode: 'EC1A 1AA',    country: 'GB'})

Remarques

  • With an OAuth access token it asks for a verification code: until the app has verified one, it is refused with 403 step_up_required. An API key is never asked.

  • An address the billing provider refuses is 422 billing_address_rejected.

  • The SDK does not retry it.

Aussi disponible dans

API
PUT /billing/invoices/{orderId}/details
CLI
openemail billing save-invoice-details