Skip to main content

Localization & Currency

Pass locale and currency headers with any request. For full details, see the Localization reference.
// Set locale and currency per request
const products = await client.products.list({}, {
  locale: 'fr',
  currency: 'EUR',
  country: 'FR',
})
// Works with all endpoints
const category = await client.categories.get('clothing/shirts', {
  expand: ['ancestors'],
}, {
  locale: 'de',
  currency: 'EUR',
})

Error Handling

import { SpreeError } from '@spree/sdk';

try {
  await client.products.get('non-existent');
} catch (error) {
  if (error instanceof SpreeError) {
    console.log(error.code);    // 'record_not_found'
    console.log(error.message); // 'Product not found'
    console.log(error.status);  // 404
    console.log(error.details); // Validation errors (if any)
  }
}

Custom Fetch

You can provide a custom fetch implementation:
import { createClient } from '@spree/sdk';

const client = createClient({
  baseUrl: 'https://api.mystore.com',
  publishableKey: 'spree_pk_xxx',
  fetch: customFetchImplementation,
});

Monetary Amounts

All monetary values in the API are returned as strings (e.g., "29.99", "0.0"), not numbers. This preserves decimal precision and avoids floating-point rounding issues.
const order = await client.orders.get('or_abc123', {}, { token });

// Monetary fields are strings
order.total;         // "129.99"
order.item_total;    // "99.99"
order.ship_total;    // "10.00"
order.tax_total;     // "20.00"

// Display fields include currency formatting
order.display_total; // "$129.99"

// Convert to number when needed for calculations
const total = parseFloat(order.total);
This applies to all monetary fields across all types: StoreOrder, StoreLineItem, StoreShipment, StorePayment, StoreGiftCard, StorePrice, etc.

TypeScript Support

The SDK includes full TypeScript support with generated types from the API serializers:
import type {
  StoreProduct,
  StoreOrder,
  StoreVariant,
  StoreCategory,
  StoreLineItem,
  StoreAddress,
  StoreCustomer,
  PaginatedResponse,
} from '@spree/sdk';

// All responses are fully typed
const products: PaginatedResponse<StoreProduct> = await client.products.list();
const category: StoreCategory = await client.categories.get('clothing');

Available Types

Core Types

  • StoreProduct - Product data
  • StoreVariant - Variant data
  • StoreOrder - Order/cart data
  • StoreLineItem - Line item in cart
  • StoreCategory - Category
  • StoreCountry - Country with states
  • StoreState - State/province
  • StoreAddress - Customer address
  • StoreCustomer - Customer profile

Commerce Types

  • StorePayment - Payment record
  • StorePaymentMethod - Payment method
  • StorePaymentSession - Provider-agnostic payment session
  • StoreShipment - Shipment record
  • StoreShippingRate - Shipping rate option
  • StoreShippingMethod - Shipping method
  • StoreCreditCard - Saved credit card
  • StoreGiftCard - Gift card

Product Types

  • StoreImage - Product image
  • StorePrice - Price data
  • StoreOptionType - Option type (e.g., Size, Color)
  • StoreOptionValue - Option value (e.g., Small, Red)
  • StoreDigitalLink - Digital download link

Wishlist Types

  • StoreWishlist - Wishlist
  • StoreWishedItem - Wishlist item

Client Types

  • SpreeClient - Main client class
  • StoreClient - Store API client
  • AdminClient - Admin API client
  • SpreeClientConfig - Client configuration
  • RequestOptions - Per-request options
  • RetryConfig - Retry behavior configuration

Utility Types

  • PaginatedResponse<T> - Paginated API response
  • AuthTokens - JWT tokens from login
  • AddressParams - Address input parameters
  • CreatePaymentSessionParams - Payment session creation parameters
  • UpdatePaymentSessionParams - Payment session update parameters
  • CompletePaymentSessionParams - Payment session completion parameters
  • ProductFiltersResponse - Product filters response