Spree Seller SDK
import { createSellerClient } from '@spree/seller-sdk'
const client = createSellerClient({
baseUrl: 'https://your-store.com',
jwtToken: 'eyJhbGciOi...',
sellerId: 'sel_UkLWZg9DAJ',
})
// An export is built in the background; poll until it is done.
let exp = await client.exports.get('exp_UkLWZg9DAJ')
while (!exp.done) {
await new Promise((resolve) => setTimeout(resolve, 2000))
exp = await client.exports.get(exp.id)
}
if (exp.download_url) {
// Exports are served through the API, so fetch with the session's token
// and seller, then drive the browser download:
const response = await fetch(`https://your-store.com${exp.download_url}`, {
headers: { Authorization: 'Bearer eyJhbGciOi...', 'X-Spree-Seller-Id': 'sel_UkLWZg9DAJ' },
})
if (!response.ok) throw new Error(`Download failed with status ${response.status}`)
const url = URL.createObjectURL(await response.blob())
const link = Object.assign(document.createElement('a'), {
href: url,
download: exp.filename ?? 'export.csv',
})
link.click()
URL.revokeObjectURL(url)
}curl --request GET \
--url http://{defaultHost}/api/v3/seller/exports/{id}/download \
--header 'Authorization: Bearer <token>' \
--header 'X-Spree-Seller-Id: <x-spree-seller-id>'{
"error": {
"code": "record_not_found",
"message": "Export not found"
}
}{
"error": {
"code": "export_not_ready",
"message": "Export is not ready yet"
}
}Download an export
Streams the finished CSV.
The bytes are served by this endpoint rather than through a redirect, so the seller’s own session authorizes every download.
GET
/
api
/
v3
/
seller
/
exports
/
{id}
/
download
Spree Seller SDK
import { createSellerClient } from '@spree/seller-sdk'
const client = createSellerClient({
baseUrl: 'https://your-store.com',
jwtToken: 'eyJhbGciOi...',
sellerId: 'sel_UkLWZg9DAJ',
})
// An export is built in the background; poll until it is done.
let exp = await client.exports.get('exp_UkLWZg9DAJ')
while (!exp.done) {
await new Promise((resolve) => setTimeout(resolve, 2000))
exp = await client.exports.get(exp.id)
}
if (exp.download_url) {
// Exports are served through the API, so fetch with the session's token
// and seller, then drive the browser download:
const response = await fetch(`https://your-store.com${exp.download_url}`, {
headers: { Authorization: 'Bearer eyJhbGciOi...', 'X-Spree-Seller-Id': 'sel_UkLWZg9DAJ' },
})
if (!response.ok) throw new Error(`Download failed with status ${response.status}`)
const url = URL.createObjectURL(await response.blob())
const link = Object.assign(document.createElement('a'), {
href: url,
download: exp.filename ?? 'export.csv',
})
link.click()
URL.revokeObjectURL(url)
}curl --request GET \
--url http://{defaultHost}/api/v3/seller/exports/{id}/download \
--header 'Authorization: Bearer <token>' \
--header 'X-Spree-Seller-Id: <x-spree-seller-id>'{
"error": {
"code": "record_not_found",
"message": "Export not found"
}
}{
"error": {
"code": "export_not_ready",
"message": "Export is not ready yet"
}
}Was this page helpful?
⌘I

