@spree/docs 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -0
- package/dist/api-reference/platform/authentication.md +38 -0
- package/dist/api-reference/store-api/authentication.md +188 -0
- package/dist/api-reference/store-api/errors.md +277 -0
- package/dist/api-reference/store-api/idempotency.md +129 -0
- package/dist/api-reference/store-api/introduction.md +34 -0
- package/dist/api-reference/store-api/localization.md +279 -0
- package/dist/api-reference/store-api/metadata.md +160 -0
- package/dist/api-reference/store-api/monetary-amounts.md +65 -0
- package/dist/api-reference/store-api/querying.md +399 -0
- package/dist/api-reference/store-api/rate-limitting.md +103 -0
- package/dist/api-reference/store-api/relations.md +185 -0
- package/dist/api-reference/storefront/authentication.md +88 -0
- package/dist/api-reference/tutorials/adyen-integration-guide-for-android.md +165 -0
- package/dist/api-reference/tutorials/adyen-integration-guide-for-ios.md +194 -0
- package/dist/api-reference/tutorials/quick-checkout-with-stripe.md +248 -0
- package/dist/api-reference/v2/fetching-multiple-resources.md +26 -0
- package/dist/api-reference/v2/filtering-and-sorting.md +53 -0
- package/dist/api-reference/v2/introduction.md +22 -0
- package/dist/api-reference/v2/pagination.md +37 -0
- package/dist/api-reference/webhooks-events.md +883 -0
- package/dist/developer/admin/admin.md +205 -0
- package/dist/developer/admin/authentication.md +59 -0
- package/dist/developer/admin/components.md +711 -0
- package/dist/developer/admin/custom-css.md +243 -0
- package/dist/developer/admin/custom-javascript.md +116 -0
- package/dist/developer/admin/extending-ui.md +1964 -0
- package/dist/developer/admin/form-builder.md +444 -0
- package/dist/developer/admin/helper-methods.md +531 -0
- package/dist/developer/admin/navigation.md +805 -0
- package/dist/developer/admin/tables.md +491 -0
- package/dist/developer/advanced/adding_spree_to_rails_app.md +106 -0
- package/dist/developer/cli/quickstart.md +137 -0
- package/dist/developer/contributing/creating-an-extension.md +258 -0
- package/dist/developer/contributing/developing-spree.md +339 -0
- package/dist/developer/contributing/quickstart.md +32 -0
- package/dist/developer/contributing/updating-extensions.md +67 -0
- package/dist/developer/core-concepts/addresses.md +265 -0
- package/dist/developer/core-concepts/adjustments.md +107 -0
- package/dist/developer/core-concepts/architecture.md +177 -0
- package/dist/developer/core-concepts/calculators.md +323 -0
- package/dist/developer/core-concepts/customers.md +230 -0
- package/dist/developer/core-concepts/events.md +624 -0
- package/dist/developer/core-concepts/imports-exports.md +698 -0
- package/dist/developer/core-concepts/inventory.md +191 -0
- package/dist/developer/core-concepts/markets.md +250 -0
- package/dist/developer/core-concepts/media.md +167 -0
- package/dist/developer/core-concepts/metafields.md +187 -0
- package/dist/developer/core-concepts/orders.md +328 -0
- package/dist/developer/core-concepts/payments.md +710 -0
- package/dist/developer/core-concepts/pricing.md +163 -0
- package/dist/developer/core-concepts/products.md +360 -0
- package/dist/developer/core-concepts/promotions.md +322 -0
- package/dist/developer/core-concepts/reports.md +206 -0
- package/dist/developer/core-concepts/search-filtering.md +237 -0
- package/dist/developer/core-concepts/shipments.md +212 -0
- package/dist/developer/core-concepts/slugs.md +111 -0
- package/dist/developer/core-concepts/staff-roles.md +123 -0
- package/dist/developer/core-concepts/store-credits-gift-cards.md +317 -0
- package/dist/developer/core-concepts/stores.md +117 -0
- package/dist/developer/core-concepts/taxes.md +135 -0
- package/dist/developer/core-concepts/translations.md +120 -0
- package/dist/developer/core-concepts/users.md +299 -0
- package/dist/developer/core-concepts/webhooks.md +378 -0
- package/dist/developer/create-spree-app/quickstart.md +158 -0
- package/dist/developer/customization/api.md +93 -0
- package/dist/developer/customization/authentication.md +88 -0
- package/dist/developer/customization/checkout.md +204 -0
- package/dist/developer/customization/configuration.md +55 -0
- package/dist/developer/customization/decorators.md +523 -0
- package/dist/developer/customization/dependencies.md +232 -0
- package/dist/developer/customization/emails.md +21 -0
- package/dist/developer/customization/extensions.md +92 -0
- package/dist/developer/customization/metadata.md +236 -0
- package/dist/developer/customization/model-preferences.md +130 -0
- package/dist/developer/customization/permissions.md +265 -0
- package/dist/developer/customization/quickstart.md +229 -0
- package/dist/developer/customization/routes.md +24 -0
- package/dist/developer/customization/v4/admin-panel.md +78 -0
- package/dist/developer/customization/v4/authentication.md +210 -0
- package/dist/developer/customization/v4/checkout.md +212 -0
- package/dist/developer/customization/v4/deface.md +251 -0
- package/dist/developer/customization/v4/images.md +86 -0
- package/dist/developer/customization/v4/storefront.md +450 -0
- package/dist/developer/deployment/assets.md +87 -0
- package/dist/developer/deployment/aws.md +335 -0
- package/dist/developer/deployment/caching.md +27 -0
- package/dist/developer/deployment/cdn.md +39 -0
- package/dist/developer/deployment/database.md +155 -0
- package/dist/developer/deployment/docker.md +128 -0
- package/dist/developer/deployment/emails.md +77 -0
- package/dist/developer/deployment/environment_variables.md +111 -0
- package/dist/developer/deployment/heroku.md +51 -0
- package/dist/developer/deployment/render.md +95 -0
- package/dist/developer/getting-started/quickstart.md +82 -0
- package/dist/developer/how-to/custom-payment-method.md +374 -0
- package/dist/developer/how-to/custom-promotion.md +373 -0
- package/dist/developer/how-to/custom-report.md +387 -0
- package/dist/developer/how-to/custom-search-provider.md +230 -0
- package/dist/developer/multi-store/quickstart.md +71 -0
- package/dist/developer/multi-store/setup.md +38 -0
- package/dist/developer/multi-tenant/configuration.md +41 -0
- package/dist/developer/multi-tenant/core-concepts.md +75 -0
- package/dist/developer/multi-tenant/installation.md +96 -0
- package/dist/developer/multi-tenant/quickstart.md +20 -0
- package/dist/developer/multi-vendor/installation.md +45 -0
- package/dist/developer/multi-vendor/quickstart.md +17 -0
- package/dist/developer/sdk/admin/quickstart.md +22 -0
- package/dist/developer/sdk/authentication.md +89 -0
- package/dist/developer/sdk/configuration.md +225 -0
- package/dist/developer/sdk/quickstart.md +82 -0
- package/dist/developer/sdk/store/account.md +67 -0
- package/dist/developer/sdk/store/cart-checkout.md +140 -0
- package/dist/developer/sdk/store/markets.md +151 -0
- package/dist/developer/sdk/store/payments.md +96 -0
- package/dist/developer/sdk/store/products.md +149 -0
- package/dist/developer/sdk/store/wishlists.md +52 -0
- package/dist/developer/security/pci_compliance.md +15 -0
- package/dist/developer/security/security_policy.md +68 -0
- package/dist/developer/storefront/blocks.md +285 -0
- package/dist/developer/storefront/custom-css.md +260 -0
- package/dist/developer/storefront/custom-javascript.md +166 -0
- package/dist/developer/storefront/helper-methods.md +1288 -0
- package/dist/developer/storefront/links.md +298 -0
- package/dist/developer/storefront/nextjs/architecture.md +150 -0
- package/dist/developer/storefront/nextjs/customization.md +141 -0
- package/dist/developer/storefront/nextjs/deployment.md +180 -0
- package/dist/developer/storefront/nextjs/quickstart.md +92 -0
- package/dist/developer/storefront/nextjs/spree-next-package.md +314 -0
- package/dist/developer/storefront/pages.md +163 -0
- package/dist/developer/storefront/sections.md +569 -0
- package/dist/developer/storefront/storefront.md +56 -0
- package/dist/developer/storefront/themes.md +161 -0
- package/dist/developer/tutorial/admin.md +134 -0
- package/dist/developer/tutorial/extending-models.md +380 -0
- package/dist/developer/tutorial/file-uploads.md +121 -0
- package/dist/developer/tutorial/introduction.md +33 -0
- package/dist/developer/tutorial/model.md +41 -0
- package/dist/developer/tutorial/page-builder.md +487 -0
- package/dist/developer/tutorial/rich-text.md +73 -0
- package/dist/developer/tutorial/seo.md +332 -0
- package/dist/developer/tutorial/storefront.md +352 -0
- package/dist/developer/tutorial/testing.md +558 -0
- package/dist/developer/upgrades/2.0-to-2.1.md +46 -0
- package/dist/developer/upgrades/2.1-to-2.2.md +59 -0
- package/dist/developer/upgrades/2.2-to-2.3.md +44 -0
- package/dist/developer/upgrades/2.3-to-2.4.md +42 -0
- package/dist/developer/upgrades/3.0-to-3.1.md +47 -0
- package/dist/developer/upgrades/3.1-to-3.2.md +34 -0
- package/dist/developer/upgrades/3.2-to-3.3.md +70 -0
- package/dist/developer/upgrades/3.3-to-3.4.md +36 -0
- package/dist/developer/upgrades/3.4-to-3.5.md +44 -0
- package/dist/developer/upgrades/3.5-to-3.6.md +40 -0
- package/dist/developer/upgrades/3.6-to-3.7.md +62 -0
- package/dist/developer/upgrades/3.7-to-4.0.md +152 -0
- package/dist/developer/upgrades/4.0-to-4.1.md +92 -0
- package/dist/developer/upgrades/4.1-to-4.2.md +109 -0
- package/dist/developer/upgrades/4.10-to-5.0.md +129 -0
- package/dist/developer/upgrades/4.2-to-4.3.md +100 -0
- package/dist/developer/upgrades/4.3-to-4.4.md +125 -0
- package/dist/developer/upgrades/4.4-to-4.5.md +94 -0
- package/dist/developer/upgrades/4.5-to-4.6.md +119 -0
- package/dist/developer/upgrades/4.6-to-4.7.md +39 -0
- package/dist/developer/upgrades/4.8-to-4.9.md +24 -0
- package/dist/developer/upgrades/4.9-to-4.10.md +24 -0
- package/dist/developer/upgrades/4.x-to-4.8.md +52 -0
- package/dist/developer/upgrades/5.0-to-5.1.md +28 -0
- package/dist/developer/upgrades/5.1-to-5.2.md +127 -0
- package/dist/developer/upgrades/5.2-to-5.3.md +338 -0
- package/dist/developer/upgrades/5.3-to-5.4.md +248 -0
- package/dist/developer/upgrades/quickstart.md +36 -0
- package/dist/integrations/analytics/google-analytics.md +64 -0
- package/dist/integrations/analytics/google-tag-manager.md +78 -0
- package/dist/integrations/integrations.md +39 -0
- package/dist/integrations/marketing/klaviyo.md +99 -0
- package/dist/integrations/payments/adyen.md +90 -0
- package/dist/integrations/payments/paypal.md +41 -0
- package/dist/integrations/payments/razorpay.md +45 -0
- package/dist/integrations/payments/stripe.md +109 -0
- package/dist/integrations/search/meilisearch.md +236 -0
- package/dist/integrations/sso-mfa-social-login/admin-dashboard.md +57 -0
- package/dist/integrations/sso-mfa-social-login/storefront.md +56 -0
- package/package.json +27 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Store API"
|
|
3
|
+
sidebarTitle: "Introduction"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
This API reference includes Spree Store APIs, which are REST APIs exposed by the Spree application. They are used to create a storefront for your commerce store, such as a website, point of sale or a commerce mobile app.
|
|
7
|
+
|
|
8
|
+
All API Routes are prefixed with `/api/v3/store`. So, during development, the API Routes will be available under the path `http://localhost:3000/api/v3/store`. For production, replace `http://localhost:3000` with your Spree application URL.
|
|
9
|
+
|
|
10
|
+
## Using SDK
|
|
11
|
+
|
|
12
|
+
We recommend using the Spree SDK to interact with the Store API. The SDK provides a convenient way to make API requests and handle responses.
|
|
13
|
+
|
|
14
|
+
### Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @spree/sdk
|
|
18
|
+
# or
|
|
19
|
+
yarn add @spree/sdk
|
|
20
|
+
# or
|
|
21
|
+
pnpm add @spree/sdk
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Quick Start
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { createClient } from '@spree/sdk';
|
|
28
|
+
|
|
29
|
+
// Initialize the client
|
|
30
|
+
const client = createClient({
|
|
31
|
+
baseUrl: 'http://localhost:3000',
|
|
32
|
+
publishableKey: 'spree_pk_xxx'
|
|
33
|
+
});
|
|
34
|
+
```
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Localization"
|
|
3
|
+
sidebarTitle: "Localization"
|
|
4
|
+
description: "How to set locale, currency, and country for API requests"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
The Store API supports multi-language, multi-currency, and market-aware responses. Use request headers to control the locale, currency, and country for each request.
|
|
8
|
+
|
|
9
|
+
## Headers
|
|
10
|
+
|
|
11
|
+
| Header | Example | Description |
|
|
12
|
+
|--------|---------|-------------|
|
|
13
|
+
| `X-Spree-Locale` | `fr` | Language for translated content (product names, descriptions, etc.) |
|
|
14
|
+
| `X-Spree-Currency` | `EUR` | Currency for prices and totals |
|
|
15
|
+
| `X-Spree-Country` | `FR` | Country ISO code for market resolution |
|
|
16
|
+
|
|
17
|
+
## Client-Level Defaults
|
|
18
|
+
|
|
19
|
+
Set locale, currency, and country once at initialization — all subsequent requests use these defaults:
|
|
20
|
+
|
|
21
|
+
```typescript SDK
|
|
22
|
+
import { createClient } from '@spree/sdk'
|
|
23
|
+
|
|
24
|
+
const client = createClient({
|
|
25
|
+
baseUrl: 'https://api.mystore.com',
|
|
26
|
+
publishableKey: 'spree_pk_xxx',
|
|
27
|
+
locale: 'fr',
|
|
28
|
+
currency: 'EUR',
|
|
29
|
+
country: 'FR',
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
// All requests use fr/EUR/FR automatically
|
|
33
|
+
const products = await client.products.list()
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Update defaults at any time:
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
client.setLocale('de')
|
|
40
|
+
client.setCurrency('EUR')
|
|
41
|
+
client.setCountry('DE')
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Per-Request Overrides
|
|
45
|
+
|
|
46
|
+
Override client defaults for individual requests:
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
```typescript SDK
|
|
50
|
+
const products = await client.products.list({}, {
|
|
51
|
+
locale: 'fr',
|
|
52
|
+
currency: 'EUR',
|
|
53
|
+
country: 'FR',
|
|
54
|
+
})
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```bash cURL
|
|
58
|
+
curl -G 'http://localhost:3000/api/v3/store/products' \
|
|
59
|
+
-H 'X-Spree-Api-Key: spree_pk_xxx' \
|
|
60
|
+
-H 'X-Spree-Locale: fr' \
|
|
61
|
+
-H 'X-Spree-Currency: EUR'
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
## Country and Markets
|
|
66
|
+
|
|
67
|
+
The `X-Spree-Country` header resolves the customer's [market](/developer/core-concepts/markets), which influences default locale and currency. Markets allow you to configure different pricing, languages, and product availability per region.
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
```typescript SDK
|
|
71
|
+
// Setting country automatically resolves the market
|
|
72
|
+
const products = await client.products.list({}, {
|
|
73
|
+
country: 'DE', // Resolves German market → EUR, de locale
|
|
74
|
+
})
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
```bash cURL
|
|
78
|
+
curl -G 'http://localhost:3000/api/v3/store/products' \
|
|
79
|
+
-H 'X-Spree-Api-Key: spree_pk_xxx' \
|
|
80
|
+
-H 'X-Spree-Country: DE'
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
When a market is resolved from the country:
|
|
85
|
+
1. The market's default locale is used (unless overridden by `X-Spree-Locale`)
|
|
86
|
+
2. The market's default currency is used (unless overridden by `X-Spree-Currency`)
|
|
87
|
+
|
|
88
|
+
You can also resolve the market explicitly using the [Markets API](/developer/sdk/store/markets):
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
```typescript SDK
|
|
92
|
+
// Resolve which market applies for a country
|
|
93
|
+
const market = await client.markets.resolve('DE')
|
|
94
|
+
// => { id: "mkt_xxx", name: "Europe", currency: "EUR", default_locale: "de", ... }
|
|
95
|
+
|
|
96
|
+
// Then set the client defaults
|
|
97
|
+
client.setLocale(market.default_locale)
|
|
98
|
+
client.setCurrency(market.currency)
|
|
99
|
+
client.setCountry('DE')
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
```bash cURL
|
|
103
|
+
# Resolve market by country
|
|
104
|
+
curl 'http://localhost:3000/api/v3/store/markets/resolve?country=DE' \
|
|
105
|
+
-H 'X-Spree-Api-Key: spree_pk_xxx'
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
## Resolution Priority
|
|
110
|
+
|
|
111
|
+
Each value is resolved in the following order:
|
|
112
|
+
|
|
113
|
+
### Locale
|
|
114
|
+
1. `X-Spree-Locale` header
|
|
115
|
+
2. `locale` query parameter
|
|
116
|
+
3. Market default locale (if country is set)
|
|
117
|
+
4. Store default locale
|
|
118
|
+
|
|
119
|
+
### Currency
|
|
120
|
+
1. `X-Spree-Currency` header
|
|
121
|
+
2. `currency` query parameter
|
|
122
|
+
3. Market default currency (if country is set)
|
|
123
|
+
4. Store default currency
|
|
124
|
+
|
|
125
|
+
### Market
|
|
126
|
+
1. `X-Spree-Country` header
|
|
127
|
+
2. `country` query parameter
|
|
128
|
+
|
|
129
|
+
> **NOTE:** The locale and currency must be supported by the current store. If an unsupported value is provided, the API falls back to the store's default.
|
|
130
|
+
|
|
131
|
+
## Translated Content
|
|
132
|
+
|
|
133
|
+
When a locale is set, all translatable fields are returned in the requested language. This includes product names, descriptions, category names, and other content managed through [translations](/developer/core-concepts/translations).
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
```typescript SDK
|
|
137
|
+
// English (default)
|
|
138
|
+
const enProduct = await client.products.get('spree-tote')
|
|
139
|
+
console.log(enProduct.name) // "Spree Tote"
|
|
140
|
+
|
|
141
|
+
// French
|
|
142
|
+
const frProduct = await client.products.get('spree-tote', {}, {
|
|
143
|
+
locale: 'fr',
|
|
144
|
+
})
|
|
145
|
+
console.log(frProduct.name) // "Sac Spree"
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
```bash cURL
|
|
149
|
+
# English
|
|
150
|
+
curl 'http://localhost:3000/api/v3/store/products/spree-tote' \
|
|
151
|
+
-H 'X-Spree-Api-Key: spree_pk_xxx' \
|
|
152
|
+
-H 'X-Spree-Locale: en'
|
|
153
|
+
|
|
154
|
+
# French
|
|
155
|
+
curl 'http://localhost:3000/api/v3/store/products/spree-tote' \
|
|
156
|
+
-H 'X-Spree-Api-Key: spree_pk_xxx' \
|
|
157
|
+
-H 'X-Spree-Locale: fr'
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
If a translation doesn't exist for the requested locale, the API falls back to the store's default locale automatically.
|
|
162
|
+
|
|
163
|
+
## Currency-Aware Prices
|
|
164
|
+
|
|
165
|
+
All price fields in the response reflect the requested currency:
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
```typescript SDK
|
|
169
|
+
// USD prices
|
|
170
|
+
const usdProduct = await client.products.get('spree-tote', {}, {
|
|
171
|
+
currency: 'USD',
|
|
172
|
+
})
|
|
173
|
+
console.log(usdProduct.price) // { amount: "15.99", currency: "USD" }
|
|
174
|
+
|
|
175
|
+
// EUR prices
|
|
176
|
+
const eurProduct = await client.products.get('spree-tote', {}, {
|
|
177
|
+
currency: 'EUR',
|
|
178
|
+
})
|
|
179
|
+
console.log(eurProduct.price) // { amount: "14.49", currency: "EUR" }
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
```bash cURL
|
|
183
|
+
# USD prices
|
|
184
|
+
curl 'http://localhost:3000/api/v3/store/products/spree-tote' \
|
|
185
|
+
-H 'X-Spree-Api-Key: spree_pk_xxx' \
|
|
186
|
+
-H 'X-Spree-Currency: USD'
|
|
187
|
+
|
|
188
|
+
# EUR prices
|
|
189
|
+
curl 'http://localhost:3000/api/v3/store/products/spree-tote' \
|
|
190
|
+
-H 'X-Spree-Api-Key: spree_pk_xxx' \
|
|
191
|
+
-H 'X-Spree-Currency: EUR'
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
## Discovering Available Options
|
|
196
|
+
|
|
197
|
+
Use the dedicated endpoints to discover which markets, countries, locales, and currencies are available. These are derived from your store's [markets](/developer/core-concepts/markets) configuration.
|
|
198
|
+
|
|
199
|
+
### Markets
|
|
200
|
+
|
|
201
|
+
List all markets to get the full picture of regions, currencies, and supported locales:
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
```typescript SDK
|
|
205
|
+
const { data: markets } = await client.markets.list()
|
|
206
|
+
// [
|
|
207
|
+
// { id: "mkt_xxx", name: "North America", currency: "USD", default_locale: "en",
|
|
208
|
+
// supported_locales: ["en", "es"], countries: [{ iso: "US", ... }, { iso: "CA", ... }] },
|
|
209
|
+
// { id: "mkt_yyy", name: "Europe", currency: "EUR", default_locale: "de",
|
|
210
|
+
// supported_locales: ["de", "en", "fr"], countries: [{ iso: "DE", ... }, { iso: "FR", ... }] },
|
|
211
|
+
// ]
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
```bash cURL
|
|
215
|
+
curl 'http://localhost:3000/api/v3/store/markets' \
|
|
216
|
+
-H 'X-Spree-Api-Key: spree_pk_xxx'
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
### Countries
|
|
221
|
+
|
|
222
|
+
List all countries or countries within a specific market. Each country includes its market's currency and supported locales:
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
```typescript SDK
|
|
226
|
+
// All countries across all markets
|
|
227
|
+
const { data: countries } = await client.countries.list()
|
|
228
|
+
|
|
229
|
+
// Countries in a specific market (useful for checkout address forms)
|
|
230
|
+
const { data: marketCountries } = await client.markets.countries.list('mkt_xxx')
|
|
231
|
+
|
|
232
|
+
// Get a single country with states
|
|
233
|
+
const usa = await client.countries.get('US', {
|
|
234
|
+
expand: ['states'],
|
|
235
|
+
})
|
|
236
|
+
console.log(usa.states) // [{ abbr: "CA", name: "California" }, ...]
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
```bash cURL
|
|
240
|
+
# All countries
|
|
241
|
+
curl 'http://localhost:3000/api/v3/store/countries' \
|
|
242
|
+
-H 'X-Spree-Api-Key: spree_pk_xxx'
|
|
243
|
+
|
|
244
|
+
# Countries in a specific market
|
|
245
|
+
curl 'http://localhost:3000/api/v3/store/markets/mkt_xxx/countries' \
|
|
246
|
+
-H 'X-Spree-Api-Key: spree_pk_xxx'
|
|
247
|
+
|
|
248
|
+
# Get a country with states
|
|
249
|
+
curl 'http://localhost:3000/api/v3/store/countries/US?expand=states' \
|
|
250
|
+
-H 'X-Spree-Api-Key: spree_pk_xxx'
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
### Locales
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
```typescript SDK
|
|
258
|
+
const { data: locales } = await client.locales.list()
|
|
259
|
+
// [{ code: "en", name: "English" }, { code: "fr", name: "French" }, ...]
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
```bash cURL
|
|
263
|
+
curl 'http://localhost:3000/api/v3/store/locales' \
|
|
264
|
+
-H 'X-Spree-Api-Key: spree_pk_xxx'
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
### Currencies
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
```typescript SDK
|
|
272
|
+
const { data: currencies } = await client.currencies.list()
|
|
273
|
+
// [{ iso_code: "USD", name: "US Dollar", symbol: "$" }, { iso_code: "EUR", name: "Euro", symbol: "€" }, ...]
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
```bash cURL
|
|
277
|
+
curl 'http://localhost:3000/api/v3/store/currencies' \
|
|
278
|
+
-H 'X-Spree-Api-Key: spree_pk_xxx'
|
|
279
|
+
```
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Metadata"
|
|
3
|
+
sidebarTitle: "Metadata"
|
|
4
|
+
description: "How to store and retrieve custom metadata on carts, orders, and line items"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
The Store API supports storing arbitrary key-value **metadata** on carts (orders) and line items. Metadata is useful for tracking custom information like gift messages, attribution data, or integration-specific fields.
|
|
8
|
+
|
|
9
|
+
> **NOTE:** Metadata is different from [metafields](/developer/core-concepts/metafields). Metadata is simple JSON storage (untyped, no schema), while metafields are structured, typed, and schema-defined. Use metadata for integration data and internal tracking. Use metafields for customer-facing custom attributes.
|
|
10
|
+
|
|
11
|
+
## Cart Metadata
|
|
12
|
+
|
|
13
|
+
You can attach metadata when creating a cart:
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
```typescript SDK
|
|
17
|
+
const cart = await client.carts.create({
|
|
18
|
+
metadata: {
|
|
19
|
+
utm_source: 'google',
|
|
20
|
+
utm_campaign: 'summer_sale',
|
|
21
|
+
referral_code: 'FRIEND20',
|
|
22
|
+
},
|
|
23
|
+
})
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```bash cURL
|
|
27
|
+
curl -X POST 'http://localhost:3000/api/v3/store/carts' \
|
|
28
|
+
-H 'X-Spree-Api-Key: spree_pk_xxx' \
|
|
29
|
+
-H 'Content-Type: application/json' \
|
|
30
|
+
-d '{
|
|
31
|
+
"metadata": {
|
|
32
|
+
"utm_source": "google",
|
|
33
|
+
"utm_campaign": "summer_sale",
|
|
34
|
+
"referral_code": "FRIEND20"
|
|
35
|
+
}
|
|
36
|
+
}'
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
## Cart Metadata (Update)
|
|
41
|
+
|
|
42
|
+
Update metadata on an existing cart:
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
```typescript SDK
|
|
46
|
+
await client.carts.update(cart.id, {
|
|
47
|
+
metadata: {
|
|
48
|
+
gift_message: 'Happy Birthday!',
|
|
49
|
+
preferred_delivery: 'morning',
|
|
50
|
+
},
|
|
51
|
+
}, { spreeToken: cart.token })
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
```bash cURL
|
|
55
|
+
curl -X PATCH 'http://localhost:3000/api/v3/store/carts/cart_xxx' \
|
|
56
|
+
-H 'X-Spree-Api-Key: spree_pk_xxx' \
|
|
57
|
+
-H 'X-Spree-Token: <order_token>' \
|
|
58
|
+
-H 'Content-Type: application/json' \
|
|
59
|
+
-d '{
|
|
60
|
+
"metadata": {
|
|
61
|
+
"gift_message": "Happy Birthday!",
|
|
62
|
+
"preferred_delivery": "morning"
|
|
63
|
+
}
|
|
64
|
+
}'
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
## Item Metadata
|
|
69
|
+
|
|
70
|
+
Attach metadata to individual items when adding or updating them:
|
|
71
|
+
|
|
72
|
+
### When Adding an Item
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
```typescript SDK
|
|
76
|
+
await client.carts.items.create(cart.id, {
|
|
77
|
+
variant_id: 'variant_abc123',
|
|
78
|
+
quantity: 1,
|
|
79
|
+
metadata: {
|
|
80
|
+
personalization: 'John',
|
|
81
|
+
gift_wrap: true,
|
|
82
|
+
},
|
|
83
|
+
}, { spreeToken: cart.token })
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
```bash cURL
|
|
87
|
+
curl -X POST 'http://localhost:3000/api/v3/store/carts/cart_xxx/items' \
|
|
88
|
+
-H 'X-Spree-Api-Key: spree_pk_xxx' \
|
|
89
|
+
-H 'X-Spree-Token: <order_token>' \
|
|
90
|
+
-H 'Content-Type: application/json' \
|
|
91
|
+
-d '{
|
|
92
|
+
"variant_id": "variant_abc123",
|
|
93
|
+
"quantity": 1,
|
|
94
|
+
"metadata": {
|
|
95
|
+
"personalization": "John",
|
|
96
|
+
"gift_wrap": true
|
|
97
|
+
}
|
|
98
|
+
}'
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
### When Updating an Item
|
|
103
|
+
|
|
104
|
+
Updating metadata **merges** with existing values rather than replacing them:
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
```typescript SDK
|
|
108
|
+
await client.carts.items.update(cart.id, 'li_xyz789', {
|
|
109
|
+
metadata: {
|
|
110
|
+
personalization: 'Jane', // Updates existing key
|
|
111
|
+
engraving: 'With Love', // Adds new key
|
|
112
|
+
},
|
|
113
|
+
}, { spreeToken: cart.token })
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
```bash cURL
|
|
117
|
+
curl -X PATCH 'http://localhost:3000/api/v3/store/carts/cart_xxx/items/li_xyz789' \
|
|
118
|
+
-H 'X-Spree-Api-Key: spree_pk_xxx' \
|
|
119
|
+
-H 'X-Spree-Token: <order_token>' \
|
|
120
|
+
-H 'Content-Type: application/json' \
|
|
121
|
+
-d '{
|
|
122
|
+
"metadata": {
|
|
123
|
+
"personalization": "Jane",
|
|
124
|
+
"engraving": "With Love"
|
|
125
|
+
}
|
|
126
|
+
}'
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
> **INFO:** Metadata values can be any JSON-serializable type: strings, numbers, booleans, arrays, or nested objects.
|
|
131
|
+
|
|
132
|
+
## Metadata Structure
|
|
133
|
+
|
|
134
|
+
Metadata is stored as a flat JSON object. You can use any keys and values:
|
|
135
|
+
|
|
136
|
+
```json
|
|
137
|
+
{
|
|
138
|
+
"metadata": {
|
|
139
|
+
"string_value": "hello",
|
|
140
|
+
"number_value": 42,
|
|
141
|
+
"boolean_value": true,
|
|
142
|
+
"nested_object": {
|
|
143
|
+
"key": "value"
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Metadata vs Metafields
|
|
150
|
+
|
|
151
|
+
| | Metadata | Metafields |
|
|
152
|
+
|-|----------|------------|
|
|
153
|
+
| **Structure** | Untyped JSON | Schema-defined, strongly typed |
|
|
154
|
+
| **Validation** | None | Type-specific validation |
|
|
155
|
+
| **Visibility** | Write-only in Store API | Configurable (public/private) |
|
|
156
|
+
| **Admin UI** | JSON preview | Dedicated form fields |
|
|
157
|
+
| **Best for** | Integration data, tracking, attribution | Product specs, custom fields, customer-facing data |
|
|
158
|
+
| **API access** | Write via Store API, read via Admin API | Read/write via both APIs |
|
|
159
|
+
|
|
160
|
+
For more details on metafields, see the [Metafields guide](/developer/core-concepts/metafields).
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Monetary Amounts"
|
|
3
|
+
sidebarTitle: "Monetary Amounts"
|
|
4
|
+
description: "How monetary values are represented in API responses"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
All monetary values in the Store API are returned as **strings** (e.g., `"29.99"`, `"0.0"`), not numbers. This preserves decimal precision and avoids floating-point rounding issues common with JSON numbers.
|
|
8
|
+
|
|
9
|
+
## Response Format
|
|
10
|
+
|
|
11
|
+
Every monetary field has a corresponding `display_` field that includes currency formatting:
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"total": "129.99",
|
|
16
|
+
"display_total": "$129.99",
|
|
17
|
+
"item_total": "99.99",
|
|
18
|
+
"display_item_total": "$99.99",
|
|
19
|
+
"ship_total": "10.00",
|
|
20
|
+
"display_ship_total": "$10.00",
|
|
21
|
+
"tax_total": "20.00",
|
|
22
|
+
"display_tax_total": "$20.00"
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Affected Types
|
|
27
|
+
|
|
28
|
+
This convention applies to all monetary fields across all resources:
|
|
29
|
+
|
|
30
|
+
| Resource | Monetary Fields |
|
|
31
|
+
|----------|----------------|
|
|
32
|
+
| **Order** | `total`, `item_total`, `ship_total`, `tax_total`, `adjustment_total`, `promo_total`, `included_tax_total`, `additional_tax_total` |
|
|
33
|
+
| **Line Item** | `price`, `total`, `adjustment_total`, `promo_total`, `pre_tax_amount`, `discounted_amount`, `compare_at_amount` |
|
|
34
|
+
| **Shipment** | `cost` |
|
|
35
|
+
| **Payment** | `amount` |
|
|
36
|
+
| **Gift Card** | `amount`, `amount_used`, `amount_authorized`, `amount_remaining` |
|
|
37
|
+
| **Store Credit** | `amount`, `amount_used`, `amount_remaining` |
|
|
38
|
+
| **Price** | `amount`, `compare_at_amount` |
|
|
39
|
+
|
|
40
|
+
## Working with Amounts
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
```typescript SDK
|
|
44
|
+
const order = await client.orders.get('or_abc123', {}, { token });
|
|
45
|
+
|
|
46
|
+
// Raw string values
|
|
47
|
+
order.total; // "129.99"
|
|
48
|
+
order.display_total; // "$129.99"
|
|
49
|
+
|
|
50
|
+
// Convert to number for calculations
|
|
51
|
+
const total = parseFloat(order.total);
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
```javascript JavaScript
|
|
55
|
+
const data = await response.json();
|
|
56
|
+
|
|
57
|
+
// Use display fields for rendering
|
|
58
|
+
element.textContent = data.display_total; // "$129.99"
|
|
59
|
+
|
|
60
|
+
// Use raw fields for calculations
|
|
61
|
+
const total = parseFloat(data.total);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
> **TIP:** Use `display_*` fields for rendering prices in the UI — they are pre-formatted with the correct currency symbol and decimal places based on the order's currency. Use the raw string fields when you need to perform calculations.
|