The SDK comes with a number of helper functions making consuming responses from the Spree API easier.

extractSuccess() unwraps Spree responses and throws errors.


import { extractSuccess } from '@spree/storefront-api-v2-sdk'
try {
const cartResponse = await extractSuccess(client.cart.create())
console.log('Created a new cart having token: ',
} catch (error) {
console.error('Creating a cart failed. Reason: ', error)

findRelationshipDocuments() finds related records included in a response and findSingleRelationshipDocument() finds a single included record.


import {
} from '@spree/storefront-api-v2-sdk'
const productResult = await{
id: '1',
include: 'primary_variant,variants,images'
const productResponse = productResult.success()
const primaryVariant = findSingleRelationshipDocument(productResponse,, 'primary_variant')
const variants = findRelationshipDocuments(productResponse,, 'variants')
const images = findRelationshipDocuments(productResponse,, 'images')

Generated using TypeDoc