Docs / built-apps / purchaseDomain

purchaseDomain

utilitysince 0.3.1not for built apps

Client function: buy a domain through Casino — returns a Stripe Checkout URL; registration + site auto-connect fire from the payment webhook (P0-163).

import { purchaseDomain } from 'flowstack-sdk'

Non-React client function. Starts a domain purchase through Casino's registrar: POST /api/v1/registrar/purchase with a PurchaseDomainRequest returns a Stripe Checkout session_url — redirect the builder there to pay. Route 53 registration and (if site_id was set) automatic connectDomain-style wiring happen asynchronously from the payment webhook, NOT in this call. Use searchDomains first to confirm availability and price.

Signature

purchaseDomain(credentials, request, config?): Promise<ApiResponse<{ domain: string; price_usd: number; session_url: string; session_id: string }>>

Parameters

ParamTypeNotesDescription
credentialsFlowstackCredentialsrequiredThe builder's credentials (owner-scoped JWT).
requestPurchaseDomainRequestrequiredDomain (name without TLD), TLD, RegistrantContact, and options (auto_renew, whois_privacy, site_id for auto-connect).
configFlowstackClientConfigClient config (baseUrl, appScope, tenantId as needed).

Returns

FieldTypeDescription
Promise<ApiResponse<{ domain: string; price_usd: number; session_url: string; session_id: string }>>The Stripe Checkout URL to redirect the builder to, plus the quoted first-year price.

Examples

Buy a domain and auto-connect it to a site
const res = await purchaseDomain(credentials, {
  domain: 'thezengarden',
  tld: 'com',
  registrant: {
    first_name: 'Ada', last_name: 'Lovelace', email: 'ada@example.com',
    phone: '+12125551234', address_line1: '1 Main St', city: 'New York',
    state: 'NY', zip_code: '10001', country_code: 'US',
  },
  auto_renew: true,
  whois_privacy: true,
  site_id: siteId,
});
if (res.data?.session_url) window.location.href = res.data.session_url;
WarningThe domain is NOT owned when this call returns — payment happens in the browser at session_url, and Route 53 registration + site auto-connect fire from the payment webhook afterwards. Poll listDomains / getDomainStatus to observe completion; do not treat a 200 here as a completed purchase.
WarningOwner/management operation — call it with the builder's credentials from a dashboard/builder context, not from inside the generated app's end-user runtime. builtAppSafe is false.
NoteRegistrant contact fields are registrar-validated: phone must be E.164 (+12125551234), country_code a 2-char ISO code, state a 2-char code for US addresses. Invalid contact data fails the registration after payment — get these right up front.

See also

searchDomains · PurchaseDomainRequest · RegistrantContact · listDomains · getDomainStatus

Source: src/api/client.ts (Domain Registrar, P0-163) · Also available in llms-full.txt and registry.json.