Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

1.1 KB
Raw Blame
import { createAdminClient } from '@spree/admin-sdk'

const client = createAdminClient({
  baseUrl: 'https://your-store.com',
  secretKey: 'sk_xxx',
})

// region:example
const product = await client.products.create({
  name: 'Premium T-Shirt',
  // Rich text: send HTML. Reads return this as plain text, plus
  // `description_html` with the markup.
  description: '<p>Soft, organic cotton.</p>',
  status: 'active',
  variants: [
    {
      sku: 'TSHIRT-S-NAVY',
      options: [
        { name: 'size', value: 'Small' },
        { name: 'color', value: 'navy' },
      ],
      prices: [
        { currency: 'USD', amount: '29.99' },
        { currency: 'EUR', amount: '27.99' },
      ],
      stock_levels: [{ stock_location_id: 'sloc_UkLWZg9DAJ', count_on_hand: 50 }],
    },
    {
      sku: 'TSHIRT-M-NAVY',
      options: [
        { name: 'size', value: 'Medium' },
        { name: 'color', value: 'navy' },
      ],
      prices: [{ currency: 'USD', amount: '29.99' }],
      stock_levels: [{ stock_location_id: 'sloc_UkLWZg9DAJ', count_on_hand: 30 }],
    },
  ],
})

// endregion:example

export { product }